From 4de7f0210b86f31ada359e97f39315a03394fcbc Mon Sep 17 00:00:00 2001 From: casey langen Date: Mon, 18 Feb 2019 01:16:12 -0800 Subject: [PATCH] More de-jank and cleanups. --- .../remote/injection/ViewComponent.kt | 2 + .../ui/albums/activity/AlbumBrowseActivity.kt | 1 - .../ui/albums/fragment/AlbumBrowseFragment.kt | 12 ++- .../ui/browse/activity/BrowseActivity.kt | 42 ++--------- .../ui/browse/fragment/BrowseFragment.kt | 2 - .../activity/AllCategoriesActivity.kt | 70 +++-------------- .../activity/CategoryBrowseActivity.kt | 1 - .../fragment/AllCategoriesFragment.kt | 75 +++++++++++++++++++ .../fragment/CategoryBrowseFragment.kt | 12 ++- .../remote/ui/home/activity/MainActivity.kt | 26 ++++--- .../remote/ui/navigation/Navigate.kt | 53 ++++++++++--- .../playqueue/fragment/PlayQueueFragment.kt | 5 +- .../remote/ui/shared/activity/BaseActivity.kt | 31 ++++++++ .../activity/FragmentActivityWithTransport.kt | 20 ++--- .../remote/ui/shared/extension/Extensions.kt | 4 +- .../remote/ui/shared/fragment/BaseFragment.kt | 19 +++-- .../remote/ui/shared/view/EmptyListView.kt | 15 +++- .../ui/tracks/activity/TrackListActivity.kt | 2 - .../ui/tracks/fragment/TrackListFragment.kt | 6 +- .../layout/recycler_view_with_empty_state.xml | 2 +- ...w_with_empty_state_and_toolbar_and_fab.xml | 7 +- .../app/src/main/res/layout/toolbar.xml | 1 + 22 files changed, 237 insertions(+), 171 deletions(-) create mode 100644 src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/fragment/AllCategoriesFragment.kt diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/injection/ViewComponent.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/injection/ViewComponent.kt index 51e43774b..6c5e64f1f 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/injection/ViewComponent.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/injection/ViewComponent.kt @@ -6,6 +6,7 @@ import io.casey.musikcube.remote.ui.albums.fragment.AlbumBrowseFragment import io.casey.musikcube.remote.ui.browse.activity.BrowseActivity import io.casey.musikcube.remote.ui.category.activity.AllCategoriesActivity import io.casey.musikcube.remote.ui.category.activity.CategoryBrowseActivity +import io.casey.musikcube.remote.ui.category.fragment.AllCategoriesFragment import io.casey.musikcube.remote.ui.category.fragment.CategoryBrowseFragment import io.casey.musikcube.remote.ui.home.activity.MainActivity import io.casey.musikcube.remote.ui.home.view.MainMetadataView @@ -40,6 +41,7 @@ interface ViewComponent { fun inject(activity: TrackListActivity) fun inject(fragment: AlbumBrowseFragment) + fun inject(fragment: AllCategoriesFragment) fun inject(fragment: BaseFragment) fun inject(fragment: CategoryBrowseFragment) fun inject(fragment: PlayQueueFragment) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/activity/AlbumBrowseActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/activity/AlbumBrowseActivity.kt index 787661845..59e7d0fd5 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/activity/AlbumBrowseActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/activity/AlbumBrowseActivity.kt @@ -18,7 +18,6 @@ class AlbumBrowseActivity: FragmentActivityWithTransport() { get() = content as AlbumBrowseFragment override fun onCreateOptionsMenu(menu: Menu): Boolean = albums.createOptionsMenu(menu) - override fun setFilter(filter: String) = albums.setFilter(filter) override fun onTransportChanged() = albums.onTransportChanged() override val contentFragmentTag: String = AlbumBrowseFragment.TAG diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/fragment/AlbumBrowseFragment.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/fragment/AlbumBrowseFragment.kt index 53ea5a4f6..5fc84e9fa 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/fragment/AlbumBrowseFragment.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/albums/fragment/AlbumBrowseFragment.kt @@ -2,7 +2,6 @@ package io.casey.musikcube.remote.ui.albums.fragment import android.content.Context import android.os.Bundle -import android.support.v4.view.ViewCompat import android.view.LayoutInflater import android.view.Menu import android.view.View @@ -18,7 +17,10 @@ import io.casey.musikcube.remote.ui.shared.activity.IFilterable import io.casey.musikcube.remote.ui.shared.activity.ITitleProvider import io.casey.musikcube.remote.ui.shared.activity.ITransportObserver import io.casey.musikcube.remote.ui.shared.constant.Shared -import io.casey.musikcube.remote.ui.shared.extension.* +import io.casey.musikcube.remote.ui.shared.extension.getLayoutId +import io.casey.musikcube.remote.ui.shared.extension.getTitleOverride +import io.casey.musikcube.remote.ui.shared.extension.initSearchMenu +import io.casey.musikcube.remote.ui.shared.extension.setupDefaultRecyclerView import io.casey.musikcube.remote.ui.shared.fragment.BaseFragment import io.casey.musikcube.remote.ui.shared.mixin.DataProviderMixin import io.casey.musikcube.remote.ui.shared.mixin.ItemContextMenuMixin @@ -57,8 +59,6 @@ class AlbumBrowseFragment: BaseFragment(), IFilterable, ITitleProvider, ITranspo override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = inflater.inflate(this.getLayoutId(), container, false).apply { - ViewCompat.setElevation(this, extras.elevation) - val recyclerView = findViewById(R.id.recycler_view) setupDefaultRecyclerView(recyclerView, adapter) @@ -66,8 +66,6 @@ class AlbumBrowseFragment: BaseFragment(), IFilterable, ITitleProvider, ITranspo emptyView.capability = EmptyListView.Capability.OnlineOnly emptyView.emptyMessage = getString(R.string.empty_no_items_format, getString(R.string.browse_type_albums)) emptyView.alternateView = recyclerView - - initToolbarIfNecessary(appCompatActivity, this) } override fun setFilter(filter: String) { @@ -83,7 +81,7 @@ class AlbumBrowseFragment: BaseFragment(), IFilterable, ITitleProvider, ITranspo override fun onTransportChanged() = adapter.notifyDataSetChanged() - override fun initObservables() { + override fun onInitObservables() { disposables.add(data.provider.observeState().subscribeBy( onNext = { state -> if (state.first == IDataProvider.State.Connected) { 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 0c9e1896b..eee62bb66 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 @@ -3,13 +3,10 @@ package io.casey.musikcube.remote.ui.browse.activity import android.content.Context import android.content.Intent import android.os.Bundle -import android.support.v4.app.Fragment -import android.support.v4.app.FragmentManager import io.casey.musikcube.remote.R import io.casey.musikcube.remote.ui.browse.constant.Browse import io.casey.musikcube.remote.ui.browse.fragment.BrowseFragment import io.casey.musikcube.remote.ui.shared.activity.BaseActivity -import io.casey.musikcube.remote.ui.shared.activity.IBackHandler import io.casey.musikcube.remote.ui.shared.activity.ITransportObserver import io.casey.musikcube.remote.ui.shared.extension.enableUpNavigation import io.casey.musikcube.remote.ui.shared.extension.findFragment @@ -37,19 +34,6 @@ class BrowseActivity: BaseActivity() { enableUpNavigation() } - override fun onBackPressed() { - (top as? IBackHandler)?.let { - if (it.onBackPressed()) { - return - } - } - - when { - fm.backStackEntryCount > 1 -> fm.popBackStack() - else -> super.onBackPressed() - } - } - private fun createFragments() { supportFragmentManager .beginTransaction() @@ -68,25 +52,11 @@ class BrowseActivity: BaseActivity() { supportFragmentManager.executePendingTransactions() } - private val top: Fragment? - get() { - return when { - fm.backStackEntryCount == 0 -> - fm.findFragmentByTag(BrowseFragment.TAG) - else -> fm.findFragmentByTag( - fm.getBackStackEntryAt(fm.backStackEntryCount - 1).name) - + companion object { + fun getStartIntent(context: Context, + initialCategoryType: String = ""): Intent = + Intent(context, BrowseActivity::class.java).apply { + putExtra(Browse.Extras.INITIAL_CATEGORY_TYPE, initialCategoryType) } - } - - private val fm: FragmentManager - get() = supportFragmentManager - - companion object { - fun getStartIntent(context: Context, - initialCategoryType: String = ""): Intent = - Intent(context, BrowseActivity::class.java).apply { - putExtra(Browse.Extras.INITIAL_CATEGORY_TYPE, initialCategoryType) - } - } + } } \ No newline at end of file diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/fragment/BrowseFragment.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/fragment/BrowseFragment.kt index cb81b0786..ec12b6773 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/fragment/BrowseFragment.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/browse/fragment/BrowseFragment.kt @@ -72,8 +72,6 @@ class BrowseFragment: BaseFragment(), ITransportObserver, IFilterable, ITitlePro } }) - initToolbarIfNecessary(appCompatActivity, this) - showFabIfNecessary(pager.currentItem) } diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/AllCategoriesActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/AllCategoriesActivity.kt index dd69dfc15..58e05a952 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/AllCategoriesActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/AllCategoriesActivity.kt @@ -2,69 +2,17 @@ package io.casey.musikcube.remote.ui.category.activity import android.content.Context import android.content.Intent -import android.os.Bundle -import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView -import io.casey.musikcube.remote.R -import io.casey.musikcube.remote.service.websocket.model.IDataProvider -import io.casey.musikcube.remote.ui.category.adapter.AllCategoriesAdapter -import io.casey.musikcube.remote.ui.shared.activity.BaseActivity -import io.casey.musikcube.remote.ui.shared.extension.addTransportFragment -import io.casey.musikcube.remote.ui.shared.extension.enableUpNavigation -import io.casey.musikcube.remote.ui.shared.extension.setupDefaultRecyclerView -import io.casey.musikcube.remote.ui.shared.mixin.DataProviderMixin -import io.reactivex.rxkotlin.subscribeBy +import io.casey.musikcube.remote.ui.category.fragment.AllCategoriesFragment +import io.casey.musikcube.remote.ui.shared.activity.FragmentActivityWithTransport +import io.casey.musikcube.remote.ui.shared.extension.withToolbar +import io.casey.musikcube.remote.ui.shared.fragment.BaseFragment -class AllCategoriesActivity: BaseActivity() { - private lateinit var data: DataProviderMixin - private lateinit var adapter: AllCategoriesAdapter +class AllCategoriesActivity: FragmentActivityWithTransport() { + override fun createContentFragment(): BaseFragment = + AllCategoriesFragment().withToolbar() - override fun onCreate(savedInstanceState: Bundle?) { - component.inject(this) - data = mixin(DataProviderMixin()) - - super.onCreate(savedInstanceState) - - setTitle(R.string.category_activity) - setContentView(R.layout.recycler_view_activity) - - val recyclerView = findViewById(R.id.recycler_view) - adapter = AllCategoriesAdapter(adapterListener) - - setupDefaultRecyclerView(recyclerView, adapter) - enableUpNavigation() - addTransportFragment() - } - - override fun onResume() { - super.onResume() - initObservers() - } - - private fun requery() { - disposables.add(data.provider.listCategories().subscribeBy( - onNext = { - adapter.setModel(it) - }, - onError = { - })) - } - - private fun initObservers() { - disposables.add(data.provider.observeState().subscribeBy( - onNext = { states -> - if (states.first == IDataProvider.State.Connected) { - requery() - } - }, - onError = { - })) - } - - private val adapterListener = object:AllCategoriesAdapter.EventListener { - override fun onItemClicked(category: String) { - startActivity(CategoryBrowseActivity.getStartIntent(this@AllCategoriesActivity, category)) - } - } + override val contentFragmentTag: String = + AllCategoriesFragment.TAG companion object { fun getStartIntent(context: Context): Intent { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/CategoryBrowseActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/CategoryBrowseActivity.kt index 83376c928..53c46a553 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/CategoryBrowseActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/activity/CategoryBrowseActivity.kt @@ -16,7 +16,6 @@ class CategoryBrowseActivity: FragmentActivityWithTransport() { get() = content as CategoryBrowseFragment override fun onCreateOptionsMenu(menu: Menu): Boolean = category.createOptionsMenu(menu) - override fun setFilter(filter: String) = category.setFilter(filter) override fun onTransportChanged() = category.onTransportChanged() override val contentFragmentTag: String = CategoryBrowseFragment.TAG diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/fragment/AllCategoriesFragment.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/fragment/AllCategoriesFragment.kt new file mode 100644 index 000000000..e0bd452ff --- /dev/null +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/fragment/AllCategoriesFragment.kt @@ -0,0 +1,75 @@ +package io.casey.musikcube.remote.ui.category.fragment + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView +import io.casey.musikcube.remote.R +import io.casey.musikcube.remote.service.websocket.model.IDataProvider +import io.casey.musikcube.remote.ui.category.adapter.AllCategoriesAdapter +import io.casey.musikcube.remote.ui.navigation.Navigate +import io.casey.musikcube.remote.ui.shared.activity.ITitleProvider +import io.casey.musikcube.remote.ui.shared.extension.getLayoutId +import io.casey.musikcube.remote.ui.shared.extension.setupDefaultRecyclerView +import io.casey.musikcube.remote.ui.shared.fragment.BaseFragment +import io.casey.musikcube.remote.ui.shared.mixin.DataProviderMixin +import io.reactivex.rxkotlin.subscribeBy + +class AllCategoriesFragment: BaseFragment(), ITitleProvider { + private lateinit var data: DataProviderMixin + private lateinit var adapter: AllCategoriesAdapter + + override val title: String + get() = getString(R.string.category_activity) + + override fun onCreate(savedInstanceState: Bundle?) { + component.inject(this) + data = mixin(DataProviderMixin()) + + super.onCreate(savedInstanceState) + + adapter = AllCategoriesAdapter(adapterListener) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = + inflater.inflate(this.getLayoutId(), container, false).apply { + val recyclerView = findViewById(R.id.recycler_view) + setupDefaultRecyclerView(recyclerView, adapter) + } + + override fun onInitObservables() { + disposables.add(data.provider.observeState().subscribeBy( + onNext = { states -> + if (states.first == IDataProvider.State.Connected) { + requery() + } + }, + onError = { + })) + } + + private fun requery() { + disposables.add(data.provider.listCategories().subscribeBy( + onNext = { + adapter.setModel(it) + }, + onError = { + })) + } + + + private val adapterListener = object:AllCategoriesAdapter.EventListener { + override fun onItemClicked(category: String) = + Navigate.toCategoryList( + category, + appCompatActivity, + this@AllCategoriesFragment) + } + + companion object { + const val TAG = "AllCategoriesFragment" + + fun create(): AllCategoriesFragment = AllCategoriesFragment() + } +} \ No newline at end of file diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/fragment/CategoryBrowseFragment.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/fragment/CategoryBrowseFragment.kt index 56a5e3ea3..50e5054f3 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/fragment/CategoryBrowseFragment.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/category/fragment/CategoryBrowseFragment.kt @@ -5,7 +5,6 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.support.design.widget.FloatingActionButton -import android.support.v4.view.ViewCompat import android.view.LayoutInflater import android.view.Menu import android.view.View @@ -24,7 +23,10 @@ import io.casey.musikcube.remote.ui.shared.activity.IFilterable import io.casey.musikcube.remote.ui.shared.activity.ITitleProvider import io.casey.musikcube.remote.ui.shared.activity.ITransportObserver import io.casey.musikcube.remote.ui.shared.constant.Shared -import io.casey.musikcube.remote.ui.shared.extension.* +import io.casey.musikcube.remote.ui.shared.extension.getLayoutId +import io.casey.musikcube.remote.ui.shared.extension.getTitleOverride +import io.casey.musikcube.remote.ui.shared.extension.initSearchMenu +import io.casey.musikcube.remote.ui.shared.extension.setupDefaultRecyclerView import io.casey.musikcube.remote.ui.shared.fragment.BaseFragment import io.casey.musikcube.remote.ui.shared.mixin.DataProviderMixin import io.casey.musikcube.remote.ui.shared.mixin.ItemContextMenuMixin @@ -75,10 +77,7 @@ class CategoryBrowseFragment: BaseFragment(), IFilterable, ITitleProvider, ITran override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = inflater.inflate(this.getLayoutId(), container, false).apply { - ViewCompat.setElevation(this, extras.elevation) - this@CategoryBrowseFragment.rootView = this - val recyclerView = findViewById(R.id.recycler_view) emptyView = findViewById(R.id.empty_list_view) @@ -87,7 +86,6 @@ class CategoryBrowseFragment: BaseFragment(), IFilterable, ITitleProvider, ITran emptyView.alternateView = recyclerView setupDefaultRecyclerView(recyclerView, adapter) - initToolbarIfNecessary(appCompatActivity, this) } override fun onFabPress(fab: FloatingActionButton) { @@ -113,7 +111,7 @@ class CategoryBrowseFragment: BaseFragment(), IFilterable, ITitleProvider, ITran override fun onTransportChanged() = adapter.notifyDataSetChanged() - override fun initObservables() { + override fun onInitObservables() { disposables.add(data.provider.observeState().subscribeBy( onNext = { states -> when (states.first) { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/activity/MainActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/activity/MainActivity.kt index 6a06de241..e6fd517bb 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/activity/MainActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/home/activity/MainActivity.kt @@ -20,13 +20,11 @@ import io.casey.musikcube.remote.service.playback.impl.remote.Metadata import io.casey.musikcube.remote.service.websocket.WebSocketService 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.activity.AllCategoriesActivity import io.casey.musikcube.remote.ui.category.activity.CategoryBrowseActivity import io.casey.musikcube.remote.ui.category.constant.NavigationType import io.casey.musikcube.remote.ui.home.fragment.InvalidPasswordDialogFragment import io.casey.musikcube.remote.ui.home.view.MainMetadataView import io.casey.musikcube.remote.ui.navigation.Navigate -import io.casey.musikcube.remote.ui.playqueue.activity.PlayQueueActivity import io.casey.musikcube.remote.ui.settings.activity.RemoteSettingsActivity import io.casey.musikcube.remote.ui.settings.activity.SettingsActivity import io.casey.musikcube.remote.ui.settings.constants.Prefs @@ -177,7 +175,7 @@ class MainActivity : BaseActivity() { } R.id.action_categories -> { - startActivity(AllCategoriesActivity.getStartIntent(this)) + Navigate.toAllCategories(this) return true } @@ -300,11 +298,9 @@ class MainActivity : BaseActivity() { } findViewById(R.id.button_play_pause).setOnClickListener { - if (playback.service.state === PlaybackState.Stopped) { - playback.service.playAll() - } - else { - playback.service.pauseOrResume() + when (playback.service.state === PlaybackState.Stopped) { + true -> playback.service.playAll() + else -> playback.service.pauseOrResume() } } @@ -370,8 +366,15 @@ class MainActivity : BaseActivity() { } findViewById(R.id.metadata_container).setOnClickListener { - if (playback.service.queueCount > 0) { - navigateToPlayQueue() + when (playback.service.queueCount > 0) { + true -> navigateToPlayQueue() + else -> Navigate.toBrowse(this) + } + } + + findViewById(R.id.middle_container).setOnClickListener { + if (data.wss.state == WebSocketService.State.Connected) { + Navigate.toBrowse(this) } } @@ -484,8 +487,7 @@ class MainActivity : BaseActivity() { } private fun navigateToPlayQueue() { - startActivity(PlayQueueActivity.getStartIntent( - this@MainActivity, playback.service.queuePosition)) + Navigate.toPlayQueue(playback.service.queuePosition, this) } private fun scheduleUpdateTime(immediate: Boolean) { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/navigation/Navigate.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/navigation/Navigate.kt index c0049b1cd..b02ce412f 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/navigation/Navigate.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/navigation/Navigate.kt @@ -5,7 +5,6 @@ import android.os.Bundle import android.support.v4.app.ActivityOptionsCompat import android.support.v4.util.Pair import android.support.v7.app.AppCompatActivity -import android.view.View import io.casey.musikcube.remote.R import io.casey.musikcube.remote.service.playback.impl.remote.Metadata import io.casey.musikcube.remote.service.websocket.model.IAlbum @@ -13,7 +12,7 @@ import io.casey.musikcube.remote.service.websocket.model.ICategoryValue import io.casey.musikcube.remote.ui.albums.activity.AlbumBrowseActivity import io.casey.musikcube.remote.ui.albums.fragment.AlbumBrowseFragment import io.casey.musikcube.remote.ui.browse.activity.BrowseActivity -import io.casey.musikcube.remote.ui.browse.constant.Browse +import io.casey.musikcube.remote.ui.category.activity.AllCategoriesActivity import io.casey.musikcube.remote.ui.category.activity.CategoryBrowseActivity import io.casey.musikcube.remote.ui.category.constant.NavigationType import io.casey.musikcube.remote.ui.category.fragment.CategoryBrowseFragment @@ -37,14 +36,16 @@ object Navigate { initialCategoryType: String = "") = activity.startActivity( BrowseActivity.getStartIntent(activity, initialCategoryType), - when (activity is MainActivity) { - true -> ActivityOptionsCompat.makeSceneTransitionAnimation( - activity, - Pair(activity.findViewById(R.id.PlayControls), "play_controls_transition"), -// Pair(activity.findViewById(R.id.button_play_queue), "play_queue_transition"), - Pair(activity.findViewById(R.id.toolbar), "toolbar_transition")).toBundle() - false -> Bundle() - }) + createMainTransition(activity)) + + /* + * + * list of categories + * + */ + + fun toAllCategories(activity: AppCompatActivity) = + activity.startActivity(AllCategoriesActivity.getStartIntent(activity)) /* * @@ -137,6 +138,19 @@ object Navigate { .getStartIntent(activity, targetType, sourceType, sourceId, sourceValue)) } + fun toCategoryList(targetType: String, + activity: AppCompatActivity, + fragment: BaseFragment? = null) = + when (fragment != null && fragment.pushContainerId > 0) { + true -> + fragment.pushWithToolbar( + fragment.pushContainerId, + "$targetType)", + CategoryBrowseFragment.create(activity, targetType)) + false -> + activity.startActivity(CategoryBrowseActivity.getStartIntent(activity, targetType)) + } + /* * * playlist-related @@ -216,4 +230,23 @@ object Navigate { .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)) } } + + /* + * + * transition stuff + * + */ + + private fun createMainTransition(activity: AppCompatActivity) = + when (activity is MainActivity) { + true -> + ActivityOptionsCompat.makeSceneTransitionAnimation( + activity, + Pair(activity.findViewById(R.id.PlayControls), "play_controls_transition"), +// Pair(activity.findViewById(R.id.middle_container), "middle_content_transition"), +// Pair(activity.findViewById(R.id.button_play_queue), "play_queue_transition"), + Pair(activity.findViewById(R.id.toolbar), "toolbar_transition")).toBundle() + false -> + Bundle() + } } \ No newline at end of file diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/playqueue/fragment/PlayQueueFragment.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/playqueue/fragment/PlayQueueFragment.kt index 020530c0f..eeee56d01 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/playqueue/fragment/PlayQueueFragment.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/playqueue/fragment/PlayQueueFragment.kt @@ -46,8 +46,6 @@ class PlayQueueFragment: BaseFragment(), ITitleProvider { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = inflater.inflate(this.getLayoutId(), container, false).apply { - ViewCompat.setElevation(this, extras.elevation) - val queryFactory = playback.service.playlistQueryFactory offlineQueue = playback.service.playlistQueryFactory.offline() @@ -58,7 +56,6 @@ class PlayQueueFragment: BaseFragment(), ITitleProvider { adapter = PlayQueueAdapter(tracks, playback, prefs, adapterListener) setupDefaultRecyclerView(recyclerView, adapter) - initToolbarIfNecessary(appCompatActivity, this, searchMenu = false) emptyView = findViewById(R.id.empty_list_view) emptyView.capability = EmptyListView.Capability.OfflineOk @@ -79,7 +76,7 @@ class PlayQueueFragment: BaseFragment(), ITitleProvider { } } - override fun initObservables() { + override fun onInitObservables() { disposables.add(data.provider.observeState().subscribeBy( onNext = { states -> if (states.first == IDataProvider.State.Connected) { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/BaseActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/BaseActivity.kt index 924e6f263..20b8b5c0c 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/BaseActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/BaseActivity.kt @@ -5,6 +5,8 @@ import android.content.Intent import android.content.SharedPreferences import android.media.AudioManager import android.os.Bundle +import android.support.v4.app.Fragment +import android.support.v4.app.FragmentManager import android.support.v7.app.AppCompatActivity import android.view.KeyEvent import android.view.MenuItem @@ -18,6 +20,7 @@ import io.casey.musikcube.remote.framework.MixinSet import io.casey.musikcube.remote.framework.ViewModel import io.casey.musikcube.remote.injection.DaggerViewComponent import io.casey.musikcube.remote.injection.ViewComponent +import io.casey.musikcube.remote.ui.browse.fragment.BrowseFragment import io.casey.musikcube.remote.ui.navigation.Transition import io.casey.musikcube.remote.ui.settings.constants.Prefs import io.casey.musikcube.remote.ui.shared.extension.* @@ -94,6 +97,20 @@ abstract class BaseActivity : AppCompatActivity(), ViewModel.Provider, Runner.Ta mixins.onDestroy() } + + override fun onBackPressed() { + (top as? IBackHandler)?.let { + if (it.onBackPressed()) { + return + } + } + + when { + fm.backStackEntryCount > 1 -> fm.popBackStack() + else -> super.onBackPressed() + } + } + override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { if (mixin(PlaybackMixin::class.java)?.onKeyDown(keyCode) == true) { return true @@ -144,6 +161,20 @@ abstract class BaseActivity : AppCompatActivity(), ViewModel.Provider, Runner.Ta toolbar?.let { setSupportActionBar(it) } } + protected val top: Fragment? + get() { + return when { + fm.backStackEntryCount == 0 -> + fm.findFragmentByTag(BrowseFragment.TAG) + else -> fm.findFragmentByTag( + fm.getBackStackEntryAt(fm.backStackEntryCount - 1).name) + + } + } + + protected val fm: FragmentManager + get() = supportFragmentManager + protected open val transitionType = Transition.Horizontal protected val extras: Bundle diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/FragmentActivityWithTransport.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/FragmentActivityWithTransport.kt index db4d2b65d..5fb731328 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/FragmentActivityWithTransport.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/activity/FragmentActivityWithTransport.kt @@ -11,7 +11,7 @@ import io.casey.musikcube.remote.ui.shared.extension.* import io.casey.musikcube.remote.ui.shared.fragment.BaseFragment import io.casey.musikcube.remote.ui.shared.fragment.TransportFragment -abstract class FragmentActivityWithTransport: BaseActivity(), IFilterable { +abstract class FragmentActivityWithTransport: BaseActivity() { private var transport: TransportFragment? = null protected lateinit var content: BaseFragment @@ -76,11 +76,6 @@ abstract class FragmentActivityWithTransport: BaseActivity(), IFilterable { return super.onOptionsItemSelected(item) } - override fun setFilter(filter: String) = - (content as? IFilterable)?.run { - setFilter(filter) - } ?: Unit - override val transitionType: Transition get() = extras.transitionType @@ -93,13 +88,18 @@ abstract class FragmentActivityWithTransport: BaseActivity(), IFilterable { private fun createFragments() { content = createContentFragment() - .withToolbar().withTitleOverride(this) + .withToolbar() + .withTitleOverride(this) + .pushTo(R.id.content_container) supportFragmentManager.beginTransaction().apply { add(R.id.content_container, content, contentFragmentTag) if (!withoutTransport) { - transport = TransportFragment.create().apply { - add(R.id.transport_container, this, TransportFragment.TAG) - } + transport = TransportFragment + .create() + .pushTo(R.id.content_container) + .apply { + add(R.id.transport_container, this, TransportFragment.TAG) + } } commit() } diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt index 94e5d5fde..b0bce5427 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt @@ -286,7 +286,7 @@ fun BaseFragment.pushWithToolbar( } inline fun T.withToolbar(): T { - this.arguments?.putBoolean(Shared.Extra.WITH_TOOLBAR, true) + this.extras.putBoolean(Shared.Extra.WITH_TOOLBAR, true) return this } @@ -323,7 +323,7 @@ fun BaseFragment.initToolbarIfNecessary(activity: AppCompatActivity, view: View, fun BaseFragment.getLayoutId(): Int = when (this.extras.getBoolean(Shared.Extra.WITH_TOOLBAR)) { true -> R.layout.recycler_view_with_empty_state_and_toolbar_and_fab - else -> R.layout.recycler_view_with_empty_state + false -> R.layout.recycler_view_with_empty_state } inline fun T.addElevation(fm: FragmentManager): T { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/fragment/BaseFragment.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/fragment/BaseFragment.kt index 1211192a0..0811f8175 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/fragment/BaseFragment.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/fragment/BaseFragment.kt @@ -6,6 +6,7 @@ import android.content.SharedPreferences import android.os.Bundle import android.os.Handler import android.support.v4.app.Fragment +import android.support.v4.view.ViewCompat import android.support.v7.app.AppCompatActivity import android.support.v7.widget.Toolbar import android.view.View @@ -23,6 +24,8 @@ import io.casey.musikcube.remote.ui.settings.constants.Prefs import io.casey.musikcube.remote.ui.shared.activity.IBackHandler import io.casey.musikcube.remote.ui.shared.activity.ITitleProvider import io.casey.musikcube.remote.ui.shared.extension.collapseActionViewIfExpanded +import io.casey.musikcube.remote.ui.shared.extension.elevation +import io.casey.musikcube.remote.ui.shared.extension.initToolbarIfNecessary import io.casey.musikcube.remote.ui.shared.extension.setTitleFromIntent import io.casey.musikcube.remote.ui.shared.mixin.ViewModelMixin import io.reactivex.disposables.CompositeDisposable @@ -43,20 +46,20 @@ open class BaseFragment: Fragment(), ViewModel.Provider, IBackHandler { private set(value) { field = value when (field) { - true -> destroyObservables() - false -> initObservables() + true -> onDestroyObservables() + false -> onInitObservables() } } protected var disposables = CompositeDisposable() private set - private fun destroyObservables() { + private fun onDestroyObservables() { disposables.dispose() disposables = CompositeDisposable() } - protected open fun initObservables() { + protected open fun onInitObservables() { /* for subclass use */ } @@ -67,6 +70,12 @@ open class BaseFragment: Fragment(), ViewModel.Provider, IBackHandler { handler.post { onPostCreate(savedInstanceState) } } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + ViewCompat.setElevation(view, extras.elevation) + initToolbarIfNecessary(appCompatActivity, view) + } + open fun onPostCreate(savedInstanceState: Bundle?) { } @@ -84,7 +93,7 @@ open class BaseFragment: Fragment(), ViewModel.Provider, IBackHandler { toolbar?.setTitleFromIntent(title) } if (!animating) { - initObservables() + onInitObservables() } } diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/view/EmptyListView.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/view/EmptyListView.kt index 891379401..6ee3eac85 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/view/EmptyListView.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/view/EmptyListView.kt @@ -50,7 +50,10 @@ class EmptyListView : FrameLayout { var alternateView: View? = null set(value) { field = value - alternateView?.visibility = if (visibility == View.GONE) View.VISIBLE else View.GONE + alternateView?.visibility = when (visibility == View.VISIBLE) { + true -> View.GONE + false -> View.VISIBLE + } } var emptyMessage: String @@ -77,7 +80,10 @@ class EmptyListView : FrameLayout { emptyContainer?.setVisible(!showOfflineContainer) } - alternateView?.visibility = if (visibility == View.GONE) View.VISIBLE else View.GONE + alternateView?.visibility = when (visibility == View.VISIBLE) { + true -> View.GONE + false -> View.VISIBLE + } } fun update(state: IDataProvider.State, count: Int) { @@ -96,7 +102,10 @@ class EmptyListView : FrameLayout { emptyContainer?.setVisible(!showOfflineContainer) } - alternateView?.visibility = if (visibility == View.INVISIBLE) View.VISIBLE else View.INVISIBLE + alternateView?.visibility = when (visibility == View.INVISIBLE) { + true -> View.VISIBLE + false -> View.INVISIBLE + } } private fun initialize() { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/TrackListActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/TrackListActivity.kt index a880f3763..73cb2e104 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/TrackListActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/activity/TrackListActivity.kt @@ -25,9 +25,7 @@ class TrackListActivity: FragmentActivityWithTransport() { } override fun createContentFragment(): BaseFragment = TrackListFragment.create(intent) - override val contentFragmentTag: String = TrackListFragment.TAG - override fun onTransportChanged() = tracks.onTransportChanged() companion object { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/fragment/TrackListFragment.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/fragment/TrackListFragment.kt index 1bb525d7b..7b7d571d2 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/fragment/TrackListFragment.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/tracks/fragment/TrackListFragment.kt @@ -3,7 +3,6 @@ package io.casey.musikcube.remote.ui.tracks.fragment import android.content.Context import android.content.Intent import android.os.Bundle -import android.support.v4.view.ViewCompat import android.support.v7.app.AppCompatActivity import android.view.* import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView @@ -81,7 +80,7 @@ class TrackListFragment: BaseFragment(), IFilterable, ITitleProvider, ITransport requeryIfViewingOfflineCache() } - override fun initObservables() { + override fun onInitObservables() { disposables.add(data.provider.observeState().subscribeBy( onNext = { states -> val shouldRequery = @@ -102,15 +101,12 @@ class TrackListFragment: BaseFragment(), IFilterable, ITitleProvider, ITransport override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = inflater.inflate(this.getLayoutId(), container, false).apply { - ViewCompat.setElevation(this, extras.elevation) - val recyclerView = findViewById(R.id.recycler_view) tracks = DefaultSlidingWindow(recyclerView, data.provider, queryFactory) adapter = TrackListAdapter(tracks, eventListener, playback, prefs) setupDefaultRecyclerView(recyclerView, adapter) - initToolbarIfNecessary(appCompatActivity, this, searchMenu = false) emptyView = findViewById(R.id.empty_list_view) diff --git a/src/musikdroid/app/src/main/res/layout/recycler_view_with_empty_state.xml b/src/musikdroid/app/src/main/res/layout/recycler_view_with_empty_state.xml index fd5baee6b..5e5f40d64 100644 --- a/src/musikdroid/app/src/main/res/layout/recycler_view_with_empty_state.xml +++ b/src/musikdroid/app/src/main/res/layout/recycler_view_with_empty_state.xml @@ -11,7 +11,7 @@ style="@style/RecyclerView" android:id="@+id/recycler_view" android:layout_width="match_parent" - android:layout_height="match_parent" /> + android:layout_height="match_parent"/> - + + android:layout_height="match_parent"/>