From a57326509286b9081766d19e88f3596ff6a3f226 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sun, 19 Nov 2017 13:24:33 -0800 Subject: [PATCH] More context menu handling fixes. Lots of cross linkage! --- .../ui/albums/activity/AlbumBrowseActivity.kt | 18 ++------ .../activity/CategoryBrowseActivity.kt | 41 +++++++++---------- .../remote/ui/shared/constants/Navigation.kt | 19 --------- .../ui/shared/mixin/ItemContextMenuMixin.kt | 36 ++++++++++------ .../ui/tracks/activity/TrackListActivity.kt | 15 ++++--- .../app/src/main/res/values/strings.xml | 2 + 6 files changed, 54 insertions(+), 77 deletions(-) delete mode 100644 src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/constants/Navigation.kt diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/activity/AlbumBrowseActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/activity/AlbumBrowseActivity.kt index 75510aef6..d1cb56672 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/activity/AlbumBrowseActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/activity/AlbumBrowseActivity.kt @@ -14,7 +14,6 @@ import io.casey.musikcube.remote.service.websocket.model.IDataProvider import io.casey.musikcube.remote.ui.albums.adapter.AlbumBrowseAdapter import io.casey.musikcube.remote.ui.shared.activity.BaseActivity import io.casey.musikcube.remote.ui.shared.activity.Filterable -import io.casey.musikcube.remote.ui.shared.constants.Navigation import io.casey.musikcube.remote.ui.shared.extension.* import io.casey.musikcube.remote.ui.shared.fragment.TransportFragment import io.casey.musikcube.remote.ui.shared.mixin.DataProviderMixin @@ -84,15 +83,6 @@ class AlbumBrowseActivity : BaseActivity(), Filterable { filterDebouncer.call(filter) } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - if (resultCode == Navigation.ResponseCode.PLAYBACK_STARTED) { - setResult(Navigation.ResponseCode.PLAYBACK_STARTED) - finish() - } - - super.onActivityResult(requestCode, resultCode, data) - } - private fun initObservables() { disposables.add(data.provider.observeState().subscribeBy( onNext = { state -> @@ -128,11 +118,9 @@ class AlbumBrowseActivity : BaseActivity(), Filterable { } private val eventListener = object: AlbumBrowseAdapter.EventListener { - override fun onItemClicked(album: IAlbum) { - val intent = TrackListActivity.getStartIntent( - this@AlbumBrowseActivity, Messages.Category.ALBUM, album.id, album.value) - - startActivityForResult(intent, Navigation.RequestCode.ALBUM_TRACKS_ACTIVITY) } + override fun onItemClicked(album: IAlbum) = + startActivity(TrackListActivity.getStartIntent( + this@AlbumBrowseActivity, Messages.Category.ALBUM, album.id, album.value)) override fun onActionClicked(view: View, album: IAlbum) { mixin(ItemContextMenuMixin::class.java)?.showForCategory(album, view) 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 232c8b6a0..b6c35df86 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 @@ -15,7 +15,6 @@ import io.casey.musikcube.remote.ui.category.adapter.CategoryBrowseAdapter import io.casey.musikcube.remote.ui.category.constant.NavigationType import io.casey.musikcube.remote.ui.shared.activity.BaseActivity import io.casey.musikcube.remote.ui.shared.activity.Filterable -import io.casey.musikcube.remote.ui.shared.constants.Navigation import io.casey.musikcube.remote.ui.shared.extension.* import io.casey.musikcube.remote.ui.shared.fragment.TransportFragment import io.casey.musikcube.remote.ui.shared.mixin.DataProviderMixin @@ -97,15 +96,6 @@ class CategoryBrowseActivity : BaseActivity(), Filterable { return true } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - - if (resultCode == Navigation.ResponseCode.PLAYBACK_STARTED) { - setResult(Navigation.ResponseCode.PLAYBACK_STARTED) - finish() - } - } - override fun setFilter(filter: String) { this.lastFilter = filter this.filterDebouncer.call() @@ -171,17 +161,11 @@ class CategoryBrowseActivity : BaseActivity(), Filterable { } } - private fun navigateToAlbums(entry: ICategoryValue) { - val intent = AlbumBrowseActivity.getStartIntent(this, category, entry) - startActivityForResult(intent, Navigation.RequestCode.ALBUM_BROWSE_ACTIVITY) - } + private fun navigateToAlbums(entry: ICategoryValue) = + startActivity(AlbumBrowseActivity.getStartIntent(this, category, entry)) - private fun navigateToTracks(entry: ICategoryValue) { - val categoryId = entry.id - val value = entry.value - val intent = TrackListActivity.getStartIntent(this, category, categoryId, value) - startActivityForResult(intent, Navigation.RequestCode.CATEGORY_TRACKS_ACTIVITY) - } + private fun navigateToTracks(entry: ICategoryValue) = + startActivity(TrackListActivity.getStartIntent(this, category, entry.id, entry.value)) private fun navigateToSelect(id: Long) { val intent = Intent() @@ -206,6 +190,12 @@ class CategoryBrowseActivity : BaseActivity(), Filterable { Messages.Category.ALBUM to R.string.albums_title, Messages.Category.PLAYLISTS to R.string.playlists_title) + private val CATEGORY_NAME_TO_RELATED_TITLE: Map = mapOf( + Messages.Category.ALBUM_ARTIST to R.string.artists_from_category, + Messages.Category.GENRE to R.string.genres_from_category, + Messages.Category.ARTIST to R.string.artists_from_category, + Messages.Category.ALBUM to R.string.albums_by_title) + private val CATEGORY_NAME_TO_EMPTY_TYPE: Map = mapOf( Messages.Category.ALBUM_ARTIST to R.string.browse_type_artists, Messages.Category.GENRE to R.string.browse_type_genres, @@ -213,11 +203,18 @@ class CategoryBrowseActivity : BaseActivity(), Filterable { Messages.Category.ALBUM to R.string.browse_type_albums, Messages.Category.PLAYLISTS to R.string.browse_type_playlists) - fun getStartIntent(context: Context, category: String, predicateType: String = "", predicateId: Long = -1): Intent { - return Intent(context, CategoryBrowseActivity::class.java) + fun getStartIntent(context: Context, category: String, predicateType: String = "", predicateId: Long = -1, predicateValue: String = ""): Intent { + val intent = Intent(context, CategoryBrowseActivity::class.java) .putExtra(EXTRA_CATEGORY, category) .putExtra(EXTRA_PREDICATE_TYPE, predicateType) .putExtra(EXTRA_PREDICATE_ID, predicateId) + + if (predicateValue.isNotBlank() && CATEGORY_NAME_TO_RELATED_TITLE.containsKey(category)) { + val format = CATEGORY_NAME_TO_RELATED_TITLE[category]!! + intent.putExtra(EXTRA_ACTIVITY_TITLE, context.getString(format, predicateValue)) + } + + return intent } fun getStartIntent(context: Context, category: String, navigationType: NavigationType, title: String = ""): Intent { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/constants/Navigation.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/constants/Navigation.kt deleted file mode 100644 index 6940b1027..000000000 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/constants/Navigation.kt +++ /dev/null @@ -1,19 +0,0 @@ -package io.casey.musikcube.remote.ui.shared.constants - -import android.app.Activity - -object Navigation { - interface RequestCode { - companion object { - val ALBUM_TRACKS_ACTIVITY = 10 - val ALBUM_BROWSE_ACTIVITY = 11 - val CATEGORY_TRACKS_ACTIVITY = 12 - } - } - - interface ResponseCode { - companion object { - val PLAYBACK_STARTED = Activity.RESULT_FIRST_USER + 0xbeef - } - } -} 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 9b1c25787..a5b43f827 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 @@ -172,13 +172,11 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, } R.id.menu_show_artist_albums -> { AlbumBrowseActivity.getStartIntent( - activity, Messages.Category.ARTIST, track.artistId) + activity, Messages.Category.ARTIST, track.artistId, track.artist) } R.id.menu_show_artist_tracks -> { TrackListActivity.getStartIntent( - activity, - Messages.Category.ARTIST, - track.artistId) + activity, Messages.Category.ARTIST, track.artistId, track.artist) } else -> null } @@ -236,29 +234,41 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity, addToPlaylist(value) null } - R.id.menu_show_artist_albums -> { + R.id.menu_show_artist_albums, + R.id.menu_show_genre_albums -> { if (value is IAlbum) { AlbumBrowseActivity.getStartIntent( - activity, Messages.Category.ALBUM_ARTIST, value.albumArtistId) + activity, + Messages.Category.ALBUM_ARTIST, + value.albumArtistId, + value.albumArtist) } else { - null /* should never happen */ + AlbumBrowseActivity.getStartIntent( + activity, value.type, value.id, value.value) } } - R.id.menu_show_genre_albums -> { - AlbumBrowseActivity.getStartIntent(activity, value.type, value.id) - } R.id.menu_show_artist_tracks, R.id.menu_show_genre_tracks -> { - TrackListActivity.getStartIntent(activity, value.type, value.id) + if (value is IAlbum) { + TrackListActivity.getStartIntent( + activity, + Messages.Category.ALBUM_ARTIST, + value.albumArtistId, + value.albumArtist) + } + else { + TrackListActivity.getStartIntent( + activity, value.type, value.id, value.value) + } } R.id.menu_show_artist_genres -> { CategoryBrowseActivity.getStartIntent( - activity, Messages.Category.GENRE, value.type, value.id) + activity, Messages.Category.GENRE, value.type, value.id, value.value) } R.id.menu_show_genre_artists -> { CategoryBrowseActivity.getStartIntent( - activity, Messages.Category.ARTIST, value.type, value.id) + activity, Messages.Category.ARTIST, value.type, value.id, value.value) } else -> null } 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 b5878aef6..631f96c91 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 @@ -10,9 +10,9 @@ import io.casey.musikcube.remote.R import io.casey.musikcube.remote.service.websocket.Messages import io.casey.musikcube.remote.service.websocket.model.IDataProvider import io.casey.musikcube.remote.service.websocket.model.ITrack +import io.casey.musikcube.remote.ui.home.activity.MainActivity import io.casey.musikcube.remote.ui.shared.activity.BaseActivity import io.casey.musikcube.remote.ui.shared.activity.Filterable -import io.casey.musikcube.remote.ui.shared.constants.Navigation import io.casey.musikcube.remote.ui.shared.extension.* import io.casey.musikcube.remote.ui.shared.fragment.TransportFragment import io.casey.musikcube.remote.ui.shared.mixin.DataProviderMixin @@ -51,7 +51,7 @@ class TrackListActivity : BaseActivity(), Filterable { playback.service.playAll(index, lastFilter) } - setResult(Navigation.ResponseCode.PLAYBACK_STARTED) + startActivity(MainActivity.getStartIntent(this)) finish() } @@ -220,11 +220,8 @@ class TrackListActivity : BaseActivity(), Filterable { private val EXTRA_SELECTED_ID = "extra_selected_id" private val EXTRA_TITLE_ID = "extra_title_id" - fun getStartIntent(context: Context, type: String, id: Long): Intent { - return Intent(context, TrackListActivity::class.java) - .putExtra(EXTRA_CATEGORY_TYPE, type) - .putExtra(EXTRA_SELECTED_ID, id) - } + fun getStartIntent(context: Context, type: String, id: Long): Intent = + getStartIntent(context, type, id, "") fun getOfflineStartIntent(context: Context): Intent { return getStartIntent(context, Messages.Category.OFFLINE, 0) @@ -232,7 +229,9 @@ class TrackListActivity : BaseActivity(), Filterable { } fun getStartIntent(context: Context, type: String, id: Long, categoryValue: String): Intent { - val intent = getStartIntent(context, type, id) + val intent = Intent(context, TrackListActivity::class.java) + .putExtra(EXTRA_CATEGORY_TYPE, type) + .putExtra(EXTRA_SELECTED_ID, id) if (Strings.notEmpty(categoryValue)) { intent.putExtra( diff --git a/src/musikdroid/app/src/main/res/values/strings.xml b/src/musikdroid/app/src/main/res/values/strings.xml index 892600121..0dc0dd41d 100644 --- a/src/musikdroid/app/src/main/res/values/strings.xml +++ b/src/musikdroid/app/src/main/res/values/strings.xml @@ -8,7 +8,9 @@ songs songs from \'%1$s\' genres + genres from \'%1$s\' artists + artists from \'%1$s\' playlists connections pause