diff --git a/.gitignore b/.gitignore index ed6a9781b0..711cd1be06 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ _sandbox # Android Studio captures folder captures/ +tools/iosched-codestyle.xml diff --git a/mobile/src/main/java/com/google/samples/apps/iosched/ui/info/InfoFragment.kt b/mobile/src/main/java/com/google/samples/apps/iosched/ui/info/InfoFragment.kt index d38a9e18f8..39e7d48a23 100644 --- a/mobile/src/main/java/com/google/samples/apps/iosched/ui/info/InfoFragment.kt +++ b/mobile/src/main/java/com/google/samples/apps/iosched/ui/info/InfoFragment.kt @@ -29,8 +29,12 @@ import com.google.android.material.tabs.TabLayoutMediator import com.google.samples.apps.iosched.R import com.google.samples.apps.iosched.databinding.FragmentInfoBinding import com.google.samples.apps.iosched.shared.analytics.AnalyticsHelper +import com.google.samples.apps.iosched.shared.result.EventObserver import com.google.samples.apps.iosched.ui.MainActivityViewModel import com.google.samples.apps.iosched.ui.MainNavigationFragment +import com.google.samples.apps.iosched.ui.schedule.ScheduleFragment +import com.google.samples.apps.iosched.ui.signin.SignInDialogFragment +import com.google.samples.apps.iosched.ui.signin.SignOutDialogFragment import com.google.samples.apps.iosched.ui.signin.setupProfileMenuItem import com.google.samples.apps.iosched.util.doOnApplyWindowInsets import dagger.hilt.android.AndroidEntryPoint @@ -38,7 +42,6 @@ import javax.inject.Inject @AndroidEntryPoint class InfoFragment : MainNavigationFragment() { - @Inject lateinit var analyticsHelper: AnalyticsHelper private lateinit var binding: FragmentInfoBinding @@ -46,9 +49,9 @@ class InfoFragment : MainNavigationFragment() { private val viewModel: MainActivityViewModel by viewModels() override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? ): View? { binding = FragmentInfoBinding.inflate(inflater, container, false).apply { lifecycleOwner = viewLifecycleOwner @@ -56,6 +59,14 @@ class InfoFragment : MainNavigationFragment() { binding.viewpager.doOnApplyWindowInsets { v, insets, padding -> v.updatePaddingRelative(bottom = padding.bottom + insets.systemWindowInsetBottom) } + + viewModel.navigateToSignInDialogAction.observe(viewLifecycleOwner, EventObserver { + openSignInDialog() + }) + + viewModel.navigateToSignOutDialogAction.observe(viewLifecycleOwner, EventObserver { + openSignOutDialog() + }) return binding.root } @@ -81,6 +92,17 @@ class InfoFragment : MainNavigationFragment() { } } + + private fun openSignInDialog() { + val dialog = SignInDialogFragment() + dialog.show(requireActivity().supportFragmentManager, InfoFragment.DIALOG_NEED_TO_SIGN_IN) + } + + private fun openSignOutDialog() { + val dialog = SignOutDialogFragment() + dialog.show(requireActivity().supportFragmentManager, InfoFragment.DIALOG_CONFIRM_SIGN_OUT) + } + private fun trackInfoScreenView(position: Int) { val pageName = getString(INFO_TITLES[position]) analyticsHelper.sendScreenView("Info - $pageName", requireActivity()) @@ -97,16 +119,20 @@ class InfoFragment : MainNavigationFragment() { companion object { + private const val DIALOG_NEED_TO_SIGN_IN = "dialog_need_to_sign_in" + private const val DIALOG_CONFIRM_SIGN_OUT = "dialog_confirm_sign_out" + + private val INFO_TITLES = arrayOf( - R.string.event_title, - R.string.travel_title, - R.string.faq_title + R.string.event_title, + R.string.travel_title, + R.string.faq_title ) private val INFO_PAGES = arrayOf( - { EventFragment() }, - { TravelFragment() }, - { FaqFragment() } - // TODO: Track the InfoPage performance b/130335745 + { EventFragment() }, + { TravelFragment() }, + { FaqFragment() } + // TODO: Track the InfoPage performance b/130335745 ) } } diff --git a/mobile/src/main/java/com/google/samples/apps/iosched/ui/settings/SettingsFragment.kt b/mobile/src/main/java/com/google/samples/apps/iosched/ui/settings/SettingsFragment.kt index 059cf540f2..72c267a540 100644 --- a/mobile/src/main/java/com/google/samples/apps/iosched/ui/settings/SettingsFragment.kt +++ b/mobile/src/main/java/com/google/samples/apps/iosched/ui/settings/SettingsFragment.kt @@ -31,6 +31,9 @@ import com.google.samples.apps.iosched.databinding.FragmentSettingsBinding import com.google.samples.apps.iosched.shared.result.EventObserver import com.google.samples.apps.iosched.ui.MainActivityViewModel import com.google.samples.apps.iosched.ui.MainNavigationFragment +import com.google.samples.apps.iosched.ui.info.InfoFragment +import com.google.samples.apps.iosched.ui.signin.SignInDialogFragment +import com.google.samples.apps.iosched.ui.signin.SignOutDialogFragment import com.google.samples.apps.iosched.ui.signin.setupProfileMenuItem import com.google.samples.apps.iosched.util.doOnApplyWindowInsets import dagger.hilt.android.AndroidEntryPoint @@ -38,13 +41,18 @@ import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class SettingsFragment : MainNavigationFragment() { + companion object { + private const val DIALOG_NEED_TO_SIGN_IN = "dialog_need_to_sign_in" + private const val DIALOG_CONFIRM_SIGN_OUT = "dialog_confirm_sign_out" + } + private val viewModel: SettingsViewModel by viewModels() private val mainActivityViewModel: MainActivityViewModel by viewModels() override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? ): View? { viewModel.navigateToThemeSelector.observe(viewLifecycleOwner, EventObserver { @@ -61,9 +69,26 @@ class SettingsFragment : MainNavigationFragment() { binding.settingsScroll.doOnApplyWindowInsets { v, insets, padding -> v.updatePaddingRelative(bottom = padding.bottom + insets.systemWindowInsetBottom) } + mainActivityViewModel.navigateToSignInDialogAction.observe(viewLifecycleOwner, EventObserver { + openSignInDialog() + }) + + mainActivityViewModel.navigateToSignOutDialogAction.observe(viewLifecycleOwner, EventObserver { + openSignOutDialog() + }) return binding.root } + + private fun openSignInDialog() { + val dialog = SignInDialogFragment() + dialog.show(requireActivity().supportFragmentManager, SettingsFragment.DIALOG_NEED_TO_SIGN_IN) + } + + private fun openSignOutDialog() { + val dialog = SignOutDialogFragment() + dialog.show(requireActivity().supportFragmentManager, SettingsFragment.DIALOG_CONFIRM_SIGN_OUT) + } } @BindingAdapter(value = ["dialogTitle", "fileLink"], requireAll = true) @@ -74,10 +99,10 @@ fun createDialogForFile(button: View, dialogTitle: String, fileLink: String) { webView.settings.useWideViewPort = true webView.settings.loadWithOverviewMode = true AlertDialog.Builder(context) - .setTitle(dialogTitle) - .setView(webView) - .create() - .show() + .setTitle(dialogTitle) + .setView(webView) + .create() + .show() } }