Skip to content

Commit

Permalink
Implement sign out ui.
Browse files Browse the repository at this point in the history
- Fixed dialog theme & tweaked typography.
- Consolodated sign in/login terminology as 'sign in'.
- Split dialogs package out by feature.
- Made clicking sign in button show dialog first.
- Added view models for sign in/out dialogs.

Test: ScheduleViewModelTest, SignInViewModelTest
Bug: 74393872
Change-Id: Id79339065dae2d95db37ae472d1404854eea3eac
  • Loading branch information
nickbutcher committed Mar 27, 2018
1 parent 65537c3 commit 54cf7a9
Show file tree
Hide file tree
Showing 47 changed files with 1,045 additions and 629 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ package com.google.samples.apps.iosched.di

import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.FirebaseFirestore
import com.google.samples.apps.iosched.shared.data.login.datasources.AuthStateUserDataSource
import com.google.samples.apps.iosched.shared.data.login.datasources.FirebaseAuthStateUserDataSource
import com.google.samples.apps.iosched.shared.data.login.datasources.FirestoreRegisteredUserDataSource
import com.google.samples.apps.iosched.shared.data.login.datasources.RegisteredUserDataSource
import com.google.samples.apps.iosched.shared.data.signin.datasources.AuthStateUserDataSource
import com.google.samples.apps.iosched.shared.data.signin.datasources.FirebaseAuthStateUserDataSource
import com.google.samples.apps.iosched.shared.data.signin.datasources.FirestoreRegisteredUserDataSource
import com.google.samples.apps.iosched.shared.data.signin.datasources.RegisteredUserDataSource
import com.google.samples.apps.iosched.shared.fcm.FcmTokenUpdater
import com.google.samples.apps.iosched.util.login.DefaultLoginHandler
import com.google.samples.apps.iosched.util.login.LoginHandler
import com.google.samples.apps.iosched.util.signin.DefaultSignInHandler
import com.google.samples.apps.iosched.util.signin.SignInHandler
import dagger.Module
import dagger.Provides
import javax.inject.Singleton

@Module
internal class LoginModule {
internal class SignInModule {
@Provides
fun provideLoginHandler(): LoginHandler = DefaultLoginHandler()
fun provideSignInHandler(): SignInHandler = DefaultSignInHandler()

@Singleton
@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ package com.google.samples.apps.iosched.di

import com.google.samples.apps.iosched.shared.di.ActivityScoped
import com.google.samples.apps.iosched.ui.MainActivity
import com.google.samples.apps.iosched.ui.dialog.DialogModule
import com.google.samples.apps.iosched.ui.signin.SignInDialogModule
import com.google.samples.apps.iosched.ui.info.InfoModule
import com.google.samples.apps.iosched.ui.map.MapModule
import com.google.samples.apps.iosched.ui.reservation.ReservationModule
import com.google.samples.apps.iosched.ui.schedule.ScheduleModule
import com.google.samples.apps.iosched.ui.sessiondetail.SessionDetailActivity
import com.google.samples.apps.iosched.ui.sessiondetail.SessionDetailModule
import dagger.Module
import dagger.android.ContributesAndroidInjector


/**
* We want Dagger.Android to create a Subcomponent which has a parent Component of whichever module
* ActivityBindingModule is on, in our case that will be [AppComponent]. You never
Expand All @@ -41,12 +41,23 @@ abstract class ActivityBindingModule {

@ActivityScoped
@ContributesAndroidInjector(
modules = [ScheduleModule::class, MapModule::class, InfoModule::class,
DialogModule::class])
modules = [
ScheduleModule::class,
MapModule::class,
InfoModule::class,
SignInDialogModule::class,
ReservationModule::class
]
)
internal abstract fun mainActivity(): MainActivity

@ActivityScoped
@ContributesAndroidInjector(modules = [SessionDetailModule::class, DialogModule::class])
@ContributesAndroidInjector(
modules = [
SessionDetailModule::class,
SignInDialogModule::class,
ReservationModule::class
]
)
internal abstract fun sessionDetailActivity(): SessionDetailActivity

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.google.samples.apps.iosched.MainApplication
import com.google.samples.apps.iosched.shared.di.ServiceBindingModule
import com.google.samples.apps.iosched.shared.di.SharedModule
import com.google.samples.apps.iosched.shared.di.ViewModelModule
import com.google.samples.apps.iosched.ui.login.LoginViewModelPluginModule
import com.google.samples.apps.iosched.ui.signin.SignInViewModelDelegateModule
import com.google.samples.apps.iosched.ui.sessiondetail.SessionDetailModule
import dagger.Component
import dagger.android.AndroidInjector
Expand All @@ -43,9 +43,9 @@ import javax.inject.Singleton
ServiceBindingModule::class,
SharedModule::class,
SessionDetailModule::class,
LoginModule::class,
LoginViewModelPluginModule::class])
SignInModule::class,
SignInViewModelDelegateModule::class])
interface AppComponent : AndroidInjector<MainApplication> {
@Component.Builder
abstract class Builder : AndroidInjector.Builder<MainApplication>()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class AppModule {
fun provideContext(application: MainApplication): Context {
return application.applicationContext
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.samples.apps.iosched.ui.dialog
package com.google.samples.apps.iosched.ui.reservation

import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProvider
Expand Down Expand Up @@ -69,8 +69,11 @@ class RemoveReservationDialogFragment : CustomDimDialogFragment(), HasSupportFra
AndroidSupportInjection.inject(this)
}

override fun onCreateView(inflater: LayoutInflater,
container: ViewGroup?, savedInstanceState: Bundle?): View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
removeViewModel = viewModelProvider(viewModelFactory)

requireNotNull(arguments).run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.samples.apps.iosched.ui.dialog
package com.google.samples.apps.iosched.ui.reservation

import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.samples.apps.iosched.ui.dialog
package com.google.samples.apps.iosched.ui.reservation

import android.arch.lifecycle.ViewModel
import com.google.samples.apps.iosched.shared.di.ChildFragmentScoped
Expand All @@ -26,17 +26,10 @@ import dagger.android.ContributesAndroidInjector
import dagger.multibindings.IntoMap

/**
* Module that defines the child fragments of the DialogFragments.
* Module that provides classes needed for reservations.
*/
@Module
internal abstract class DialogModule {

/**
* Generates an [AndroidInjector] for the [SignInDialogFragment].
*/
@ChildFragmentScoped
@ContributesAndroidInjector
internal abstract fun contributeDialogSignInFragment(): SignInDialogFragment
internal abstract class ReservationModule {

/**
* Generates an [AndroidInjector] for the [RemoveReservationDialogFragment].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,17 @@ import com.google.samples.apps.iosched.databinding.FragmentScheduleBinding
import com.google.samples.apps.iosched.shared.domain.users.ReservationRequestParameters
import com.google.samples.apps.iosched.shared.util.TimeUtils.ConferenceDay
import com.google.samples.apps.iosched.shared.util.activityViewModelProvider
import com.google.samples.apps.iosched.shared.util.checkAllMatched
import com.google.samples.apps.iosched.ui.SnackbarMessage
import com.google.samples.apps.iosched.ui.dialog.RemoveReservationDialogFragment
import com.google.samples.apps.iosched.ui.dialog.RemoveReservationDialogFragment.Companion.DIALOG_REMOVE_RESERVATION
import com.google.samples.apps.iosched.ui.dialog.SignInDialogFragment
import com.google.samples.apps.iosched.ui.dialog.SignInDialogFragment.Companion.DIALOG_NEED_TO_SIGN_IN
import com.google.samples.apps.iosched.ui.login.LoginEvent.RequestLogin
import com.google.samples.apps.iosched.ui.login.LoginEvent.RequestLogout
import com.google.samples.apps.iosched.ui.reservation.RemoveReservationDialogFragment
import com.google.samples.apps.iosched.ui.reservation.RemoveReservationDialogFragment.Companion.DIALOG_REMOVE_RESERVATION
import com.google.samples.apps.iosched.ui.schedule.agenda.ScheduleAgendaFragment
import com.google.samples.apps.iosched.ui.schedule.day.ScheduleDayFragment
import com.google.samples.apps.iosched.ui.sessiondetail.SessionDetailActivity
import com.google.samples.apps.iosched.util.login.LoginHandler
import com.google.samples.apps.iosched.ui.signin.SignInDialogFragment
import com.google.samples.apps.iosched.ui.signin.SignOutDialogFragment
import com.google.samples.apps.iosched.widget.BottomSheetBehavior
import com.google.samples.apps.iosched.widget.HideBottomViewOnScrollBehavior
import dagger.android.support.DaggerFragment
import timber.log.Timber
import javax.inject.Inject

/**
Expand All @@ -67,10 +62,11 @@ class ScheduleFragment : DaggerFragment() {
companion object {
private val COUNT = ConferenceDay.values().size + 1 // Agenda
private val AGENDA_POSITION = COUNT - 1
private const val DIALOG_NEED_TO_SIGN_IN = "dialog_need_to_sign_in"
private const val DIALOG_CONFIRM_SIGN_OUT = "dialog_confirm_sign_out"
}

@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
@Inject lateinit var loginHandler: LoginHandler

private lateinit var viewModel: ScheduleViewModel
private lateinit var coordinatorLayout: CoordinatorLayout
Expand Down Expand Up @@ -98,18 +94,15 @@ class ScheduleFragment : DaggerFragment() {
}
})

viewModel.performLoginEvent.observe(this, Observer { loginRequestEvent ->
loginRequestEvent?.getContentIfNotHandled()?.let { loginEvent ->
when (loginEvent) {
RequestLogout -> doLogout()
RequestLogin -> requestLogin()
}.checkAllMatched
viewModel.navigateToSignInDialogAction.observe(this, Observer {
it?.getContentIfNotHandled()?.let {
openSignInDialog()
}
})

viewModel.navigateToSignInDialogAction.observe(this, Observer {
viewModel.navigateToSignOutDialogAction.observe(this, Observer {
it?.getContentIfNotHandled()?.let {
openSignInDialog(requireActivity())
openSignOutDialog()
}
})
viewModel.navigateToRemoveReservationDialogAction.observe(this, Observer {
Expand Down Expand Up @@ -186,28 +179,22 @@ class ScheduleFragment : DaggerFragment() {
startActivity(SessionDetailActivity.starterIntent(requireContext(), id))
}

private fun openSignInDialog(activity: FragmentActivity) {
private fun openSignInDialog() {
val dialog = SignInDialogFragment()
dialog.show(activity.supportFragmentManager, DIALOG_NEED_TO_SIGN_IN)
dialog.show(requireActivity().supportFragmentManager, DIALOG_NEED_TO_SIGN_IN)
}

private fun openRemoveReservationDialog(activity: FragmentActivity,
parameters: ReservationRequestParameters) {
private fun openRemoveReservationDialog(
activity: FragmentActivity,
parameters: ReservationRequestParameters
) {
val dialog = RemoveReservationDialogFragment.newInstance(parameters)
dialog.show(activity.supportFragmentManager, DIALOG_REMOVE_RESERVATION)
}

private fun doLogout() {
// TODO: b/74393872 Implement full UX here
this.context?.let {
loginHandler.logout(it) {
Timber.d("Logged out!")
}
}
}

private fun requestLogin() {
loginHandler.makeLoginIntent()?.let { startActivity(it) }
private fun openSignOutDialog() {
val dialog = SignOutDialogFragment()
dialog.show(requireActivity().supportFragmentManager, DIALOG_CONFIRM_SIGN_OUT)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package com.google.samples.apps.iosched.ui.schedule
import android.arch.lifecycle.ViewModel
import com.google.samples.apps.iosched.shared.di.FragmentScoped
import com.google.samples.apps.iosched.shared.di.ViewModelKey
import com.google.samples.apps.iosched.ui.reservation.ReservationModule
import com.google.samples.apps.iosched.ui.schedule.filters.ScheduleFilterFragment
import com.google.samples.apps.iosched.ui.sessioncommon.SessionViewPoolModule
import com.google.samples.apps.iosched.ui.signin.SignInDialogModule
import dagger.Binds
import dagger.Module
import dagger.android.AndroidInjector
Expand All @@ -37,8 +39,12 @@ internal abstract class ScheduleModule {
* Generates an [AndroidInjector] for the [ScheduleFragment].
*/
@FragmentScoped
@ContributesAndroidInjector(modules = [ScheduleChildFragmentsModule::class,
SessionViewPoolModule::class])
@ContributesAndroidInjector(
modules = [
ScheduleChildFragmentsModule::class,
SessionViewPoolModule::class
]
)
internal abstract fun contributeScheduleFragment(): ScheduleFragment

/**
Expand All @@ -55,5 +61,5 @@ internal abstract class ScheduleModule {
@Binds
@IntoMap
@ViewModelKey(ScheduleViewModel::class)
abstract fun bindScheduleFragmentViewModel(viewModel: ScheduleViewModel): ViewModel
abstract fun bindScheduleViewModel(viewModel: ScheduleViewModel): ViewModel
}
Loading

0 comments on commit 54cf7a9

Please sign in to comment.