Skip to content
Snippets Groups Projects
Commit 51298bc1 authored by Taras's avatar Taras
Browse files

Remove reauth dialog fragment

parent 9193c6e3
No related branches found
No related tags found
No related merge requests found
......@@ -18,8 +18,8 @@
android:id="@+id/to_activeSessionsDialogFragment"
app:destination="@id/log_in_sessions_nav_graph" />
<action
android:id="@+id/to_reAuthStagesDialogFragment"
app:destination="@id/reAuthStagesDialogFragment" />
android:id="@+id/to_uiaDialogFragment"
app:destination="@id/UIADialogFragment" />
<action
android:id="@+id/to_pushNotificationsSettingsDialogFragment"
app:destination="@id/pushNotificationsSettingsDialogFragment" />
......@@ -50,14 +50,13 @@
<include app:graph="@navigation/log_in_sessions_nav_graph" />
<dialog
android:id="@+id/reAuthStagesDialogFragment"
android:name="org.futo.circles.auth.feature.reauth.ReAuthStagesDialogFragment"
tools:layout="@layout/fragment_login_stages" />
<dialog
android:id="@+id/manageSubscriptionDialogFragment"
android:name="org.futo.circles.auth.feature.manage_subscription.ManageSubscriptionDialogFragment"
tools:layout="@layout/dialog_fragment_manage_subscription" />
<dialog
android:id="@+id/UIADialogFragment"
android:name="org.futo.circles.auth.feature.uia.UIADialogFragment"
tools:layout="@layout/dialog_fragment_uia" />
</navigation>
\ No newline at end of file
package org.futo.circles.auth.feature.reauth
import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
@HiltViewModel
class ReAuthStageViewModel @Inject constructor(reAuthStagesDataSource: ReAuthStagesDataSource) : ViewModel() {
val subtitleLiveData = reAuthStagesDataSource.subtitleLiveData
val loginStageNavigationLiveData = reAuthStagesDataSource.loginStageNavigationLiveData
val finishReAuthEventLiveData = reAuthStagesDataSource.finishReAuthEventLiveData
}
\ No newline at end of file
package org.futo.circles.auth.feature.reauth
import android.app.Dialog
import android.os.Bundle
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.viewModels
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import dagger.hilt.android.AndroidEntryPoint
import org.futo.circles.auth.R
import org.futo.circles.auth.databinding.FragmentLoginStagesBinding
import org.futo.circles.core.base.fragment.BackPressOwner
import org.futo.circles.core.base.fragment.BaseFullscreenDialogFragment
import org.futo.circles.core.extensions.navigateSafe
import org.futo.circles.core.extensions.observeData
import org.futo.circles.core.extensions.onBackPressed
import org.futo.circles.core.extensions.showDialog
@AndroidEntryPoint
class ReAuthStagesDialogFragment :
BaseFullscreenDialogFragment(FragmentLoginStagesBinding::inflate), BackPressOwner {
private val viewModel by viewModels<ReAuthStageViewModel>()
private val binding by lazy {
getBinding() as FragmentLoginStagesBinding
}
private val childNavHostFragment by lazy {
childFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog =
object : Dialog(requireContext(), theme) {
@Suppress("OVERRIDE_DEPRECATION")
override fun onBackPressed() {
activity?.onBackPressedDispatcher?.onBackPressed()
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.toolbar.apply {
title = getString(R.string.confirm_auth)
setNavigationOnClickListener { handleBackAction() }
}
setupObservers()
}
private fun setupObservers() {
viewModel.loginStageNavigationLiveData.observeData(this) { event ->
val id = when (event) {
LoginStageNavigationEvent.DirectPassword -> R.id.to_direct_login
LoginStageNavigationEvent.Password -> R.id.to_reAuthPassword
LoginStageNavigationEvent.Terms -> R.id.to_ReAuthAcceptTerms
LoginStageNavigationEvent.BSspekeLogin -> R.id.to_reAuthBsSpekeLogin
LoginStageNavigationEvent.BSspekeSignup -> R.id.to_reAuthBsSpekeSignup
else -> throw IllegalArgumentException(getString(R.string.not_supported_navigation_event))
}
binding.navHostFragment.findNavController().navigateSafe(id)
}
viewModel.subtitleLiveData.observeData(this) {
binding.toolbar.subtitle = it
}
viewModel.finishReAuthEventLiveData.observeData(this) {
dismiss()
}
}
private fun showDiscardDialog() {
showDialog(
titleResIdRes = R.string.discard_current_login_progress,
negativeButtonVisible = true,
positiveAction = {
cancelReAuth()
findNavController().popBackStack()
}
)
}
override fun onChildBackPress(callback: OnBackPressedCallback) {
handleBackAction(callback)
}
private fun handleBackAction(callback: OnBackPressedCallback? = null) {
val includedFragmentsManager = childNavHostFragment.childFragmentManager
if (includedFragmentsManager.backStackEntryCount == 1) {
cancelReAuth()
callback?.remove()
onBackPressed()
} else {
showDiscardDialog()
}
}
private fun cancelReAuth() {
parentFragment?.childFragmentManager?.fragments?.forEach {
(it as? ReAuthCancellationListener)?.onReAuthCanceled()
}
}
}
\ No newline at end of file
package org.futo.circles.auth.feature.sign_up
package org.futo.circles.auth.feature.uia.flow
import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext
......@@ -13,14 +13,13 @@ import org.futo.circles.core.provider.MatrixInstanceProvider
import org.futo.circles.core.provider.MatrixSessionProvider
import org.futo.circles.core.provider.PreferencesProvider
import org.matrix.android.sdk.api.auth.registration.RegistrationResult
import org.matrix.android.sdk.api.auth.registration.Stage
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.JsonDict
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class SignUpDataSource @Inject constructor(
class SignUpStagesDataSource @Inject constructor(
@ApplicationContext private val context: Context,
private val createPassPhraseDataSource: CreatePassPhraseDataSource,
private val preferencesProvider: PreferencesProvider
......
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/log_in_nav_graph"
app:startDestination="@id/emptyFragment">
<action
android:id="@+id/to_acceptTerms"
app:destination="@id/acceptTermsFragmentLogin">
<argument
android:name="mode"
android:defaultValue="Login"
app:argType="org.futo.circles.auth.model.TermsModeArg"
app:nullable="false" />
</action>
<action
android:id="@+id/to_ReAuthAcceptTerms"
app:destination="@id/acceptTermsFragmentLogin">
<argument
android:name="mode"
android:defaultValue="ReAuth"
app:argType="org.futo.circles.auth.model.TermsModeArg"
app:nullable="false" />
</action>
<action
android:id="@+id/to_direct_login"
app:destination="@id/passwordFragmentLogin">
<argument
android:name="mode"
android:defaultValue="LoginDirect"
app:argType="org.futo.circles.auth.model.PasswordModeArg"
app:nullable="false" />
</action>
<action
android:id="@+id/to_password"
app:destination="@id/passwordFragmentLogin">
<argument
android:name="mode"
android:defaultValue="LoginPasswordStage"
app:argType="org.futo.circles.auth.model.PasswordModeArg"
app:nullable="false" />
</action>
<action
android:id="@+id/to_bsspeke"
app:destination="@id/passwordFragmentLogin">
<argument
android:name="mode"
android:defaultValue="LoginBsSpekeStage"
app:argType="org.futo.circles.auth.model.PasswordModeArg"
app:nullable="false" />
</action>
<action
android:id="@+id/to_reAuthPassword"
app:destination="@id/passwordFragmentLogin">
<argument
android:name="mode"
android:defaultValue="ReAuthPassword"
app:argType="org.futo.circles.auth.model.PasswordModeArg"
app:nullable="false" />
</action>
<action
android:id="@+id/to_reAuthBsSpekeLogin"
app:destination="@id/passwordFragmentLogin">
<argument
android:name="mode"
android:defaultValue="ReAuthBsSpekeLogin"
app:argType="org.futo.circles.auth.model.PasswordModeArg"
app:nullable="false" />
</action>
<action
android:id="@+id/to_reAuthBsSpekeSignup"
app:destination="@id/passwordFragmentLogin">
<argument
android:name="mode"
android:defaultValue="ReAuthBsSpekeSignup"
app:argType="org.futo.circles.auth.model.PasswordModeArg"
app:nullable="false" />
</action>
<fragment
android:id="@+id/acceptTermsFragmentLogin"
android:name="org.futo.circles.auth.feature.sign_up.terms.AcceptTermsFragment"
tools:layout="@layout/fragment_accept_terms">
<argument
android:name="mode"
app:argType="org.futo.circles.auth.model.TermsModeArg"
app:nullable="false" />
</fragment>
<fragment
android:id="@+id/passwordFragmentLogin"
android:name="org.futo.circles.auth.feature.sign_up.password.PasswordFragment"
tools:layout="@layout/fragment_password">
<argument
android:name="mode"
app:argType="org.futo.circles.auth.model.PasswordModeArg"
app:nullable="false" />
</fragment>
<fragment
android:id="@+id/emptyFragment"
android:name="org.futo.circles.auth.feature.log_in.EmptyFragment"
tools:layout="@layout/fragment_empty" />
</navigation>
\ No newline at end of file
......@@ -11,8 +11,8 @@
android:label="ActiveSessionsDialogFragment"
tools:layout="@layout/dialog_fragment_active_sessions">
<action
android:id="@+id/to_reAuthStagesDialogFragment"
app:destination="@id/reAuthStagesDialogFragment" />
android:id="@+id/to_uiaDialogFragment"
app:destination="@id/UIADialogFragment" />
<action
android:id="@+id/to_verifySessionDialogFragment"
......@@ -38,7 +38,7 @@
</dialog>
<dialog
android:id="@+id/reAuthStagesDialogFragment"
android:name="org.futo.circles.auth.feature.reauth.ReAuthStagesDialogFragment"
tools:layout="@layout/fragment_login_stages" />
android:id="@+id/UIADialogFragment"
android:name="org.futo.circles.auth.feature.uia.UIADialogFragment"
tools:layout="@layout/dialog_fragment_uia" />
</navigation>
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/sign_up_nav_graph"
app:startDestination="@id/selectSignUpTypeFragment">
<action
android:id="@+id/to_validateToken"
app:destination="@id/validateTokenFragment" />
<action
android:id="@+id/to_validateEmail"
app:destination="@id/validateEmailFragment" />
<action
android:id="@+id/to_acceptTerms"
app:destination="@id/acceptTermsFragment" />
<action
android:id="@+id/to_subscriptions"
app:destination="@id/subscriptionStageFragment" />
<action
android:id="@+id/to_username"
app:destination="@id/usernameFragment" />
<action
android:id="@+id/to_password"
app:destination="@id/passwordFragment">
<argument
android:name="mode"
android:defaultValue="SignupPasswordStage"
app:argType="org.futo.circles.auth.model.PasswordModeArg"
app:nullable="false" />
</action>
<action
android:id="@+id/to_bsspeke"
app:destination="@id/passwordFragment">
<argument
android:name="mode"
android:defaultValue="SignupBsSpekeStage"
app:argType="org.futo.circles.auth.model.PasswordModeArg"
app:nullable="false" />
</action>
<fragment
android:id="@+id/selectSignUpTypeFragment"
android:name="org.futo.circles.auth.feature.sign_up.sign_up_type.SelectSignUpTypeFragment"
tools:layout="@layout/fragment_select_sign_up_type" />
<fragment
android:id="@+id/validateTokenFragment"
android:name="org.futo.circles.auth.feature.sign_up.validate_token.ValidateTokenFragment"
tools:layout="@layout/fragment_validate_token" />
<fragment
android:id="@+id/validateEmailFragment"
android:name="org.futo.circles.auth.feature.sign_up.validate_email.ValidateEmailFragment"
tools:layout="@layout/fragment_validate_email" />
<fragment
android:id="@+id/acceptTermsFragment"
android:name="org.futo.circles.auth.feature.sign_up.terms.AcceptTermsFragment"
tools:layout="@layout/fragment_accept_terms">
<argument
android:name="mode"
android:defaultValue="Signup"
app:argType="org.futo.circles.auth.model.TermsModeArg"
app:nullable="false" />
</fragment>
<fragment
android:id="@+id/subscriptionStageFragment"
android:name="org.futo.circles.auth.feature.sign_up.subscription_stage.SubscriptionStageFragment"
tools:layout="@layout/fragment_subscription_stage" />
<fragment
android:id="@+id/passwordFragment"
android:name="org.futo.circles.auth.feature.sign_up.password.PasswordFragment"
tools:layout="@layout/fragment_password">
<argument
android:name="mode"
app:argType="org.futo.circles.auth.model.PasswordModeArg"
app:nullable="false" />
</fragment>
<fragment
android:id="@+id/usernameFragment"
android:name="org.futo.circles.auth.feature.sign_up.username.UsernameFragment"
tools:layout="@layout/fragment_username" />
</navigation>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment