From 92384dc9c71e8d9630fc0917bbd51fdb3af3bd61 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Tue, 3 May 2022 18:26:03 +0530 Subject: [PATCH 1/3] App lounge: (issue_266) create method shouldShowPaidAppsSnackBar() --- .../foundation/e/apps/MainActivityViewModel.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt index 73ff62972..5c8bd8b11 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 { -- GitLab From 88c12e2e82a6b79fff92ad1ef43a24bc1ed7e54f Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Tue, 3 May 2022 18:28:29 +0530 Subject: [PATCH 2/3] App lounge: (issue_266) Implement MainActivityViewModel.shouldShowPaidAppsSnackBar() instead of showing alert dialog. --- .../e/apps/application/ApplicationFragment.kt | 11 +++-------- .../applicationlist/ApplicationListFragment.kt | 16 +++------------- .../java/foundation/e/apps/home/HomeFragment.kt | 12 +++--------- .../foundation/e/apps/search/SearchFragment.kt | 16 +++------------- .../foundation/e/apps/updates/UpdatesFragment.kt | 15 +++------------ 5 files changed, 15 insertions(+), 55 deletions(-) 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 25713512d..5fe947dd8 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,9 @@ 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)) { + mainActivityViewModel.getApplication(fusedApp, it) + } } } } 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 456b1d3bc..e78031b23 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,9 @@ 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)) { + getApplication(fusedApp) + } } } 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 399cf52af..e9b6ddba4 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,9 @@ 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)) { + getApplication(fusedApp) + } } 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 7979ca525..cdd0c8c82 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,9 @@ 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)) { + getApplication(fusedApp) + } } } 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 c365ca6ae..da4d5ec0e 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,9 @@ 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)) { + getApplication(fusedApp) + } } } -- GitLab From 61ec037bb688be7fa40ba35d991f6a7e05efdc5c Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Tue, 3 May 2022 19:09:31 +0530 Subject: [PATCH 3/3] App lounge: (issue_266) Show alert dialog only for Google signed in users. Else just show snackbar. --- .../e/apps/application/ApplicationFragment.kt | 10 +++++++++- .../applicationlist/ApplicationListFragment.kt | 14 +++++++++++++- .../java/foundation/e/apps/home/HomeFragment.kt | 10 +++++++++- .../foundation/e/apps/search/SearchFragment.kt | 14 +++++++++++++- .../foundation/e/apps/updates/UpdatesFragment.kt | 14 +++++++++++++- 5 files changed, 57 insertions(+), 5 deletions(-) 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 5fe947dd8..d1031a4c1 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt @@ -413,7 +413,15 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { mainActivityViewModel.getApplication(fusedApp, it) } else { if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) { - mainActivityViewModel.getApplication(fusedApp, it) + 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 e78031b23..ada42adbc 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt @@ -120,7 +120,19 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu viewLifecycleOwner ) { fusedApp -> if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) { - getApplication(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 e9b6ddba4..8fc618938 100644 --- a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt @@ -93,7 +93,15 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { mainActivityViewModel, viewLifecycleOwner ) { fusedApp -> if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) { - getApplication(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/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index cdd0c8c82..1ef753bb1 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -128,7 +128,19 @@ class SearchFragment : viewLifecycleOwner ) { fusedApp -> if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) { - getApplication(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 da4d5ec0e..5b41db085 100644 --- a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt +++ b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt @@ -99,7 +99,19 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { viewLifecycleOwner, ) { fusedApp -> if (!mainActivityViewModel.shouldShowPaidAppsSnackBar(fusedApp)) { - getApplication(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") } } } -- GitLab