Basic filtering in browse view.

This commit is contained in:
casey langen 2019-02-10 11:52:57 -08:00
parent d3bc24480a
commit 9e4be0ff80
2 changed files with 32 additions and 8 deletions

View File

@ -5,14 +5,17 @@ import android.content.Intent
import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.view.ViewPager
import android.view.Menu
import io.casey.musikcube.remote.R
import io.casey.musikcube.remote.ui.browse.adapter.BrowseFragmentAdapter
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.enableUpNavigation
import io.casey.musikcube.remote.ui.shared.extension.findFragment
import io.casey.musikcube.remote.ui.shared.extension.initSearchMenu
import io.casey.musikcube.remote.ui.shared.fragment.TransportFragment
class BrowseActivity: BaseActivity() {
class BrowseActivity: BaseActivity(), Filterable {
private lateinit var transport: TransportFragment
private lateinit var pager: ViewPager
private lateinit var tabs: TabLayout
@ -34,29 +37,31 @@ class BrowseActivity: BaseActivity() {
else -> restoreFragments()
}
transport.modelChangedListener = {
// transport.modelChangedListener = {
// content.notifyTransportChanged()
}
// }
enableUpNavigation()
}
// override fun onCreateOptionsMenu(menu: Menu): Boolean = content.createOptionsMenu(menu)
// override fun setFilter(filter: String) = content.setFilter(filter)
override fun onCreateOptionsMenu(menu: Menu): Boolean {
return initSearchMenu(menu, this)
}
override fun setFilter(filter: String) {
adapter.filter = filter
}
private fun createFragments() {
// content = CategoryBrowseFragment.create(intent)
transport = TransportFragment.create()
supportFragmentManager
.beginTransaction()
// .add(R.id.content_container, content, CategoryBrowseFragment.TAG)
.add(R.id.transport_container, transport, TransportFragment.TAG)
.commit()
}
private fun restoreFragments() {
transport = findFragment(TransportFragment.TAG)
// content = findFragment(CategoryBrowseFragment.TAG)
}
companion object {

View File

@ -4,12 +4,24 @@ import android.content.Context
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.view.ViewGroup
import io.casey.musikcube.remote.ui.albums.fragment.AlbumBrowseFragment
import io.casey.musikcube.remote.ui.category.constant.NavigationType
import io.casey.musikcube.remote.ui.category.fragment.CategoryBrowseFragment
import io.casey.musikcube.remote.ui.shared.activity.Filterable
import io.casey.musikcube.remote.ui.tracks.fragment.TrackListFragment
class BrowseFragmentAdapter(private val context: Context, fm: FragmentManager): FragmentPagerAdapter(fm) {
private val fragments = mutableMapOf<Int, Fragment>()
var filter = ""
set(value) {
field = value
fragments.forEach {
(it.value as? Filterable)?.setFilter(filter)
}
}
override fun getItem(index: Int): Fragment =
when (index) {
0 -> AlbumBrowseFragment.create()
@ -31,4 +43,11 @@ class BrowseFragmentAdapter(private val context: Context, fm: FragmentManager):
override fun getCount(): Int {
return 4
}
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val result = super.instantiateItem(container, position)
fragments[position] = result as Fragment
(result as? Filterable)?.setFilter(filter)
return result
}
}