diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/activity/BrowseActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/activity/BrowseActivity.kt index 7823d193e..9f96bc8f6 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/activity/BrowseActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/activity/BrowseActivity.kt @@ -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 { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/adapter/BrowseFragmentAdapter.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/adapter/BrowseFragmentAdapter.kt index aefb8176d..2fed8cd3c 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/adapter/BrowseFragmentAdapter.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/adapter/BrowseFragmentAdapter.kt @@ -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() + + 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 + } } \ No newline at end of file