Properly set the modified flag so we don't requery and clobber edits.

This commit is contained in:
casey langen 2017-12-01 08:32:32 -08:00
parent 5111b3ed30
commit 5796b1e46d
6 changed files with 19 additions and 6 deletions

View File

@ -410,7 +410,6 @@ class MainActivity : BaseActivity() {
private fun scheduleUpdateTime(immediate: Boolean) {
handler.removeCallbacks(updateTimeRunnable)
handler.postDelayed(updateTimeRunnable, (if (immediate) 0 else 1000).toLong())
handler.removeCallbacks(updateTimeRunnable)
}
private val updateTimeRunnable = Runnable {

View File

@ -200,6 +200,9 @@ fun showErrorSnackbar(view: View, text: String) =
fun showErrorSnackbar(view: View, stringId: Int) =
showErrorSnackbar(view, Application.instance!!.getString(stringId))
fun AppCompatActivity.showErrorSnackbar(stringId: Int) =
showErrorSnackbar(this.findViewById<View>(android.R.id.content), stringId)
fun AppCompatActivity.showSnackbar(viewId: Int, stringId: Int) =
showSnackbar(this.findViewById<View>(viewId), stringId)

View File

@ -235,7 +235,7 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity,
ConfirmDeletePlaylistDialog.show(activity, this, playlistName, playlistId)
}
R.id.menu_playlist_edit -> {
activity.startActivity(EditPlaylistActivity.getStartIntent(activity, playlistId))
activity.startActivity(EditPlaylistActivity.getStartIntent(activity, playlistName, playlistId))
}
R.id.menu_playlist_rename -> {
EnterPlaylistNameDialog.showForRename(activity, this, playlistName, playlistId)

View File

@ -11,6 +11,7 @@ import io.casey.musikcube.remote.R
import io.casey.musikcube.remote.framework.ViewModel
import io.casey.musikcube.remote.ui.shared.activity.BaseActivity
import io.casey.musikcube.remote.ui.shared.extension.setupDefaultRecyclerView
import io.casey.musikcube.remote.ui.shared.extension.showErrorSnackbar
import io.casey.musikcube.remote.ui.shared.mixin.DataProviderMixin
import io.casey.musikcube.remote.ui.shared.mixin.ViewModelMixin
import io.casey.musikcube.remote.ui.tracks.adapter.EditPlaylistAdapter
@ -27,6 +28,8 @@ class EditPlaylistActivity: BaseActivity() {
mixin(ViewModelMixin(this))
data = mixin(DataProviderMixin())
super.onCreate(savedInstanceState)
val playlistName = intent.extras.getString(EXTRA_PLAYLIST_NAME, "-")
title = getString(R.string.playlist_edit_activity, playlistName)
setContentView(R.layout.recycler_view_activity)
viewModel = getViewModel()!!
viewModel.attach(data.provider)
@ -50,11 +53,11 @@ class EditPlaylistActivity: BaseActivity() {
finish()
}
else {
/* TODO ERROR SNACKBAR */
showErrorSnackbar(R.string.playlist_edit_save_failed)
}
},
onError = {
/* TODO ERROR SNACKBAR */
showErrorSnackbar(R.string.playlist_edit_save_failed)
})
}
return super.onOptionsItemSelected(item)
@ -97,10 +100,12 @@ class EditPlaylistActivity: BaseActivity() {
companion object {
private val EXTRA_PLAYLIST_ID = "extra_playlist_id"
private val EXTRA_PLAYLIST_NAME = "extra_playlist_name"
fun getStartIntent(context: Context, playlistId: Long): Intent {
fun getStartIntent(context: Context, playlistName: String, playlistId: Long): Intent {
return Intent(context, EditPlaylistActivity::class.java)
.putExtra(EXTRA_PLAYLIST_ID, playlistId)
.putExtra(EXTRA_PLAYLIST_NAME, playlistName)
}
}
}

View File

@ -47,7 +47,9 @@ class EditPlaylistViewModel(private val playlistId: Long): ViewModel<EditPlaylis
val count: Int
get() {
if (externalIds.isEmpty() && status != Status.Loading) {
refreshTrackIds()
if (!modified) {
refreshTrackIds()
}
}
return externalIds.size
}
@ -70,11 +72,13 @@ class EditPlaylistViewModel(private val playlistId: Long): ViewModel<EditPlaylis
fun remove(index: Int) {
externalIds.removeAt(index)
modified = true
}
fun move(from: Int, to: Int) {
val id = externalIds.removeAt(from)
externalIds.add(if (to > from) (to - 1) else to, id)
modified = true
}
private fun refreshTrackIds() {

View File

@ -145,6 +145,8 @@
<string name="playlist_not_renamed">playlist \'%s\' not renamed</string>
<string name="playlist_deleted">playlist \'%s\' deleted</string>
<string name="playlist_not_deleted">could not delete playlist \'%s\'</string>
<string name="playlist_edit_activity">editing playlist \'%s\'</string>
<string name="playlist_edit_save_failed">could not save playlist</string>
<string name="remove_from_playlist_dialog_title">confirm</string>
<string name="remove_from_playlist_dialog_message">are you sure you want to remove \`%s\` from this playlist?</string>
<string name="spotlight_playback_mode_title">playback mode</string>