From 51be0ccfb42d05018797cf9ad7cd0c125aa99e2a Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 2 Dec 2017 23:28:33 -0800 Subject: [PATCH] Fixed a bug in playlist re-arranging when moving items up (down and delete were fine). Also improved snackbars with a "VIEW" button that jumps to updated playlists. --- .../streaming/StreamingPlaybackService.kt | 1 - .../activity/CategoryBrowseActivity.kt | 14 +-- .../remote/ui/shared/extension/Extensions.kt | 42 +++++---- .../ui/shared/mixin/ItemContextMenuMixin.kt | 90 ++++++++++--------- .../tracks/activity/EditPlaylistActivity.kt | 12 ++- .../ui/tracks/activity/TrackListActivity.kt | 24 +++-- .../ui/tracks/model/EditPlaylistViewModel.kt | 5 +- .../app/src/main/res/values/strings.xml | 5 +- 8 files changed, 115 insertions(+), 78 deletions(-) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/playback/impl/streaming/StreamingPlaybackService.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/playback/impl/streaming/StreamingPlaybackService.kt index 0795e9017..451ecd886 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/playback/impl/streaming/StreamingPlaybackService.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/service/playback/impl/streaming/StreamingPlaybackService.kt @@ -699,7 +699,6 @@ class StreamingPlaybackService(context: Context) : IPlaybackService { } .subscribeBy( onNext = { track -> - Log.e(TAG, "here") if (playContext.currentMetadata == null) { playContext.currentMetadata = track.firstOrNull() } diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/CategoryBrowseActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/CategoryBrowseActivity.kt index 77cd76317..e82bb3188 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/CategoryBrowseActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/CategoryBrowseActivity.kt @@ -141,12 +141,12 @@ class CategoryBrowseActivity : BaseActivity(), Filterable { } private val contextMenuListener = object: ItemContextMenuMixin.EventListener() { - override fun onPlaylistDeleted(id: Long) = requery() + override fun onPlaylistDeleted(id: Long, name: String) = requery() - override fun onPlaylistUpdated(id: Long) = requery() + override fun onPlaylistUpdated(id: Long, name: String) = requery() - override fun onPlaylistCreated(id: Long) = - if (navigationType == NavigationType.Select) navigateToSelect(id) else requery() + override fun onPlaylistCreated(id: Long, name: String) = + if (navigationType == NavigationType.Select) navigateToSelect(id, name) else requery() } private val adapterListener = object: CategoryBrowseAdapter.EventListener { @@ -154,7 +154,7 @@ class CategoryBrowseActivity : BaseActivity(), Filterable { when (navigationType) { NavigationType.Albums -> navigateToAlbums(value) NavigationType.Tracks -> navigateToTracks(value) - NavigationType.Select -> navigateToSelect(value.id) + NavigationType.Select -> navigateToSelect(value.id, value.value) } } @@ -169,10 +169,11 @@ class CategoryBrowseActivity : BaseActivity(), Filterable { private fun navigateToTracks(entry: ICategoryValue) = startActivity(TrackListActivity.getStartIntent(this, category, entry.id, entry.value)) - private fun navigateToSelect(id: Long) { + private fun navigateToSelect(id: Long, name: String) { val intent = Intent() .putExtra(EXTRA_CATEGORY, category) .putExtra(EXTRA_ID, id) + .putExtra(EXTRA_NAME, name) setResult(RESULT_OK, intent) finish() } @@ -180,6 +181,7 @@ class CategoryBrowseActivity : BaseActivity(), Filterable { companion object { val EXTRA_CATEGORY = "extra_category" val EXTRA_ID = "extra_id" + val EXTRA_NAME = "extra_name" private val EXTRA_PREDICATE_TYPE = "extra_predicate_type" private val EXTRA_PREDICATE_ID = "extra_predicate_id" private val EXTRA_NAVIGATION_TYPE = "extra_navigation_type" 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 a1e9691d0..9c4b0bb9c 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 @@ -175,8 +175,13 @@ fun AppCompatActivity.showDialog(dialog: DialogFragment, tag: String) { dialog.show(this.supportFragmentManager, tag) } -fun showSnackbar(view: View, text: String, bgColor: Int, fgColor: Int) { +fun showSnackbar(view: View, text: String, bgColor: Int, fgColor: Int, buttonText: String? = null, buttonCb: ((View) -> Unit)? = null) { val sb = Snackbar.make(view, text, Snackbar.LENGTH_LONG) + + if (buttonText != null && buttonCb != null) { + sb.setAction(buttonText, buttonCb) + } + val sbView = sb.view val context = view.context sbView.setBackgroundColor(ContextCompat.getColor(context, bgColor)) @@ -185,29 +190,32 @@ fun showSnackbar(view: View, text: String, bgColor: Int, fgColor: Int) { sb.show() } -fun showSnackbar(view: View, stringId: Int, bgColor: Int, fgColor: Int) = - showSnackbar(view, Application.instance!!.getString(stringId), bgColor, fgColor) +fun showSnackbar(view: View, stringId: Int, bgColor: Int, fgColor: Int, buttonText: String? = null, buttonCb: ((View) -> Unit)? = null) = + showSnackbar(view, Application.instance!!.getString(stringId), bgColor, fgColor, buttonText, buttonCb) -fun showSnackbar(view: View, text: String) = - showSnackbar(view, text, R.color.color_primary, R.color.theme_foreground) +fun showSnackbar(view: View, text: String, buttonText: String? = null, buttonCb: ((View) -> Unit)? = null) = + showSnackbar(view, text, R.color.color_primary, R.color.theme_foreground, buttonText, buttonCb) -fun showSnackbar(view: View, stringId: Int) = - showSnackbar(view, Application.instance!!.getString(stringId)) +fun showSnackbar(view: View, stringId: Int, buttonText: String? = null, buttonCb: ((View) -> Unit)? = null) = + showSnackbar(view, Application.instance!!.getString(stringId), buttonText, buttonCb) -fun showErrorSnackbar(view: View, text: String) = - showSnackbar(view, text, R.color.theme_red, R.color.theme_foreground) +fun showErrorSnackbar(view: View, text: String, buttonText: String? = null, buttonCb: ((View) -> Unit)? = null) = + showSnackbar(view, text, R.color.theme_red, R.color.theme_foreground, buttonText, buttonCb) -fun showErrorSnackbar(view: View, stringId: Int) = - showErrorSnackbar(view, Application.instance!!.getString(stringId)) +fun showErrorSnackbar(view: View, stringId: Int, buttonText: String? = null, buttonCb: ((View) -> Unit)? = null) = + showErrorSnackbar(view, Application.instance!!.getString(stringId), buttonText, buttonCb) -fun AppCompatActivity.showErrorSnackbar(stringId: Int) = - showErrorSnackbar(this.findViewById(android.R.id.content), stringId) +fun AppCompatActivity.showErrorSnackbar(stringId: Int, buttonText: String? = null, buttonCb: ((View) -> Unit)? = null) = + showErrorSnackbar(this.findViewById(android.R.id.content), stringId, buttonText, buttonCb) -fun AppCompatActivity.showSnackbar(stringId: Int) = - showSnackbar(this.findViewById(android.R.id.content), stringId) +fun AppCompatActivity.showSnackbar(stringId: Int, buttonText: String? = null, buttonCb: ((View) -> Unit)? = null) = + showSnackbar(this.findViewById(android.R.id.content), stringId, buttonText, buttonCb) -fun AppCompatActivity.showSnackbar(viewId: Int, stringId: Int) = - showSnackbar(this.findViewById(viewId), stringId) +fun AppCompatActivity.showSnackbar(stringId: String, buttonText: String? = null, buttonCb: ((View) -> Unit)? = null) = + showSnackbar(this.findViewById(android.R.id.content), stringId, buttonText, buttonCb) + +fun AppCompatActivity.showSnackbar(viewId: Int, stringId: Int, buttonText: String? = null, buttonCb: ((View) -> Unit)? = null) = + showSnackbar(this.findViewById(viewId), stringId, buttonText, buttonCb) fun fallback(input: String?, fallback: String): String = if (input.isNullOrEmpty()) fallback else input!! 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 b543ab065..98051ee2f 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 @@ -41,13 +41,13 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, @Inject lateinit var provider: IDataProvider open class EventListener { - open fun onPlaylistDeleted(id: Long) { } - open fun onPlaylistCreated(id: Long) { } - open fun onPlaylistUpdated(id: Long) { } + open fun onPlaylistDeleted(id: Long, name: String) { } + open fun onPlaylistCreated(id: Long, name: String) { } + open fun onPlaylistUpdated(id: Long, name: String) { } } private var pendingCode = -1 - private var completion: ((Long) -> Unit)? = null + private var completion: ((Long, String) -> Unit)? = null init { DaggerViewComponent.builder() @@ -81,18 +81,25 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, if (pendingCode == request) { if (result == Activity.RESULT_OK && data != null) { val playlistId = data.getLongExtra(CategoryBrowseActivity.EXTRA_ID, -1L) + val playlistName = data.getStringExtra(CategoryBrowseActivity.EXTRA_NAME) if (playlistId != -1L) { - completion?.invoke(playlistId) + completion?.invoke(playlistId, playlistName) } } pendingCode = -1 completion = null } - else if (result == Activity.RESULT_OK && request == REQUEST_EDIT_PLAYLIST) { + else if (result == Activity.RESULT_OK && request == REQUEST_EDIT_PLAYLIST && data != null) { + val playlistName = data.getStringExtra(EditPlaylistActivity.EXTRA_PLAYLIST_NAME) + val playlistId = data.getLongExtra(EditPlaylistActivity.EXTRA_PLAYLIST_ID, -1L) + showSnackbar( activity.findViewById(android.R.id.content), - R.string.playlist_edit_add_success) + context.getString(R.string.playlist_edit_add_success, playlistName), + context.getString(R.string.button_view), + viewPlaylist(playlistId, playlistName)) } + super.onActivityResult(request, result, data) } @@ -103,7 +110,7 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, provider.createPlaylist(playlistName).subscribeBy( onNext = { id -> if (id > 0L) { - listener?.onPlaylistCreated(id) + listener?.onPlaylistCreated(id, playlistName) showSuccess(activity.getString(R.string.playlist_created, playlistName)) } else { @@ -119,7 +126,7 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, provider.renamePlaylist(id, newName).subscribeBy( onNext = { success -> if (success) { - listener?.onPlaylistUpdated(id) + listener?.onPlaylistUpdated(id, newName) showSuccess(activity.getString(R.string.playlist_renamed, newName)) } else { @@ -135,31 +142,34 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, addToPlaylist(listOf(track)) fun addToPlaylist(tracks: List) { - showPlaylistChooser { id -> - addWithErrorHandler(id, provider.appendToPlaylist(id, tracks)) - } - } - - fun addToPlaylist(categoryType: String, categoryId: Long) { - showPlaylistChooser { id -> - addWithErrorHandler(id, provider.appendToPlaylist(id, categoryType, categoryId)) + showPlaylistChooser { id, name -> + addWithErrorHandler(id, name, provider.appendToPlaylist(id, tracks)) } } fun addToPlaylist(category: ICategoryValue) { - showPlaylistChooser { id -> - addWithErrorHandler(id, provider.appendToPlaylist(id, category)) + showPlaylistChooser { id, name -> + addWithErrorHandler(id, name, provider.appendToPlaylist(id, category)) } } - private fun addWithErrorHandler(playlistId: Long, observable: Observable) { + private fun viewPlaylist(playlistId: Long, playlistName: String): ((View) -> Unit) = { _ -> + activity.startActivity(TrackListActivity.getStartIntent( + activity, Messages.Category.PLAYLISTS, playlistId, playlistName)) + } + + private fun addWithErrorHandler(playlistId: Long, playlistName: String, observable: Observable) { val error = R.string.playlist_edit_add_error observable.subscribeBy( onNext = { success -> if (success) { - listener?.onPlaylistUpdated(playlistId) - showSuccess(R.string.playlist_edit_add_success) + listener?.onPlaylistUpdated(playlistId, playlistName) + + showSuccess( + context.getString(R.string.playlist_edit_add_success, playlistName), + context.getString(R.string.button_view), + viewPlaylist(playlistId, playlistName)) } else { showError(error) @@ -168,7 +178,7 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, onError = { showError(error) }) } - private fun showPlaylistChooser(callback: (Long) -> Unit) { + private fun showPlaylistChooser(callback: (Long, String) -> Unit) { completion = callback pendingCode = REQUEST_ADD_TO_PLAYLIST @@ -182,14 +192,14 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, } fun showForTrack(track: ITrack, anchorView: View) { - showForTrack(track, -1, -1, anchorView, TrackType.Normal) + showForTrack(track, -1, -1, "", anchorView, TrackType.Normal) } - fun showForPlaylistTrack(track: ITrack, position: Int, playlistId: Long, anchorView: View) { - showForTrack(track, position, playlistId, anchorView, TrackType.Playlist) + fun showForPlaylistTrack(track: ITrack, position: Int, playlistId: Long, playlistName: String, anchorView: View) { + showForTrack(track, position, playlistId, playlistName, anchorView, TrackType.Playlist) } - private fun showForTrack(track: ITrack, position: Int, categoryId: Long, anchorView: View, type: TrackType) { + private fun showForTrack(track: ITrack, position: Int, categoryId: Long, categoryValue: String, anchorView: View, type: TrackType) { val popup = PopupMenu(activity, anchorView) popup.inflate(R.menu.track_item_context_menu) @@ -205,7 +215,7 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, } R.id.menu_remove_from_playlist -> { ConfirmRemoveFromPlaylistDialog.show( - activity, this, categoryId, position, track) + activity, this, categoryId, categoryValue, position, track) null } R.id.menu_show_artist_albums -> { @@ -335,7 +345,7 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, provider.deletePlaylist(playlistId).subscribeBy( onNext = { success -> if (success) { - listener?.onPlaylistDeleted(playlistId) + listener?.onPlaylistDeleted(playlistId, playlistName) showSuccess(activity.getString(R.string.playlist_deleted, playlistName)) } else { @@ -348,10 +358,10 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, } } - private fun removeFromPlaylistConfirmed(playlistId: Long, externalId: String, position: Int) { + private fun removeFromPlaylistConfirmed(playlistId: Long, playlistName: String, externalId: String, position: Int) { provider.removeTracksFromPlaylist(playlistId, listOf(externalId), listOf(position)).subscribeBy( - onNext = { success -> - listener?.onPlaylistUpdated(playlistId) + onNext = { _ -> + listener?.onPlaylistUpdated(playlistId, playlistName) }, onError = { @@ -359,11 +369,8 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, ) } - private fun showSuccess(stringId: Int) = - showSuccess(activity.getString(stringId)) - - private fun showSuccess(message: String) = - showSnackbar(activity.findViewById(android.R.id.content), message) + private fun showSuccess(message: String, button: String? = null, cb: ((View) -> Unit)? = null) = + showSnackbar(activity.findViewById(android.R.id.content), message, buttonText = button, buttonCb = cb) private fun showError(message: Int) = showError(activity.getString(message)) @@ -376,6 +383,7 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val playlistId = arguments.getLong(EXTRA_PLAYLIST_ID, -1) + val playlistName = arguments.getString(EXTRA_PLAYLIST_NAME) ?: "" val trackTitle = arguments.getString(EXTRA_TRACK_TITLE, "") val trackExternalId = arguments.getString(EXTRA_TRACK_EXTERNAL_ID, "") val trackPosition = arguments.getInt(EXTRA_TRACK_POSITION, -1) @@ -385,7 +393,7 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, .setMessage(getString(R.string.playlist_confirm_delete_message, trackTitle)) .setNegativeButton(R.string.button_no, null) .setPositiveButton(R.string.button_yes, { _: DialogInterface, _: Int -> - mixin.removeFromPlaylistConfirmed(playlistId, trackExternalId, trackPosition) + mixin.removeFromPlaylistConfirmed(playlistId, playlistName, trackExternalId, trackPosition) }) .create() @@ -396,6 +404,7 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, companion object { val TAG = "confirm_delete_playlist_dialog" private val EXTRA_PLAYLIST_ID = "extra_playlist_id" + private val EXTRA_PLAYLIST_NAME = "extra_playlist_name" private val EXTRA_TRACK_TITLE = "extra_track_title" private val EXTRA_TRACK_EXTERNAL_ID = "extra_track_external_id" private val EXTRA_TRACK_POSITION = "extra_track_position" @@ -404,10 +413,11 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, find(activity, TAG)?.mixin = mixin } - fun show(activity: AppCompatActivity, mixin: ItemContextMenuMixin, playlistId: Long, position: Int, track: ITrack) { + fun show(activity: AppCompatActivity, mixin: ItemContextMenuMixin, playlistId: Long, playlistName: String, position: Int, track: ITrack) { dismiss(activity, TAG) val args = Bundle() args.putLong(EXTRA_PLAYLIST_ID, playlistId) + args.putString(EXTRA_PLAYLIST_NAME, playlistName) args.putString(EXTRA_TRACK_TITLE, track.title) args.putString(EXTRA_TRACK_EXTERNAL_ID, track.externalId) args.putInt(EXTRA_TRACK_POSITION, position) @@ -423,7 +433,7 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, private lateinit var mixin: ItemContextMenuMixin override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val playlistName = arguments.getString(EXTRA_PLAYLIST_NAME, "") + val playlistName = arguments.getString(EXTRA_PLAYLIST_NAME, "") ?: "" val dlg = AlertDialog.Builder(activity) .setTitle(R.string.playlist_confirm_delete_title) 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 30f255141..a1367872e 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 @@ -27,12 +27,13 @@ class EditPlaylistActivity: BaseActivity() { private lateinit var viewModel: EditPlaylistViewModel private lateinit var data: DataProviderMixin private lateinit var adapter: EditPlaylistAdapter + private var playlistName = "" override fun onCreate(savedInstanceState: Bundle?) { mixin(ViewModelMixin(this)) data = mixin(DataProviderMixin()) super.onCreate(savedInstanceState) - val playlistName = intent.extras.getString(EXTRA_PLAYLIST_NAME, "-") + playlistName = intent.extras.getString(EXTRA_PLAYLIST_NAME, "-") title = getString(R.string.playlist_edit_activity, playlistName) setContentView(R.layout.recycler_view_activity) viewModel = getViewModel()!! @@ -87,7 +88,10 @@ class EditPlaylistActivity: BaseActivity() { viewModel.save().subscribeBy( onNext = { playlistId -> if (playlistId != -1L) { - setResult(RESULT_OK) + val data = Intent() + data.putExtra(EXTRA_PLAYLIST_NAME, playlistName) + data.putExtra(EXTRA_PLAYLIST_ID, playlistId) + setResult(RESULT_OK, data) finish() } else { showErrorSnackbar(R.string.playlist_edit_save_failed) @@ -146,8 +150,8 @@ class EditPlaylistActivity: BaseActivity() { } companion object { - private val EXTRA_PLAYLIST_ID = "extra_playlist_id" - private val EXTRA_PLAYLIST_NAME = "extra_playlist_name" + val EXTRA_PLAYLIST_ID = "extra_playlist_id" + val EXTRA_PLAYLIST_NAME = "extra_playlist_name" fun getStartIntent(context: Context, playlistName: String, playlistId: Long): Intent { return Intent(context, EditPlaylistActivity::class.java) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/TrackListActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/TrackListActivity.kt index 43e101fa9..178f92463 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/TrackListActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/TrackListActivity.kt @@ -40,6 +40,7 @@ class TrackListActivity : BaseActivity(), Filterable { private var categoryType: String = "" private var categoryId: Long = 0 + private var categoryValue: String = "" private var lastFilter = "" override fun onCreate(savedInstanceState: Bundle?) { @@ -52,6 +53,7 @@ class TrackListActivity : BaseActivity(), Filterable { val intent = intent categoryType = intent.getStringExtra(EXTRA_CATEGORY_TYPE) ?: "" categoryId = intent.getLongExtra(EXTRA_SELECTED_ID, 0) + categoryValue = intent.getStringExtra(EXTRA_CATEGORY_VALUE) ?: "" val titleId = intent.getIntExtra(EXTRA_TITLE_ID, R.string.songs_title) mixin(ItemContextMenuMixin(this, menuListener)) @@ -97,16 +99,26 @@ class TrackListActivity : BaseActivity(), Filterable { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == R.id.action_edit) { - val name = intent.getStringExtra(EXTRA_CATEGORY_VALUE) startActivityForResult(EditPlaylistActivity.getStartIntent( - this, name, categoryId), REQUEST_CODE_EDIT_PLAYLIST) + this, categoryValue, categoryId), REQUEST_CODE_EDIT_PLAYLIST) } return super.onOptionsItemSelected(item) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - if (requestCode == REQUEST_CODE_EDIT_PLAYLIST && resultCode == RESULT_OK) { - showSnackbar(R.string.playlist_edit_save_success) + if (requestCode == REQUEST_CODE_EDIT_PLAYLIST && resultCode == RESULT_OK && data != null) { + val playlistName = data.getStringExtra(EditPlaylistActivity.EXTRA_PLAYLIST_NAME) ?: "" + val playlistId = data.getLongExtra(EditPlaylistActivity.EXTRA_PLAYLIST_ID, -1L) + + if (categoryType != Messages.Category.PLAYLISTS || playlistId != this.categoryId) { + showSnackbar( + getString(R.string.playlist_edit_save_success, playlistName), + buttonText = getString(R.string.button_view), + buttonCb = { _ -> + startActivity(TrackListActivity.getStartIntent( + this@TrackListActivity, Messages.Category.PLAYLISTS, playlistId, playlistName)) + }) + } } super.onActivityResult(requestCode, resultCode, data) } @@ -144,7 +156,7 @@ class TrackListActivity : BaseActivity(), Filterable { override fun onActionItemClick(view: View, track: ITrack, position: Int) { val mixin = mixin(ItemContextMenuMixin::class.java)!! if (categoryType == Messages.Category.Companion.PLAYLISTS) { - mixin.showForPlaylistTrack(track, position, categoryId, view) + mixin.showForPlaylistTrack(track, position, categoryId, categoryValue, view) } else { mixin.showForTrack(track, view) @@ -238,7 +250,7 @@ class TrackListActivity : BaseActivity(), Filterable { get() { if (categoryType == Messages.Category.PLAYLISTS) { return object: ItemContextMenuMixin.EventListener () { - override fun onPlaylistUpdated(id: Long) { + override fun onPlaylistUpdated(id: Long, name: String) { tracks.requery() } } 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 4fe73a470..56957b23d 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 @@ -67,7 +67,8 @@ class EditPlaylistViewModel(private val playlistId: Long): ViewModel from) (to - 1) else to, id) + externalIds.add(to, id) modified = true } diff --git a/src/musikdroid/app/src/main/res/values/strings.xml b/src/musikdroid/app/src/main/res/values/strings.xml index 08a311f03..22b4c3d51 100644 --- a/src/musikdroid/app/src/main/res/values/strings.xml +++ b/src/musikdroid/app/src/main/res/values/strings.xml @@ -50,6 +50,7 @@ rename discard learn more + view invalid password the server rejected your password.\n\nchange the password in the settings screen. connecting @@ -135,7 +136,7 @@ buffering couldn\'t get playlists from server playlist update failed - playlist updated + playlist \'%s\' updated pick a playlist confirm delete are you sure you want to delete playlist \'%s\'? @@ -149,7 +150,7 @@ could not delete playlist \'%s\' editing playlist \'%s\' could not save playlist - playlist saved + playlist \'%s\' saved save changes? do you want to save the changes you made to this playlist? confirm