From 94fdfbbf78dfc397a1ae12768041dc09a7de1a64 Mon Sep 17 00:00:00 2001 From: Oliver Spryn <2717340+oliverspryn@users.noreply.github.com> Date: Fri, 8 Mar 2019 14:45:49 -0500 Subject: [PATCH 01/14] Got some reduxy routing working for the tablet no selection view! --- sermons/build.gradle | 2 + .../android/sermons/actions/RoutingAction.kt | 7 ++ .../android/sermons/di/DaggerInjector.kt | 7 +- .../android/sermons/di/ProfileModule.kt | 4 +- .../android/sermons/di/RoutingModule.kt | 15 +++++ .../android/sermons/di/SermonPlayerModule.kt | 12 ++++ .../android/sermons/di/SermonsComponent.kt | 2 +- .../android/sermons/di/SermonsModule.kt | 6 +- .../middleware/PermissionMiddleware.kt | 4 +- .../sermons/reducers/RoutingReducer.kt | 26 +++++++ .../sermons/reducers/SermonsReducer.kt | 17 +++++ .../android/sermons/ui/NoSelectionFragment.kt | 18 +++++ .../android/sermons/ui/SermonsActivity.kt | 67 +++++++++++-------- .../src/main/res/drawable/no_selection.xml | 56 ++++++++++++++++ .../main/res/layout/no_selection_fragment.xml | 34 ++++++++++ sermons/src/main/res/values/strings.xml | 6 ++ 16 files changed, 243 insertions(+), 40 deletions(-) create mode 100644 sermons/src/main/java/com/branhamplayer/android/sermons/actions/RoutingAction.kt create mode 100644 sermons/src/main/java/com/branhamplayer/android/sermons/di/RoutingModule.kt create mode 100644 sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonPlayerModule.kt create mode 100644 sermons/src/main/java/com/branhamplayer/android/sermons/reducers/RoutingReducer.kt create mode 100644 sermons/src/main/java/com/branhamplayer/android/sermons/ui/NoSelectionFragment.kt create mode 100644 sermons/src/main/res/drawable/no_selection.xml create mode 100644 sermons/src/main/res/layout/no_selection_fragment.xml diff --git a/sermons/build.gradle b/sermons/build.gradle index 5cd3e0a..05b82d8 100644 --- a/sermons/build.gradle +++ b/sermons/build.gradle @@ -16,6 +16,8 @@ android { minSdkVersion min_sdk_version targetSdkVersion target_sdk_version + + vectorDrawables.useSupportLibrary = true } buildTypes { diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/actions/RoutingAction.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/actions/RoutingAction.kt new file mode 100644 index 0000000..7b30595 --- /dev/null +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/actions/RoutingAction.kt @@ -0,0 +1,7 @@ +package com.branhamplayer.android.sermons.actions + +import org.rekotlin.Action + +sealed class RoutingAction : Action { + object NavigateToNoSelectionAction : RoutingAction() +} diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/di/DaggerInjector.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/di/DaggerInjector.kt index b836e6a..f86650a 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/di/DaggerInjector.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/di/DaggerInjector.kt @@ -1,18 +1,15 @@ package com.branhamplayer.android.sermons.di -import androidx.appcompat.app.AppCompatActivity -import com.branhamplayer.android.di.AuthenticationModule +import com.branhamplayer.android.sermons.ui.SermonsActivity object DaggerInjector { var sermonsComponent: SermonsComponent? = null private set - fun buildSermonsComponent(activity: AppCompatActivity): SermonsComponent { + fun buildSermonsComponent(activity: SermonsActivity): SermonsComponent { val component = sermonsComponent ?: DaggerSermonsComponent .builder() - .authenticationModule(AuthenticationModule()) - .rxJavaModule(RxJavaModule()) .sermonsModule(SermonsModule(activity)) .build() diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/di/ProfileModule.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/di/ProfileModule.kt index 72990fb..9713bc1 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/di/ProfileModule.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/di/ProfileModule.kt @@ -13,7 +13,9 @@ class ProfileModule { @Provides fun provideProfileMiddleware( - auth0Service: Auth0Service, @Named(RxJavaModule.BG) bg: Scheduler, @Named(RxJavaModule.UI) ui: Scheduler + auth0Service: Auth0Service, + @Named(RxJavaModule.BG) bg: Scheduler, + @Named(RxJavaModule.UI) ui: Scheduler ) = ProfileMiddleware(auth0Service, bg, ui) @Provides diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/di/RoutingModule.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/di/RoutingModule.kt new file mode 100644 index 0000000..d6a7368 --- /dev/null +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/di/RoutingModule.kt @@ -0,0 +1,15 @@ +package com.branhamplayer.android.sermons.di + +import com.branhamplayer.android.sermons.reducers.RoutingReducer +import com.branhamplayer.android.sermons.ui.NoSelectionFragment +import com.branhamplayer.android.sermons.ui.SermonsActivity +import dagger.Module +import dagger.Provides + +@Module +class RoutingModule { + + @Provides + fun providesRoutingReducer(activity: SermonsActivity, noSelectionFragment: NoSelectionFragment) = + RoutingReducer(activity, noSelectionFragment) +} diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonPlayerModule.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonPlayerModule.kt new file mode 100644 index 0000000..7a5d28e --- /dev/null +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonPlayerModule.kt @@ -0,0 +1,12 @@ +package com.branhamplayer.android.sermons.di + +import com.branhamplayer.android.sermons.ui.NoSelectionFragment +import dagger.Module +import dagger.Provides + +@Module +class SermonPlayerModule { + + @Provides + fun provideNoSelectionFragment() = NoSelectionFragment() +} diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsComponent.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsComponent.kt index 7341c0e..c3e17c9 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsComponent.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsComponent.kt @@ -7,7 +7,7 @@ import com.branhamplayer.android.sermons.ui.SermonListFragment import com.branhamplayer.android.sermons.ui.SermonsActivity import dagger.Component -@Component(modules = [AuthenticationModule::class, DataModule::class, DrawerModule::class, ProfileModule::class, RxJavaModule::class, SermonsModule::class]) +@Component(modules = [AuthenticationModule::class, DataModule::class, DrawerModule::class, ProfileModule::class, RoutingModule::class, RxJavaModule::class, SermonPlayerModule::class, SermonsModule::class]) interface SermonsComponent { fun inject(activity: SermonsActivity) fun inject(fragment: SermonListFragment) diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsModule.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsModule.kt index c27291f..a047966 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsModule.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsModule.kt @@ -1,21 +1,21 @@ package com.branhamplayer.android.sermons.di import android.content.Context -import androidx.appcompat.app.AppCompatActivity import com.branhamplayer.android.sermons.adapters.SermonsAdapter import com.branhamplayer.android.sermons.ui.SermonListFragment +import com.branhamplayer.android.sermons.ui.SermonsActivity import com.branhamplayer.android.ui.DrawerHeaderViewBinder import dagger.Module import dagger.Provides @Module -class SermonsModule(private val activity: AppCompatActivity) { +class SermonsModule(private val activity: SermonsActivity) { @Provides fun provideActivity() = activity @Provides - fun provideContext(): Context = activity.applicationContext + fun provideContext(): Context = activity @Provides fun provideDrawerHeaderViewBinder() = DrawerHeaderViewBinder() diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/middleware/PermissionMiddleware.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/middleware/PermissionMiddleware.kt index 878d9fa..170414b 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/middleware/PermissionMiddleware.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/middleware/PermissionMiddleware.kt @@ -1,11 +1,11 @@ package com.branhamplayer.android.sermons.middleware -import androidx.appcompat.app.AppCompatActivity import com.branhamplayer.android.base.redux.TypedMiddleware import com.branhamplayer.android.sermons.actions.DataAction import com.branhamplayer.android.sermons.actions.PermissionAction import com.branhamplayer.android.sermons.di.RxJavaModule import com.branhamplayer.android.sermons.states.SermonsState +import com.branhamplayer.android.sermons.ui.SermonsActivity import com.branhamplayer.android.sermons.utils.permissions.PermissionConstants import com.branhamplayer.android.sermons.utils.permissions.PermissionManager import io.reactivex.Scheduler @@ -14,7 +14,7 @@ import javax.inject.Inject import javax.inject.Named class PermissionMiddleware @Inject constructor( - private val activity: AppCompatActivity, + private val activity: SermonsActivity, @Named(RxJavaModule.BG) private val bg: Scheduler, @Named(RxJavaModule.UI) private val ui: Scheduler ) : TypedMiddleware { diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/reducers/RoutingReducer.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/reducers/RoutingReducer.kt new file mode 100644 index 0000000..20f6d61 --- /dev/null +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/reducers/RoutingReducer.kt @@ -0,0 +1,26 @@ +package com.branhamplayer.android.sermons.reducers + +import com.branhamplayer.android.base.redux.TypedReducer +import com.branhamplayer.android.sermons.actions.RoutingAction +import com.branhamplayer.android.sermons.states.SermonsState +import com.branhamplayer.android.sermons.ui.NoSelectionFragment +import com.branhamplayer.android.sermons.ui.SermonsActivity +import javax.inject.Inject + +class RoutingReducer @Inject constructor( + private val sermonsActivity: SermonsActivity, + private val noSelectionFragment: NoSelectionFragment +) : TypedReducer { + + override fun invoke(action: RoutingAction, oldState: SermonsState): SermonsState { + when (action) { + is RoutingAction.NavigateToNoSelectionAction -> navigateToNoSelection() + } + + return oldState + } + + private fun navigateToNoSelection() { + sermonsActivity.setDetailFragment(noSelectionFragment) + } +} diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/reducers/SermonsReducer.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/reducers/SermonsReducer.kt index 395ac7f..7d0b147 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/reducers/SermonsReducer.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/reducers/SermonsReducer.kt @@ -3,6 +3,7 @@ package com.branhamplayer.android.sermons.reducers import com.branhamplayer.android.sermons.actions.DataAction import com.branhamplayer.android.sermons.actions.DrawerAction import com.branhamplayer.android.sermons.actions.ProfileAction +import com.branhamplayer.android.sermons.actions.RoutingAction import com.branhamplayer.android.sermons.di.DaggerInjector import com.branhamplayer.android.sermons.states.SermonsState import org.rekotlin.Action @@ -11,6 +12,8 @@ import javax.inject.Inject class SermonsReducer : Reducer { + // region DI + @Inject lateinit var dataReducer: DataReducer @@ -20,6 +23,13 @@ class SermonsReducer : Reducer { @Inject lateinit var profileReducer: ProfileReducer + @Inject + lateinit var routingReducer: RoutingReducer + + // endregion + + // region Reducer + override fun invoke(action: Action, sermonsState: SermonsState?): SermonsState { val oldState = sermonsState ?: SermonsState() @@ -39,10 +49,17 @@ class SermonsReducer : Reducer { profileReducer.invoke(action, oldState) } + is RoutingAction -> { + inject() + routingReducer.invoke(action, oldState) + } + else -> oldState } } + // endregion + private fun inject() { DaggerInjector.sermonsComponent?.inject(this) } diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/ui/NoSelectionFragment.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/ui/NoSelectionFragment.kt new file mode 100644 index 0000000..1a65bc3 --- /dev/null +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/ui/NoSelectionFragment.kt @@ -0,0 +1,18 @@ +package com.branhamplayer.android.sermons.ui + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import com.branhamplayer.android.sermons.R + +class NoSelectionFragment : Fragment() { + + // region Fragment + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = + inflater.inflate(R.layout.no_selection_fragment, container, false) + + // endregion +} diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt index 9a2f3cb..046487b 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt @@ -5,16 +5,14 @@ import androidx.appcompat.app.ActionBarDrawerToggle import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar import androidx.drawerlayout.widget.DrawerLayout +import androidx.fragment.app.Fragment import androidx.fragment.app.commit import butterknife.BindView import butterknife.ButterKnife import butterknife.Unbinder import com.branhamplayer.android.R as RBase import com.branhamplayer.android.sermons.R -import com.branhamplayer.android.sermons.actions.DataAction -import com.branhamplayer.android.sermons.actions.DrawerAction -import com.branhamplayer.android.sermons.actions.PermissionAction -import com.branhamplayer.android.sermons.actions.ProfileAction +import com.branhamplayer.android.sermons.actions.* import com.branhamplayer.android.sermons.di.DaggerInjector import com.branhamplayer.android.sermons.store.sermonsStore import com.branhamplayer.android.sermons.states.SermonsState @@ -28,33 +26,29 @@ class SermonsActivity : AppCompatActivity(), StoreSubscriber { private var activityUnbinder: Unbinder? = null private var drawerToggle: ActionBarDrawerToggle? = null - // region Components + // region DI - @JvmField - @BindView(R.id.navigation_drawer) - var drawer: NavigationView? = null + @Inject + lateinit var drawerHeaderBinder: DrawerHeaderViewBinder - @JvmField - @BindView(R.id.navigation_drawer_layout) - var drawerLayout: DrawerLayout? = null + @Inject + lateinit var sermonListFragment: SermonListFragment - @JvmField - @BindView(R.id.primary_toolbar) - var primaryToolbar: Toolbar? = null + // endregion - @JvmField - @BindView(R.id.sermon_list_toolbar) - var sermonsListToolbar: Toolbar? = null + // region UI - // endregion + @BindView(R.id.navigation_drawer) + lateinit var drawer: NavigationView - // region DI + @BindView(R.id.navigation_drawer_layout) + lateinit var drawerLayout: DrawerLayout - @Inject - lateinit var drawerHeaderBinder: DrawerHeaderViewBinder + @BindView(R.id.primary_toolbar) + lateinit var primaryToolbar: Toolbar - @Inject - lateinit var sermonListFragment: SermonListFragment + @BindView(R.id.sermon_list_toolbar) + lateinit var sermonsListToolbar: Toolbar // endregion @@ -78,6 +72,7 @@ class SermonsActivity : AppCompatActivity(), StoreSubscriber { sermonsStore.dispatch(DataAction.SetTitleAction(RBase.string.navigation_sermons)) sermonsStore.dispatch(PermissionAction.GetFileReadPermissionAction) + sermonsStore.dispatch(RoutingAction.NavigateToNoSelectionAction) val isTablet = resources.getBoolean(RBase.bool.is_tablet) @@ -99,7 +94,7 @@ class SermonsActivity : AppCompatActivity(), StoreSubscriber { override fun newState(state: SermonsState) { - drawer?.menu?.getItem(state.drawerItemSelectedIndex)?.isChecked = true + drawer.menu?.getItem(state.drawerItemSelectedIndex)?.isChecked = true state.profile?.let { drawerHeaderBinder.email?.text = it.email @@ -107,12 +102,28 @@ class SermonsActivity : AppCompatActivity(), StoreSubscriber { } state.title?.let { - sermonsListToolbar?.title = it + sermonsListToolbar.title = it } } // endregion + fun setDetailFragment(fragment: Fragment) { + + val isTablet = resources.getBoolean(RBase.bool.is_tablet) + if (!isTablet) return + + supportFragmentManager.commit(allowStateLoss = true) { + replace(R.id.sermons_details_container, fragment) + } + } + + fun setMasterFragment(fragment: Fragment) { + supportFragmentManager.commit(allowStateLoss = true) { + replace(R.id.sermon_list_container, fragment) + } + } + private fun setUpDrawer() { drawerToggle = ActionBarDrawerToggle( @@ -124,13 +135,13 @@ class SermonsActivity : AppCompatActivity(), StoreSubscriber { ) drawerToggle?.let { - drawerLayout?.addDrawerListener(it) + drawerLayout.addDrawerListener(it) } drawerToggle?.syncState() - if (drawer?.headerCount == 1) { - drawer?.getHeaderView(0)?.let { + if (drawer.headerCount == 1) { + drawer.getHeaderView(0)?.let { drawerHeaderBinder.bind(it) } } diff --git a/sermons/src/main/res/drawable/no_selection.xml b/sermons/src/main/res/drawable/no_selection.xml new file mode 100644 index 0000000..3db60e7 --- /dev/null +++ b/sermons/src/main/res/drawable/no_selection.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sermons/src/main/res/layout/no_selection_fragment.xml b/sermons/src/main/res/layout/no_selection_fragment.xml new file mode 100644 index 0000000..2199b4c --- /dev/null +++ b/sermons/src/main/res/layout/no_selection_fragment.xml @@ -0,0 +1,34 @@ + + + + + + + diff --git a/sermons/src/main/res/values/strings.xml b/sermons/src/main/res/values/strings.xml index 10ebb75..61f39c0 100644 --- a/sermons/src/main/res/values/strings.xml +++ b/sermons/src/main/res/values/strings.xml @@ -28,4 +28,10 @@ This permission is necessary for the Branham Player to work properly + + + + Select a sermon from the list + + From f1ca9323e6e0f2abcfb8cbb633e66b58fce1f47a Mon Sep 17 00:00:00 2001 From: Oliver Spryn <2717340+oliverspryn@users.noreply.github.com> Date: Fri, 8 Mar 2019 15:04:40 -0500 Subject: [PATCH 02/14] Shows no selection page conditionally --- .../android/sermons/ui/SermonsActivity.kt | 12 +++++++++--- .../src/main/res/layout/no_selection_fragment.xml | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt index 046487b..7d1d724 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt @@ -12,7 +12,11 @@ import butterknife.ButterKnife import butterknife.Unbinder import com.branhamplayer.android.R as RBase import com.branhamplayer.android.sermons.R -import com.branhamplayer.android.sermons.actions.* +import com.branhamplayer.android.sermons.actions.DataAction +import com.branhamplayer.android.sermons.actions.DrawerAction +import com.branhamplayer.android.sermons.actions.PermissionAction +import com.branhamplayer.android.sermons.actions.ProfileAction +import com.branhamplayer.android.sermons.actions.RoutingAction import com.branhamplayer.android.sermons.di.DaggerInjector import com.branhamplayer.android.sermons.store.sermonsStore import com.branhamplayer.android.sermons.states.SermonsState @@ -72,7 +76,6 @@ class SermonsActivity : AppCompatActivity(), StoreSubscriber { sermonsStore.dispatch(DataAction.SetTitleAction(RBase.string.navigation_sermons)) sermonsStore.dispatch(PermissionAction.GetFileReadPermissionAction) - sermonsStore.dispatch(RoutingAction.NavigateToNoSelectionAction) val isTablet = resources.getBoolean(RBase.bool.is_tablet) @@ -101,6 +104,10 @@ class SermonsActivity : AppCompatActivity(), StoreSubscriber { drawerHeaderBinder.name?.text = it.name } + if (!state.sermonList.isNullOrEmpty()) { + sermonsStore.dispatch(RoutingAction.NavigateToNoSelectionAction) + } + state.title?.let { sermonsListToolbar.title = it } @@ -109,7 +116,6 @@ class SermonsActivity : AppCompatActivity(), StoreSubscriber { // endregion fun setDetailFragment(fragment: Fragment) { - val isTablet = resources.getBoolean(RBase.bool.is_tablet) if (!isTablet) return diff --git a/sermons/src/main/res/layout/no_selection_fragment.xml b/sermons/src/main/res/layout/no_selection_fragment.xml index 2199b4c..8cfb03e 100644 --- a/sermons/src/main/res/layout/no_selection_fragment.xml +++ b/sermons/src/main/res/layout/no_selection_fragment.xml @@ -24,7 +24,7 @@ android:layout_marginTop="8dp" android:layout_width="wrap_content" android:text="@string/no_selection_description" - android:textSize="18sp" + android:textSize="16sp" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" From 3cdd5d56ebf68411b67c0bde03de2ecec8cda41d Mon Sep 17 00:00:00 2001 From: Oliver Spryn <2717340+oliverspryn@users.noreply.github.com> Date: Fri, 8 Mar 2019 15:40:17 -0500 Subject: [PATCH 03/14] Start tablet routing to player view --- .../android/base/ui/BindableViewHolder.kt | 9 +++++ .../android/sermons/actions/RoutingAction.kt | 2 ++ .../sermons/adapters/SermonViewHolder.kt | 36 +++++++++++++++---- .../android/sermons/di/PlayerModule.kt | 12 +++++++ .../android/sermons/di/RoutingModule.kt | 8 +++-- .../android/sermons/di/SermonsComponent.kt | 2 +- .../sermons/reducers/RoutingReducer.kt | 13 ++++++- .../android/sermons/ui/PlayerFragment.kt | 18 ++++++++++ .../android/sermons/ui/SermonsActivity.kt | 1 + .../src/main/res/layout/player_fragment.xml | 12 +++++++ 10 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/com/branhamplayer/android/base/ui/BindableViewHolder.kt create mode 100644 sermons/src/main/java/com/branhamplayer/android/sermons/di/PlayerModule.kt create mode 100644 sermons/src/main/java/com/branhamplayer/android/sermons/ui/PlayerFragment.kt create mode 100644 sermons/src/main/res/layout/player_fragment.xml diff --git a/app/src/main/java/com/branhamplayer/android/base/ui/BindableViewHolder.kt b/app/src/main/java/com/branhamplayer/android/base/ui/BindableViewHolder.kt new file mode 100644 index 0000000..6264c7b --- /dev/null +++ b/app/src/main/java/com/branhamplayer/android/base/ui/BindableViewHolder.kt @@ -0,0 +1,9 @@ +package com.branhamplayer.android.base.ui + +import android.view.View +import androidx.recyclerview.widget.RecyclerView +import com.branhamplayer.android.base.models.Model + +abstract class BindableViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + abstract fun bind(model: BindingModel) +} diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/actions/RoutingAction.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/actions/RoutingAction.kt index 7b30595..6963feb 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/actions/RoutingAction.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/actions/RoutingAction.kt @@ -1,7 +1,9 @@ package com.branhamplayer.android.sermons.actions +import com.branhamplayer.android.sermons.models.SermonModel import org.rekotlin.Action sealed class RoutingAction : Action { + data class NavigateToPlayerAction(val sermon: SermonModel) : RoutingAction() object NavigateToNoSelectionAction : RoutingAction() } diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/adapters/SermonViewHolder.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/adapters/SermonViewHolder.kt index cb41b5c..7fa82f9 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/adapters/SermonViewHolder.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/adapters/SermonViewHolder.kt @@ -2,19 +2,41 @@ package com.branhamplayer.android.sermons.adapters import android.view.View import android.widget.TextView -import androidx.recyclerview.widget.RecyclerView +import com.branhamplayer.android.base.ui.BindableViewHolder import com.branhamplayer.android.sermons.R +import com.branhamplayer.android.sermons.actions.RoutingAction import com.branhamplayer.android.sermons.models.SermonModel +import com.branhamplayer.android.sermons.store.sermonsStore -class SermonViewHolder( - itemView: View -) : RecyclerView.ViewHolder(itemView) { +class SermonViewHolder(itemView: View) : BindableViewHolder(itemView), View.OnClickListener { private val date: TextView = itemView.findViewById(R.id.sermon_date) private val name: TextView = itemView.findViewById(R.id.sermon_name) - fun bind(sermon: SermonModel) { - date.text = sermon.formattedDate - name.text = sermon.name + private var sermonModel: SermonModel? = null + + init { + itemView.setOnClickListener(this) + } + + // region BindableViewHolder + + override fun bind(model: SermonModel) { + date.text = model.formattedDate + name.text = model.name + + sermonModel = model } + + // endregion + + // region View.OnClickListener + + override fun onClick(view: View?) { + sermonModel?.let { + sermonsStore.dispatch(RoutingAction.NavigateToPlayerAction(it)) + } + } + + // endregion } diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/di/PlayerModule.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/di/PlayerModule.kt new file mode 100644 index 0000000..9ead764 --- /dev/null +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/di/PlayerModule.kt @@ -0,0 +1,12 @@ +package com.branhamplayer.android.sermons.di + +import com.branhamplayer.android.sermons.ui.PlayerFragment +import dagger.Module +import dagger.Provides + +@Module +class PlayerModule { + + @Provides + fun providePlayerFragment() = PlayerFragment() +} diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/di/RoutingModule.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/di/RoutingModule.kt index d6a7368..0865d75 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/di/RoutingModule.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/di/RoutingModule.kt @@ -2,6 +2,7 @@ package com.branhamplayer.android.sermons.di import com.branhamplayer.android.sermons.reducers.RoutingReducer import com.branhamplayer.android.sermons.ui.NoSelectionFragment +import com.branhamplayer.android.sermons.ui.PlayerFragment import com.branhamplayer.android.sermons.ui.SermonsActivity import dagger.Module import dagger.Provides @@ -10,6 +11,9 @@ import dagger.Provides class RoutingModule { @Provides - fun providesRoutingReducer(activity: SermonsActivity, noSelectionFragment: NoSelectionFragment) = - RoutingReducer(activity, noSelectionFragment) + fun providesRoutingReducer( + activity: SermonsActivity, + noSelectionFragment: NoSelectionFragment, + playerFragment: PlayerFragment + ) = RoutingReducer(activity, noSelectionFragment, playerFragment) } diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsComponent.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsComponent.kt index c3e17c9..de4825a 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsComponent.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/di/SermonsComponent.kt @@ -7,7 +7,7 @@ import com.branhamplayer.android.sermons.ui.SermonListFragment import com.branhamplayer.android.sermons.ui.SermonsActivity import dagger.Component -@Component(modules = [AuthenticationModule::class, DataModule::class, DrawerModule::class, ProfileModule::class, RoutingModule::class, RxJavaModule::class, SermonPlayerModule::class, SermonsModule::class]) +@Component(modules = [AuthenticationModule::class, DataModule::class, DrawerModule::class, PlayerModule::class, ProfileModule::class, RoutingModule::class, RxJavaModule::class, SermonPlayerModule::class, SermonsModule::class]) interface SermonsComponent { fun inject(activity: SermonsActivity) fun inject(fragment: SermonListFragment) diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/reducers/RoutingReducer.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/reducers/RoutingReducer.kt index 20f6d61..b929122 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/reducers/RoutingReducer.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/reducers/RoutingReducer.kt @@ -4,23 +4,34 @@ import com.branhamplayer.android.base.redux.TypedReducer import com.branhamplayer.android.sermons.actions.RoutingAction import com.branhamplayer.android.sermons.states.SermonsState import com.branhamplayer.android.sermons.ui.NoSelectionFragment +import com.branhamplayer.android.sermons.ui.PlayerFragment import com.branhamplayer.android.sermons.ui.SermonsActivity import javax.inject.Inject class RoutingReducer @Inject constructor( private val sermonsActivity: SermonsActivity, - private val noSelectionFragment: NoSelectionFragment + private val noSelectionFragment: NoSelectionFragment, + private val playerFragment: PlayerFragment ) : TypedReducer { + // region TypedReducer + override fun invoke(action: RoutingAction, oldState: SermonsState): SermonsState { when (action) { is RoutingAction.NavigateToNoSelectionAction -> navigateToNoSelection() + is RoutingAction.NavigateToPlayerAction -> navigateToPlayer() } return oldState } + // endregion + private fun navigateToNoSelection() { sermonsActivity.setDetailFragment(noSelectionFragment) } + + private fun navigateToPlayer() { + sermonsActivity.setDetailFragment(playerFragment) + } } diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/ui/PlayerFragment.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/ui/PlayerFragment.kt new file mode 100644 index 0000000..b01e387 --- /dev/null +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/ui/PlayerFragment.kt @@ -0,0 +1,18 @@ +package com.branhamplayer.android.sermons.ui + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import com.branhamplayer.android.sermons.R + +class PlayerFragment : Fragment() { + + // region Fragment + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = + inflater.inflate(R.layout.player_fragment, container, false) + + // endregion +} diff --git a/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt b/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt index 7d1d724..d574127 100644 --- a/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt +++ b/sermons/src/main/java/com/branhamplayer/android/sermons/ui/SermonsActivity.kt @@ -89,6 +89,7 @@ class SermonsActivity : AppCompatActivity(), StoreSubscriber { drawerHeaderBinder.unbind() activityUnbinder?.unbind() + sermonsStore.unsubscribe(this) } // endregion diff --git a/sermons/src/main/res/layout/player_fragment.xml b/sermons/src/main/res/layout/player_fragment.xml new file mode 100644 index 0000000..c335f44 --- /dev/null +++ b/sermons/src/main/res/layout/player_fragment.xml @@ -0,0 +1,12 @@ + + + +