From d58223a13b8ffae3a8d1769a29b3d0d336462cf7 Mon Sep 17 00:00:00 2001 From: Taras Smakula <tarassmakula@gmail.com> Date: Tue, 27 Feb 2024 17:50:48 +0200 Subject: [PATCH] Remove login stages fragment --- .../log_in/stages/LogInStagesFragment.kt | 144 ------------------ .../log_in/stages/LoginStagesViewModel.kt | 46 ------ .../main/res/layout/fragment_login_stages.xml | 43 ------ .../main/res/navigation/nav_graph_auth.xml | 14 -- 4 files changed, 247 deletions(-) delete mode 100644 auth/src/main/java/org/futo/circles/auth/feature/log_in/stages/LogInStagesFragment.kt delete mode 100644 auth/src/main/java/org/futo/circles/auth/feature/log_in/stages/LoginStagesViewModel.kt delete mode 100644 auth/src/main/res/layout/fragment_login_stages.xml diff --git a/auth/src/main/java/org/futo/circles/auth/feature/log_in/stages/LogInStagesFragment.kt b/auth/src/main/java/org/futo/circles/auth/feature/log_in/stages/LogInStagesFragment.kt deleted file mode 100644 index bc0e0af57..000000000 --- a/auth/src/main/java/org/futo/circles/auth/feature/log_in/stages/LogInStagesFragment.kt +++ /dev/null @@ -1,144 +0,0 @@ -package org.futo.circles.auth.feature.log_in.stages - -import android.net.Uri -import android.os.Bundle -import android.view.View -import androidx.activity.OnBackPressedCallback -import androidx.activity.result.contract.ActivityResultContracts -import androidx.fragment.app.Fragment -import androidx.fragment.app.viewModels -import androidx.navigation.findNavController -import androidx.navigation.fragment.NavHostFragment -import androidx.navigation.fragment.findNavController -import by.kirich1409.viewbindingdelegate.viewBinding -import dagger.hilt.android.AndroidEntryPoint -import org.futo.circles.auth.R -import org.futo.circles.auth.databinding.FragmentLoginStagesBinding -import org.futo.circles.auth.feature.log_in.recovery.EnterPassPhraseDialog -import org.futo.circles.auth.feature.log_in.recovery.EnterPassPhraseDialogListener -import org.futo.circles.core.base.NetworkObserver -import org.futo.circles.core.base.fragment.BackPressOwner -import org.futo.circles.core.extensions.navigateSafe -import org.futo.circles.core.extensions.observeData -import org.futo.circles.core.extensions.observeResponse -import org.futo.circles.core.extensions.onBackPressed -import org.futo.circles.core.extensions.setEnabledViews -import org.futo.circles.core.extensions.showDialog -import org.futo.circles.core.extensions.showError -import org.futo.circles.core.view.LoadingDialog - -@AndroidEntryPoint -class LogInStagesFragment : Fragment(R.layout.fragment_login_stages), - BackPressOwner { - - private val viewModel by viewModels<LoginStagesViewModel>() - private val binding by viewBinding(FragmentLoginStagesBinding::bind) - - private val loadingDialog by lazy { LoadingDialog(requireContext()) } - private var enterPassPhraseDialog: EnterPassPhraseDialog? = null - - private val deviceIntentLauncher = registerForActivityResult( - ActivityResultContracts.GetContent() - ) { uri -> - uri ?: return@registerForActivityResult - enterPassPhraseDialog?.selectFile(uri) - } - - private val childNavHostFragment by lazy { - childFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - binding.toolbar.setNavigationOnClickListener { onBackPressed() } - binding.toolbar.title = getString(R.string.log_in) - setupObservers() - } - - private fun setupObservers() { - NetworkObserver.observe(this) { setEnabledViews(it) } - viewModel.loginStageNavigationLiveData.observeData(this) { event -> - val id = when (event) { - LoginStageNavigationEvent.DirectPassword -> R.id.to_direct_login - LoginStageNavigationEvent.Password -> R.id.to_password - LoginStageNavigationEvent.Terms -> R.id.to_acceptTerms - LoginStageNavigationEvent.BSspekeLogin -> R.id.to_bsspeke - else -> throw IllegalArgumentException(getString(R.string.not_supported_navigation_event)) - } - binding.navHostFragment.findNavController().navigateSafe(id) - } - viewModel.subtitleLiveData.observeData(this) { - binding.toolbar.subtitle = it - } - viewModel.restoreKeysLiveData.observeResponse( - this, - error = { - showError(it) - loadingDialog.dismiss() - } - ) - viewModel.passPhraseLoadingLiveData.observeData(this) { - loadingDialog.handleLoading(it) - } - viewModel.loginNavigationLiveData.observeData(this) { event -> - when (event) { - LoginNavigationEvent.Main -> navigateToHome() - LoginNavigationEvent.PassPhrase -> showPassPhraseDialog() - else -> navigateToHome() - } - } - } - - private fun showPassPhraseDialog() { - enterPassPhraseDialog = - EnterPassPhraseDialog(requireContext(), object : EnterPassPhraseDialogListener { - override fun onRestoreBackupWithPassphrase(passphrase: String) { - viewModel.restoreBackupWithPassPhrase(passphrase) - } - - override fun onRestoreBackupWithRawKey(key: String) { - viewModel.restoreBackupWithRawKey(key) - } - - override fun onRestoreBackup(uri: Uri) { - viewModel.restoreBackup(uri) - } - - override fun onDoNotRestore() { - viewModel.onDoNotRestoreBackup() - } - - override fun onSelectFileClicked() { - deviceIntentLauncher.launch(recoveryKeyMimeType) - } - }).apply { - setOnDismissListener { enterPassPhraseDialog = null } - show() - } - } - - private fun navigateToHome() { - findNavController().navigateSafe(LogInStagesFragmentDirections.toHomeFragment()) - } - - private fun showDiscardDialog() { - showDialog( - titleResIdRes = R.string.discard_current_login_progress, - negativeButtonVisible = true, - positiveAction = { findNavController().popBackStack() }) - } - - override fun onChildBackPress(callback: OnBackPressedCallback) { - val includedFragmentsManager = childNavHostFragment.childFragmentManager - if (includedFragmentsManager.backStackEntryCount == 0) { - callback.remove() - onBackPressed() - } else { - showDiscardDialog() - } - } - - companion object { - private const val recoveryKeyMimeType = "text/plain" - } -} \ No newline at end of file diff --git a/auth/src/main/java/org/futo/circles/auth/feature/log_in/stages/LoginStagesViewModel.kt b/auth/src/main/java/org/futo/circles/auth/feature/log_in/stages/LoginStagesViewModel.kt deleted file mode 100644 index 5643512fa..000000000 --- a/auth/src/main/java/org/futo/circles/auth/feature/log_in/stages/LoginStagesViewModel.kt +++ /dev/null @@ -1,46 +0,0 @@ -package org.futo.circles.auth.feature.log_in.stages - -import android.net.Uri -import androidx.lifecycle.ViewModel -import dagger.hilt.android.lifecycle.HiltViewModel -import org.futo.circles.core.base.SingleEventLiveData -import org.futo.circles.core.extensions.Response -import org.futo.circles.core.extensions.launchBg -import javax.inject.Inject - -@HiltViewModel -class LoginStagesViewModel @Inject constructor( - private val loginStagesDataSource: LoginStagesDataSource -) : ViewModel() { - - val subtitleLiveData = loginStagesDataSource.subtitleLiveData - val loginStageNavigationLiveData = loginStagesDataSource.loginStageNavigationLiveData - val restoreKeysLiveData = SingleEventLiveData<Response<Unit>>() - val loginNavigationLiveData = loginStagesDataSource.loginNavigationLiveData - val passPhraseLoadingLiveData = loginStagesDataSource.passPhraseLoadingLiveData - - fun restoreBackupWithPassPhrase(passphrase: String) { - launchBg { - val result = loginStagesDataSource.restoreBackupWithPassphrase(passphrase) - restoreKeysLiveData.postValue(result) - } - } - - fun restoreBackupWithRawKey(rawKey: String) { - launchBg { - val result = loginStagesDataSource.restoreBackupWithRawKey(rawKey) - restoreKeysLiveData.postValue(result) - } - } - - fun restoreBackup(uri: Uri) { - launchBg { - restoreKeysLiveData.postValue(loginStagesDataSource.restoreBackup(uri)) - } - } - - fun onDoNotRestoreBackup() { - loginStagesDataSource.navigateToMain() - } - -} \ No newline at end of file diff --git a/auth/src/main/res/layout/fragment_login_stages.xml b/auth/src/main/res/layout/fragment_login_stages.xml deleted file mode 100644 index dfdf2442a..000000000 --- a/auth/src/main/res/layout/fragment_login_stages.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent" - android:layout_height="match_parent"> - - <com.google.android.material.appbar.MaterialToolbar - android:id="@+id/toolbar" - android:layout_width="0dp" - android:layout_height="?attr/actionBarSize" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" - app:navigationContentDescription="@string/back" - app:navigationIcon="?attr/homeAsUpIndicator" - app:subtitleCentered="true" - app:titleCentered="true" - tools:title="@string/log_in" /> - - <View - android:id="@+id/toolbarDivider" - android:layout_width="0dp" - android:layout_height="@dimen/divider_height" - android:background="@color/divider_color" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/toolbar" /> - - <androidx.fragment.app.FragmentContainerView - android:id="@+id/nav_host_fragment" - android:name="androidx.navigation.fragment.NavHostFragment" - android:layout_width="0dp" - android:layout_height="0dp" - app:defaultNavHost="true" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/toolbarDivider" - app:navGraph="@navigation/log_in_nav_graph" /> - - -</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/auth/src/main/res/navigation/nav_graph_auth.xml b/auth/src/main/res/navigation/nav_graph_auth.xml index 7159ab2f3..7bded3301 100644 --- a/auth/src/main/res/navigation/nav_graph_auth.xml +++ b/auth/src/main/res/navigation/nav_graph_auth.xml @@ -13,9 +13,6 @@ <action android:id="@+id/to_signUpFragment" app:destination="@id/signUpFragment" /> - <action - android:id="@+id/to_loginStagesFragment" - app:destination="@id/loginStagesFragment" /> <action android:id="@+id/to_uiaFragment" app:destination="@id/uiaFragment" /> @@ -25,17 +22,6 @@ app:popUpTo="@id/logInFragment" app:popUpToInclusive="true" /> </fragment> - <fragment - android:id="@+id/loginStagesFragment" - android:name="org.futo.circles.auth.feature.log_in.stages.LogInStagesFragment" - tools:layout="@layout/fragment_login_stages"> - - <action - android:id="@+id/to_homeFragment" - app:destination="@id/homeFragment" - app:popUpTo="@id/logInFragment" - app:popUpToInclusive="true" /> - </fragment> <dialog android:id="@+id/uiaFragment" -- GitLab