#52: implemented UI and functionnal filtering for all, me and subscribed. Funkwhale still does not seem to respect that.

This commit is contained in:
Antoine POPINEAU 2020-09-03 12:09:56 +02:00
parent 1e73ef6ee4
commit ce8d956cee
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
8 changed files with 114 additions and 23 deletions

View File

@ -55,6 +55,7 @@ class MainActivity : AppCompatActivity() {
private val favoriteRepository = FavoritesRepository(this)
private val favoritedRepository = FavoritedRepository(this)
private var menu: Menu? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -146,10 +147,18 @@ class MainActivity : AppCompatActivity() {
super.onBackPressed()
}
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
this.menu = menu
return super.onPrepareOptionsMenu(menu)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.toolbar, menu)
menu?.findItem(R.id.nav_only_my_music)?.isChecked = Settings.getScope() == "me"
menu?.findItem(R.id.nav_all_music)?.isChecked = Settings.getScopes().contains("all")
menu?.findItem(R.id.nav_my_music)?.isChecked = Settings.getScopes().contains("me")
menu?.findItem(R.id.nav_followed)?.isChecked = Settings.getScopes().contains("subscribed")
return true
}
@ -170,15 +179,48 @@ class MainActivity : AppCompatActivity() {
R.id.nav_queue -> launchDialog(QueueFragment())
R.id.nav_search -> startActivity(Intent(this, SearchActivity::class.java))
R.id.nav_only_my_music -> {
item.isChecked = !item.isChecked
R.id.nav_all_music, R.id.nav_my_music, R.id.nav_followed -> {
menu?.let { menu ->
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW)
item.actionView = View(this)
item.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
override fun onMenuItemActionExpand(item: MenuItem?) = false
override fun onMenuItemActionCollapse(item: MenuItem?) = false
})
when (item.isChecked) {
true -> PowerPreference.getDefaultFile().set("scope", "me")
false -> PowerPreference.getDefaultFile().set("scope", "all")
item.isChecked = !item.isChecked
val scopes = Settings.getScopes().toMutableSet()
val new = when (item.itemId) {
R.id.nav_my_music -> "me"
R.id.nav_followed -> "subscribed"
else -> {
menu.findItem(R.id.nav_my_music).isChecked = false
menu.findItem(R.id.nav_followed).isChecked = false
PowerPreference.getDefaultFile().set("scope", "all")
EventBus.send(Event.ListingsChanged)
return false
}
}
menu.findItem(R.id.nav_all_music).isChecked = false
scopes.remove("all")
when (item.isChecked) {
true -> scopes.add(new)
false -> scopes.remove(new)
}
PowerPreference.getDefaultFile().set("scope", scopes.joinToString(","))
EventBus.send(Event.ListingsChanged)
return false
}
EventBus.send(Event.ListingsChanged)
}
R.id.nav_downloads -> startActivity(Intent(this, DownloadsActivity::class.java))
R.id.settings -> startActivityForResult(Intent(this, SettingsActivity::class.java), 0)

View File

@ -33,7 +33,7 @@ class HttpUpstream<D : Any, R : OtterResponse<D>>(val behavior: Behavior, privat
.buildUpon()
.appendQueryParameter("page_size", AppContext.PAGE_SIZE.toString())
.appendQueryParameter("page", page.toString())
.appendQueryParameter("scope", Settings.getScope())
.appendQueryParameter("scope", Settings.getScopes().joinToString(","))
.build()
.toString()

View File

@ -75,5 +75,6 @@ object Settings {
fun getAccessToken(): String = PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).getString("access_token", "")
fun isAnonymous() = PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).getBoolean("anonymous", false)
fun areExperimentsEnabled() = PowerPreference.getDefaultFile().getBoolean("experiments", false)
fun getScope() = PowerPreference.getDefaultFile().getString("scope", "all")
fun getScopes() = PowerPreference.getDefaultFile().getString("scope", "all").split(",")
}

View File

@ -8,11 +8,29 @@
android:title="@string/toolbar_search"
app:showAsAction="ifRoom" />
<item
android:id="@+id/nav_only_my_music"
android:checkable="true"
android:title="@string/only_my_music"
app:showAsAction="never" />
<item android:title="@string/filters">
<menu>
<group android:checkableBehavior="all">
<item
android:id="@+id/nav_all_music"
android:checkable="true"
android:title="@string/fiters_all"
app:showAsAction="never" />
<item
android:id="@+id/nav_my_music"
android:checkable="true"
android:title="@string/filters_my_music"
app:showAsAction="never" />
<item
android:id="@+id/nav_followed"
android:checkable="true"
android:title="@string/filters_followed"
app:showAsAction="never" />
</group>
</menu>
</item>
<item
android:id="@+id/nav_downloads"

View File

@ -14,11 +14,29 @@
android:title="@string/toolbar_search"
app:showAsAction="ifRoom" />
<item
android:id="@+id/nav_only_my_music"
android:checkable="true"
android:title="@string/only_my_music"
app:showAsAction="never" />
<item android:title="@string/filters">
<menu>
<group android:checkableBehavior="all">
<item
android:id="@+id/nav_all_music"
android:checkable="true"
android:title="@string/fiters_all"
app:showAsAction="never" />
<item
android:id="@+id/nav_my_music"
android:checkable="true"
android:title="@string/filters_my_music"
app:showAsAction="never" />
<item
android:id="@+id/nav_followed"
android:checkable="true"
android:title="@string/filters_followed"
app:showAsAction="never" />
</group>
</menu>
</item>
<item
android:id="@+id/nav_downloads"

View File

@ -113,7 +113,10 @@
<item quantity="one">%1$d piste • %2$s</item>
<item quantity="other">%1$d pistes • %2$s</item>
</plurals>
<string name="only_my_music">Ma musique seulement</string>
<string name="filters">Filtres</string>
<string name="fiters_all">Toute la musique</string>
<string name="filters_my_music">Ma musique</string>
<string name="filters_followed">Contenu suivi</string>
<plurals name="downloads_description">
<item quantity="one">Téléchargement de %1$d piste</item>
<item quantity="other">Téléchargement de %1$d pistes</item>

View File

@ -114,7 +114,10 @@
<item quantity="one">%1$d track • %2$s"</item>
<item quantity="other">%1$d tracks • %2$s"</item>
</plurals>
<string name="only_my_music">Only my music</string>
<string name="filters">Filters</string>
<string name="fiters_all">All music</string>
<string name="filters_my_music">My music</string>
<string name="filters_followed">Followed content</string>
<plurals name="downloads_description">
<item quantity="one">Downloading %1$d track</item>
<item quantity="other">Downloading %1$d tracks</item>

View File

@ -69,7 +69,13 @@
<item name="android:drawableTint" tools:targetApi="m">@android:color/white</item>
<item name="android:tint">@android:color/white</item>
<item name="android:popupTheme">@style/ThemeOverlay.AppCompat.DayNight</item>
<item name="actionBarPopupTheme">@style/AppTheme.PopupMenu</item>
<item name="popupTheme">@style/AppTheme.PopupMenu</item>
</style>
<style name="AppTheme.PopupMenu" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="android:drawableTint" tools:targetApi="m">@color/blackWhileLight</item>
<item name="android:tint">@color/blackWhileLight</item>
</style>
<style name="AppTheme.FloatingBottomSheet" parent="Theme.MaterialComponents.DayNight.BottomSheetDialog">