From 5796b1e46dc5b74d891f26b322a147db5cd9dbe8 Mon Sep 17 00:00:00 2001 From: casey langen Date: Fri, 1 Dec 2017 08:32:32 -0800 Subject: [PATCH] Properly set the modified flag so we don't requery and clobber edits. --- .../musikcube/remote/ui/home/activity/MainActivity.kt | 1 - .../remote/ui/shared/extension/Extensions.kt | 3 +++ .../remote/ui/shared/mixin/ItemContextMenuMixin.kt | 2 +- .../remote/ui/tracks/activity/EditPlaylistActivity.kt | 11 ++++++++--- .../remote/ui/tracks/model/EditPlaylistViewModel.kt | 6 +++++- src/musikdroid/app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/activity/MainActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/activity/MainActivity.kt index 7f714a76d..9e7fec5e5 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/activity/MainActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/activity/MainActivity.kt @@ -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 { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt index ce9997b03..d5139e4e5 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt @@ -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(android.R.id.content), stringId) + fun AppCompatActivity.showSnackbar(viewId: Int, stringId: Int) = showSnackbar(this.findViewById(viewId), stringId) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/mixin/ItemContextMenuMixin.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/mixin/ItemContextMenuMixin.kt index b90aab000..36cb1fe1f 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/mixin/ItemContextMenuMixin.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/mixin/ItemContextMenuMixin.kt @@ -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) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/EditPlaylistActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/EditPlaylistActivity.kt index d5b444c54..08da42405 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/EditPlaylistActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/EditPlaylistActivity.kt @@ -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) } } } \ No newline at end of file diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/model/EditPlaylistViewModel.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/model/EditPlaylistViewModel.kt index 782ee094d..4fe73a470 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/model/EditPlaylistViewModel.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/model/EditPlaylistViewModel.kt @@ -47,7 +47,9 @@ class EditPlaylistViewModel(private val playlistId: Long): ViewModel from) (to - 1) else to, id) + modified = true } private fun refreshTrackIds() { diff --git a/src/musikdroid/app/src/main/res/values/strings.xml b/src/musikdroid/app/src/main/res/values/strings.xml index 0a192bc61..d2ecb13de 100644 --- a/src/musikdroid/app/src/main/res/values/strings.xml +++ b/src/musikdroid/app/src/main/res/values/strings.xml @@ -145,6 +145,8 @@ playlist \'%s\' not renamed playlist \'%s\' deleted could not delete playlist \'%s\' + editing playlist \'%s\' + could not save playlist confirm are you sure you want to remove \`%s\` from this playlist? playback mode