mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 20:13:36 +00:00
Basic filtering in browse view.
This commit is contained in:
parent
d3bc24480a
commit
9e4be0ff80
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user