diff --git a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt index 73ff6297200efcf070d5e8ea163be57835c13e5e..5c8bd8b11c8809aa4c11418d6dd0dfd318da8523 100644 --- a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt @@ -162,9 +162,22 @@ class MainActivityViewModel @Inject constructor( } } - fun getApplication(app: FusedApp, imageView: ImageView?) { + /* + * Check and display a snack bar if app is paid and user is logged in in anonymous mode. + * Returns true if the snack bar was displayed, false otherwise. + * + * Issue: https://gitlab.e.foundation/e/os/backlog/-/issues/266 + */ + fun shouldShowPaidAppsSnackBar(app: FusedApp): Boolean { if (!app.isFree && authData.value?.isAnonymous == true) { _errorMessageStringResource.value = R.string.paid_app_anonymous_message + return true + } + return false + } + + fun getApplication(app: FusedApp, imageView: ImageView?) { + if (shouldShowPaidAppsSnackBar(app)) { return } viewModelScope.launch { diff --git a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt index 25713512dfdcb5cbdd42dee8c6bf0e17fc085ba5..d1031a4c1c3904d796645acbcb0e258b14cea2a2 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt @@ -412,14 +412,17 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { if (fusedApp.isFree) { mainActivityViewModel.getApplication(fusedApp, it) } else { - ApplicationDialogFragment( - title = getString(R.string.dialog_title_paid_app, fusedApp.name), - message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price), - positiveButtonText = getString(R.string.dialog_confirm), - positiveButtonAction = { - }, - cancelButtonText = getString(R.string.dialog_cancel), - ).show(childFragmentManager, "ApplicationFragment") + if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) { + ApplicationDialogFragment( + title = getString(R.string.dialog_title_paid_app, fusedApp.name), + message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price), + positiveButtonText = getString(R.string.dialog_confirm), + positiveButtonAction = { + mainActivityViewModel.getApplication(fusedApp, it) + }, + cancelButtonText = getString(R.string.dialog_cancel), + ).show(childFragmentManager, "ApplicationFragment") + } } } } diff --git a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt index 456b1d3bcf4fad6efb5e8c8d8779a22a62d0a851..ada42adbc72cb2c0254a00f2dfd03a97b8aad561 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt @@ -119,19 +119,21 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), viewLifecycleOwner ) { fusedApp -> - ApplicationDialogFragment( - title = getString(R.string.dialog_title_paid_app, fusedApp.name), - message = getString( - R.string.dialog_paidapp_message, - fusedApp.name, - fusedApp.price - ), - positiveButtonText = getString(R.string.dialog_confirm), - positiveButtonAction = { - getApplication(fusedApp) - }, - cancelButtonText = getString(R.string.dialog_cancel), - ).show(childFragmentManager, "HomeFragment") + if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) { + ApplicationDialogFragment( + title = getString(R.string.dialog_title_paid_app, fusedApp.name), + message = getString( + R.string.dialog_paidapp_message, + fusedApp.name, + fusedApp.price + ), + positiveButtonText = getString(R.string.dialog_confirm), + positiveButtonAction = { + getApplication(fusedApp) + }, + cancelButtonText = getString(R.string.dialog_cancel), + ).show(childFragmentManager, "HomeFragment") + } } } diff --git a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt index 399cf52af27042606c3bc1ebabc07da0f77c5227..8fc6189389d3c317e535502cdcb0210c29539e22 100644 --- a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt @@ -92,15 +92,17 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), mainActivityViewModel, viewLifecycleOwner ) { fusedApp -> - ApplicationDialogFragment( - title = getString(R.string.dialog_title_paid_app, fusedApp.name), - message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price), - positiveButtonText = getString(R.string.dialog_confirm), - positiveButtonAction = { - getApplication(fusedApp) - }, - cancelButtonText = getString(R.string.dialog_cancel), - ).show(childFragmentManager, "HomeFragment") + if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) { + ApplicationDialogFragment( + title = getString(R.string.dialog_title_paid_app, fusedApp.name), + message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price), + positiveButtonText = getString(R.string.dialog_confirm), + positiveButtonAction = { + getApplication(fusedApp) + }, + cancelButtonText = getString(R.string.dialog_cancel), + ).show(childFragmentManager, "HomeFragment") + } } binding.parentRV.apply { diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index 7979ca5258a3139eb18238e8372074e4150bef49..1ef753bb1d36ef71a1ecf987db1a32f90220f3d6 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -127,19 +127,21 @@ class SearchFragment : User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), viewLifecycleOwner ) { fusedApp -> - ApplicationDialogFragment( - title = getString(R.string.dialog_title_paid_app, fusedApp.name), - message = getString( - R.string.dialog_paidapp_message, - fusedApp.name, - fusedApp.price - ), - positiveButtonText = getString(R.string.dialog_confirm), - positiveButtonAction = { - getApplication(fusedApp) - }, - cancelButtonText = getString(R.string.dialog_cancel), - ).show(childFragmentManager, "SearchFragment") + if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) { + ApplicationDialogFragment( + title = getString(R.string.dialog_title_paid_app, fusedApp.name), + message = getString( + R.string.dialog_paidapp_message, + fusedApp.name, + fusedApp.price + ), + positiveButtonText = getString(R.string.dialog_confirm), + positiveButtonAction = { + getApplication(fusedApp) + }, + cancelButtonText = getString(R.string.dialog_cancel), + ).show(childFragmentManager, "SearchFragment") + } } } diff --git a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt index c365ca6ae7a39dfb914a40b965216ed67d92f0a4..5b41db0854b5eed35da55d84dc9459bc1362665d 100644 --- a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt +++ b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt @@ -98,18 +98,21 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { User.valueOf(mainActivityViewModel.userType.value ?: User.UNAVAILABLE.name), viewLifecycleOwner, ) { fusedApp -> - ApplicationDialogFragment( - title = getString(R.string.dialog_title_paid_app, fusedApp.name), - message = getString( - R.string.dialog_paidapp_message, - fusedApp.name, - fusedApp.price - ), - positiveButtonText = getString(R.string.dialog_confirm), - positiveButtonAction = { - }, - cancelButtonText = getString(R.string.dialog_cancel), - ).show(childFragmentManager, "UpdatesFragment") + if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) { + ApplicationDialogFragment( + title = getString(R.string.dialog_title_paid_app, fusedApp.name), + message = getString( + R.string.dialog_paidapp_message, + fusedApp.name, + fusedApp.price + ), + positiveButtonText = getString(R.string.dialog_confirm), + positiveButtonAction = { + getApplication(fusedApp) + }, + cancelButtonText = getString(R.string.dialog_cancel), + ).show(childFragmentManager, "UpdatesFragment") + } } }