Loading app/src/main/java/foundation/e/apps/utils/parentFragment/TimeoutFragment2.kt +82 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ import foundation.e.apps.R import foundation.e.apps.databinding.DialogErrorLogBinding import foundation.e.apps.login.AuthObject import foundation.e.apps.login.LoginViewModel import foundation.e.apps.utils.enums.User import foundation.e.apps.utils.exceptions.GPlayValidationException import kotlinx.coroutines.launch /** Loading Loading @@ -61,6 +63,31 @@ abstract class TimeoutFragment2(@LayoutRes layoutId: Int) : Fragment(layoutId) { predefinedDialog: AlertDialog.Builder, ): AlertDialog.Builder? /** * Override to contain code to execute in case of other sign in error. * This can only happen for GPlay data as cleanapk does not need any login. * Do not call this function directly, use [showSignInError] for that. * * @param predefinedDialog An AlertDialog builder, already having some properties, * Fragment can change the dialog properties and return as the result. * By default: * 1. Dialog title set to [R.string.anonymous_login_failed] or [R.string.sign_in_failed_title] * 2. Content set to [R.string.anonymous_login_failed_desc] or [R.string.sign_in_failed_desc] * 3. Dialog can show technical error info on clicking "More Info" * 4. Has a positive button "Retry" which calls [LoginViewModel.startLoginFlow], * passing the list of failed auth types. * 5. Has a negative button "Logout" which logs the user out of App Lounge. * 6. Dialog is cancellable. * * @return An alert dialog (created from [predefinedDialog]) to show a timeout dialog, * or null to not show anything. */ abstract fun onSignInError( exception: GPlayValidationException, predefinedDialog: AlertDialog.Builder, ): AlertDialog.Builder? /** * Crucial to call this, other wise fragments will never receive any authentications. */ Loading Loading @@ -143,4 +170,59 @@ abstract class TimeoutFragment2(@LayoutRes layoutId: Int) : Fragment(layoutId) { showAndSetDialog(this) } } /** * Call to trigger [onSignInError]. * Only works if last loginUiAction was a failure case. Else nothing happens. * * Calls [onSignInError], which may return a [AlertDialog.Builder] * instance if it deems fit. Else it may return null, at which case no error dialog * is shown to the user. */ fun showSignInError(exception: GPlayValidationException) { val dialogView = DialogErrorLogBinding.inflate(requireActivity().layoutInflater) dialogView.apply { moreInfo.setOnClickListener { logDisplay.isVisible = true moreInfo.isVisible = false } val logToDisplay = exception.message ?: "" if (logToDisplay.isNotBlank()) { logDisplay.text = logToDisplay moreInfo.isVisible = true } } val predefinedDialog = AlertDialog.Builder(requireActivity()).apply { if (exception.user == User.GOOGLE) { setTitle(R.string.sign_in_failed_title) setMessage(R.string.sign_in_failed_desc) } else { setTitle(R.string.anonymous_login_failed) setMessage(R.string.anonymous_login_failed_desc) } setView(dialogView.root) setPositiveButton(R.string.retry) { _, _ -> showLoadingUI() loginViewModel.startLoginFlow(listOf(AuthObject.GPlayAuth::class.java.simpleName)) } setNegativeButton(R.string.logout) { _, _ -> loginViewModel.logout() } setCancelable(true) } onSignInError( exception, predefinedDialog, )?.run { stopLoadingUI() showAndSetDialog(this) } } } No newline at end of file Loading
app/src/main/java/foundation/e/apps/utils/parentFragment/TimeoutFragment2.kt +82 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ import foundation.e.apps.R import foundation.e.apps.databinding.DialogErrorLogBinding import foundation.e.apps.login.AuthObject import foundation.e.apps.login.LoginViewModel import foundation.e.apps.utils.enums.User import foundation.e.apps.utils.exceptions.GPlayValidationException import kotlinx.coroutines.launch /** Loading Loading @@ -61,6 +63,31 @@ abstract class TimeoutFragment2(@LayoutRes layoutId: Int) : Fragment(layoutId) { predefinedDialog: AlertDialog.Builder, ): AlertDialog.Builder? /** * Override to contain code to execute in case of other sign in error. * This can only happen for GPlay data as cleanapk does not need any login. * Do not call this function directly, use [showSignInError] for that. * * @param predefinedDialog An AlertDialog builder, already having some properties, * Fragment can change the dialog properties and return as the result. * By default: * 1. Dialog title set to [R.string.anonymous_login_failed] or [R.string.sign_in_failed_title] * 2. Content set to [R.string.anonymous_login_failed_desc] or [R.string.sign_in_failed_desc] * 3. Dialog can show technical error info on clicking "More Info" * 4. Has a positive button "Retry" which calls [LoginViewModel.startLoginFlow], * passing the list of failed auth types. * 5. Has a negative button "Logout" which logs the user out of App Lounge. * 6. Dialog is cancellable. * * @return An alert dialog (created from [predefinedDialog]) to show a timeout dialog, * or null to not show anything. */ abstract fun onSignInError( exception: GPlayValidationException, predefinedDialog: AlertDialog.Builder, ): AlertDialog.Builder? /** * Crucial to call this, other wise fragments will never receive any authentications. */ Loading Loading @@ -143,4 +170,59 @@ abstract class TimeoutFragment2(@LayoutRes layoutId: Int) : Fragment(layoutId) { showAndSetDialog(this) } } /** * Call to trigger [onSignInError]. * Only works if last loginUiAction was a failure case. Else nothing happens. * * Calls [onSignInError], which may return a [AlertDialog.Builder] * instance if it deems fit. Else it may return null, at which case no error dialog * is shown to the user. */ fun showSignInError(exception: GPlayValidationException) { val dialogView = DialogErrorLogBinding.inflate(requireActivity().layoutInflater) dialogView.apply { moreInfo.setOnClickListener { logDisplay.isVisible = true moreInfo.isVisible = false } val logToDisplay = exception.message ?: "" if (logToDisplay.isNotBlank()) { logDisplay.text = logToDisplay moreInfo.isVisible = true } } val predefinedDialog = AlertDialog.Builder(requireActivity()).apply { if (exception.user == User.GOOGLE) { setTitle(R.string.sign_in_failed_title) setMessage(R.string.sign_in_failed_desc) } else { setTitle(R.string.anonymous_login_failed) setMessage(R.string.anonymous_login_failed_desc) } setView(dialogView.root) setPositiveButton(R.string.retry) { _, _ -> showLoadingUI() loginViewModel.startLoginFlow(listOf(AuthObject.GPlayAuth::class.java.simpleName)) } setNegativeButton(R.string.logout) { _, _ -> loginViewModel.logout() } setCancelable(true) } onSignInError( exception, predefinedDialog, )?.run { stopLoadingUI() showAndSetDialog(this) } } } No newline at end of file