mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-30 15:32:37 +00:00
Some refactors to prep for experimental Android tab UI.
This commit is contained in:
parent
4eff08a74d
commit
5e2da898c9
@ -12,8 +12,7 @@ import io.casey.musikcube.remote.service.websocket.model.ICategoryValue
|
||||
import io.casey.musikcube.remote.service.websocket.model.IDataProvider
|
||||
import io.casey.musikcube.remote.ui.albums.activity.AlbumBrowseActivity
|
||||
import io.casey.musikcube.remote.ui.category.adapter.CategoryBrowseAdapter
|
||||
import io.casey.musikcube.remote.ui.category.constant.NavigationType
|
||||
import io.casey.musikcube.remote.ui.category.constant.categoryToString
|
||||
import io.casey.musikcube.remote.ui.category.constant.*
|
||||
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.extension.*
|
||||
@ -25,6 +24,7 @@ import io.casey.musikcube.remote.ui.shared.view.EmptyListView
|
||||
import io.casey.musikcube.remote.ui.tracks.activity.TrackListActivity
|
||||
import io.casey.musikcube.remote.util.Debouncer
|
||||
import io.reactivex.rxkotlin.subscribeBy
|
||||
import java.lang.IllegalArgumentException
|
||||
import io.casey.musikcube.remote.service.websocket.WebSocketService.State as SocketState
|
||||
|
||||
class CategoryBrowseActivity : BaseActivity(), Filterable {
|
||||
@ -47,10 +47,10 @@ class CategoryBrowseActivity : BaseActivity(), Filterable {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
category = intent.getStringExtra(EXTRA_CATEGORY)
|
||||
predicateType = intent.getStringExtra(EXTRA_PREDICATE_TYPE) ?: ""
|
||||
predicateId = intent.getLongExtra(EXTRA_PREDICATE_ID, -1)
|
||||
navigationType = NavigationType.get(intent.getIntExtra(EXTRA_NAVIGATION_TYPE, NavigationType.Albums.ordinal))
|
||||
category = intent.getStringExtra(Category.Extra.CATEGORY)
|
||||
predicateType = intent.getStringExtra(Category.Extra.PREDICATE_TYPE) ?: ""
|
||||
predicateId = intent.getLongExtra(Category.Extra.PREDICATE_ID, -1)
|
||||
navigationType = NavigationType.get(intent.getIntExtra(Category.Extra.NAVIGATION_TYPE, NavigationType.Albums.ordinal))
|
||||
adapter = CategoryBrowseAdapter(adapterListener, playback, navigationType, category, prefs)
|
||||
|
||||
setContentView(R.layout.recycler_view_activity)
|
||||
@ -119,25 +119,28 @@ class CategoryBrowseActivity : BaseActivity(), Filterable {
|
||||
|
||||
private val categoryTypeString: String
|
||||
get() {
|
||||
CATEGORY_NAME_TO_EMPTY_TYPE[category]?.let {
|
||||
Category.NAME_TO_EMPTY_TYPE[category]?.let {
|
||||
return getString(it)
|
||||
}
|
||||
return categoryToString(this, category)
|
||||
return Category.toDisplayString(this, category)
|
||||
}
|
||||
|
||||
private val categoryTitleString: String
|
||||
get() {
|
||||
CATEGORY_NAME_TO_TITLE[category]?.let {
|
||||
Category.NAME_TO_TITLE[category]?.let {
|
||||
return getString(it)
|
||||
}
|
||||
return categoryToString(this, category)
|
||||
return Category.toDisplayString(this, category)
|
||||
}
|
||||
|
||||
private fun requery() {
|
||||
data.provider.getCategoryValues(category, predicateType, predicateId, lastFilter ?: "").subscribeBy(
|
||||
onNext = { values -> adapter.setModel(values) },
|
||||
onError = { },
|
||||
onComplete = { emptyView.update(data.provider.state, adapter.itemCount)})
|
||||
@Suppress("UNUSED")
|
||||
data.provider
|
||||
.getCategoryValues(category, predicateType, predicateId, lastFilter ?: "")
|
||||
.subscribeBy(
|
||||
onNext = { values -> adapter.setModel(values) },
|
||||
onError = { },
|
||||
onComplete = { emptyView.update(data.provider.state, adapter.itemCount)})
|
||||
}
|
||||
|
||||
private val filterDebouncer = object : Debouncer<String>(350) {
|
||||
@ -178,62 +181,45 @@ class CategoryBrowseActivity : BaseActivity(), Filterable {
|
||||
startActivity(TrackListActivity.getStartIntent(this, category, entry.id, entry.value))
|
||||
|
||||
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)
|
||||
setResult(RESULT_OK, Intent()
|
||||
.putExtra(Category.Extra.CATEGORY, category)
|
||||
.putExtra(Category.Extra.ID, id)
|
||||
.putExtra(Category.Extra.NAME, name))
|
||||
finish()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_CATEGORY = "extra_category"
|
||||
const val EXTRA_ID = "extra_id"
|
||||
const val EXTRA_NAME = "extra_name"
|
||||
private const val EXTRA_PREDICATE_TYPE = "extra_predicate_type"
|
||||
private const val EXTRA_PREDICATE_ID = "extra_predicate_id"
|
||||
private const val EXTRA_NAVIGATION_TYPE = "extra_navigation_type"
|
||||
private const val EXTRA_TITLE = "extra_title"
|
||||
|
||||
private val CATEGORY_NAME_TO_TITLE: Map<String, Int> = mapOf(
|
||||
Messages.Category.ALBUM_ARTIST to R.string.artists_title,
|
||||
Messages.Category.GENRE to R.string.genres_title,
|
||||
Messages.Category.ARTIST to R.string.artists_title,
|
||||
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,
|
||||
Messages.Category.ARTIST to R.string.browse_type_artists,
|
||||
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, predicateValue: String = ""): Intent {
|
||||
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)
|
||||
.putExtra(Category.Extra.CATEGORY, category)
|
||||
.putExtra(Category.Extra.PREDICATE_TYPE, predicateType)
|
||||
.putExtra(Category.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))
|
||||
if (predicateValue.isNotBlank() && Category.NAME_TO_RELATED_TITLE.containsKey(category)) {
|
||||
val format = Category.NAME_TO_RELATED_TITLE[category]
|
||||
when (format) {
|
||||
null -> throw IllegalArgumentException("unknown category $category")
|
||||
else -> intent.putExtra(EXTRA_ACTIVITY_TITLE, context.getString(format, predicateValue))
|
||||
}
|
||||
}
|
||||
|
||||
return intent
|
||||
}
|
||||
|
||||
fun getStartIntent(context: Context, category: String, navigationType: NavigationType, title: String = ""): Intent {
|
||||
fun getStartIntent(context: Context,
|
||||
category: String,
|
||||
navigationType: NavigationType,
|
||||
title: String = ""): Intent
|
||||
{
|
||||
return Intent(context, CategoryBrowseActivity::class.java)
|
||||
.putExtra(EXTRA_CATEGORY, category)
|
||||
.putExtra(EXTRA_NAVIGATION_TYPE, navigationType.ordinal)
|
||||
.putExtra(EXTRA_TITLE, title)
|
||||
.putExtra(Category.Extra.CATEGORY, category)
|
||||
.putExtra(Category.Extra.NAVIGATION_TYPE, navigationType.ordinal)
|
||||
.putExtra(Category.Extra.TITLE, title)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import io.casey.musikcube.remote.R
|
||||
import io.casey.musikcube.remote.ui.category.constant.categoryToString
|
||||
import io.casey.musikcube.remote.ui.category.constant.Category.toDisplayString
|
||||
|
||||
class AllCategoriesAdapter(private val listener: EventListener)
|
||||
: RecyclerView.Adapter<AllCategoriesAdapter.Holder>()
|
||||
@ -26,7 +26,7 @@ class AllCategoriesAdapter(private val listener: EventListener)
|
||||
}
|
||||
|
||||
internal fun bindView(category: String) {
|
||||
title.text = categoryToString(itemView.context, category)
|
||||
title.text = toDisplayString(itemView.context, category)
|
||||
itemView.tag = category
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package io.casey.musikcube.remote.ui.category.constant
|
||||
|
||||
import android.content.Context
|
||||
import io.casey.musikcube.remote.R
|
||||
import io.casey.musikcube.remote.service.websocket.Messages
|
||||
|
||||
private val categoryToStringIdMap = mapOf(
|
||||
"album" to R.string.category_artist,
|
||||
"album_artist" to R.string.category_album_artist,
|
||||
"artist" to R.string.category_artist,
|
||||
"bitrate" to R.string.category_bitrate,
|
||||
"comment" to R.string.category_comment,
|
||||
"composer" to R.string.category_composer,
|
||||
"conductor" to R.string.category_conductor,
|
||||
"copyright" to R.string.category_copyright,
|
||||
"genre" to R.string.category_genre,
|
||||
"publisher" to R.string.category_publisher,
|
||||
"year" to R.string.category_year)
|
||||
|
||||
object Category {
|
||||
val NAME_TO_TITLE: Map<String, Int> = mapOf(
|
||||
Messages.Category.ALBUM_ARTIST to R.string.artists_title,
|
||||
Messages.Category.GENRE to R.string.genres_title,
|
||||
Messages.Category.ARTIST to R.string.artists_title,
|
||||
Messages.Category.ALBUM to R.string.albums_title,
|
||||
Messages.Category.PLAYLISTS to R.string.playlists_title)
|
||||
|
||||
val 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)
|
||||
|
||||
val 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,
|
||||
Messages.Category.ARTIST to R.string.browse_type_artists,
|
||||
Messages.Category.ALBUM to R.string.browse_type_albums,
|
||||
Messages.Category.PLAYLISTS to R.string.browse_type_playlists)
|
||||
|
||||
fun toDisplayString(context: Context, category: String): String {
|
||||
categoryToStringIdMap[category]?.let {
|
||||
return context.getString(it)
|
||||
}
|
||||
return category
|
||||
}
|
||||
|
||||
object Extra {
|
||||
const val CATEGORY = "extra_category"
|
||||
const val ID = "extra_id"
|
||||
const val NAME = "extra_name"
|
||||
const val PREDICATE_TYPE = "extra_predicate_type"
|
||||
const val PREDICATE_ID = "extra_predicate_id"
|
||||
const val NAVIGATION_TYPE = "extra_navigation_type"
|
||||
const val TITLE = "extra_title"
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
package io.casey.musikcube.remote.ui.category.constant
|
||||
|
||||
import android.content.Context
|
||||
import io.casey.musikcube.remote.R
|
||||
|
||||
private val categoryToStringIdMap = mapOf(
|
||||
"album" to R.string.category_artist,
|
||||
"album_artist" to R.string.category_album_artist,
|
||||
"artist" to R.string.category_artist,
|
||||
"bitrate" to R.string.category_bitrate,
|
||||
"comment" to R.string.category_comment,
|
||||
"composer" to R.string.category_composer,
|
||||
"conductor" to R.string.category_conductor,
|
||||
"copyright" to R.string.category_copyright,
|
||||
"genre" to R.string.category_genre,
|
||||
"publisher" to R.string.category_publisher,
|
||||
"year" to R.string.category_year)
|
||||
|
||||
fun categoryToString(context: Context, category: String): String {
|
||||
categoryToStringIdMap[category]?.let {
|
||||
return context.getString(it)
|
||||
}
|
||||
return category
|
||||
}
|
@ -22,6 +22,7 @@ import io.casey.musikcube.remote.service.websocket.model.IDataProvider
|
||||
import io.casey.musikcube.remote.service.websocket.model.ITrack
|
||||
import io.casey.musikcube.remote.ui.albums.activity.AlbumBrowseActivity
|
||||
import io.casey.musikcube.remote.ui.category.activity.CategoryBrowseActivity
|
||||
import io.casey.musikcube.remote.ui.category.constant.Category
|
||||
import io.casey.musikcube.remote.ui.category.constant.NavigationType
|
||||
import io.casey.musikcube.remote.ui.shared.extension.hideKeyboard
|
||||
import io.casey.musikcube.remote.ui.shared.extension.showErrorSnackbar
|
||||
@ -80,8 +81,8 @@ class ItemContextMenuMixin(private val activity: AppCompatActivity,
|
||||
override fun onActivityResult(request: Int, result: Int, data: Intent?) {
|
||||
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)
|
||||
val playlistId = data.getLongExtra(Category.Extra.ID, -1L)
|
||||
val playlistName = data.getStringExtra(Category.Extra.NAME)
|
||||
if (playlistId != -1L) {
|
||||
completion?.invoke(playlistId, playlistName)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.11'
|
||||
ext.kotlin_version = '1.3.21'
|
||||
|
||||
repositories {
|
||||
google()
|
||||
@ -7,7 +7,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.3.0'
|
||||
classpath 'com.android.tools.build:gradle:3.3.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user