mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-29 19:20:28 +00:00
More context menu handling fixes. Lots of cross linkage!
This commit is contained in:
parent
c41e89367c
commit
a573265092
@ -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)
|
||||
|
@ -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<String, Int> = 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<String, Int> = 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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -8,7 +8,9 @@
|
||||
<string name="songs_title">songs</string>
|
||||
<string name="songs_from_category">songs from \'%1$s\'</string>
|
||||
<string name="genres_title">genres</string>
|
||||
<string name="genres_from_category">genres from \'%1$s\'</string>
|
||||
<string name="artists_title">artists</string>
|
||||
<string name="artists_from_category">artists from \'%1$s\'</string>
|
||||
<string name="playlists_title">playlists</string>
|
||||
<string name="connections_title">connections</string>
|
||||
<string name="button_pause">pause</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user