From 48440d69edb2a46eb5b1da8bb9a9ae16913a8a30 Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Wed, 19 Jul 2023 18:12:48 +0300 Subject: [PATCH 01/13] When merged, this commit will; - Add fragments and fragment presenters for the 3 app deprecation dialogs being introduced. - Create a new DeprecationAppListener to listen to clicks on dialog options. - Add string resources for text to be displayed on the new dialogs. --- .../app/fragment/FragmentComponentImpl.kt | 8 +++- ...maticAppDeprecationNoticeDialogFragment.kt | 37 --------------- ...eprecationNoticeDialogFragmentPresenter.kt | 31 ------------- .../notice/DeprecationNoticeActionListener.kt | 12 +++++ .../DeprecationNoticeExitAppListener.kt | 7 --- ...orcedAppDeprecationNoticeDialogFragment.kt | 30 +++++++++++++ ...eprecationNoticeDialogFragmentPresenter.kt | 37 +++++++++++++++ ...ionalAppDeprecationNoticeDialogFragment.kt | 30 +++++++++++++ ...eprecationNoticeDialogFragmentPresenter.kt | 37 +++++++++++++++ .../OsDeprecationNoticeDialogFragment.kt | 33 ++++++++++++++ ...eprecationNoticeDialogFragmentPresenter.kt | 32 +++++++++++++ .../android/app/splash/SplashActivity.kt | 26 +++++++++-- .../app/splash/SplashActivityPresenter.kt | 45 ++++++++++++++++++- app/src/main/res/values/strings.xml | 28 +++++++++++- 14 files changed, 309 insertions(+), 84 deletions(-) delete mode 100644 app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragment.kt delete mode 100644 app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragmentPresenter.kt create mode 100644 app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeActionListener.kt delete mode 100644 app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeExitAppListener.kt create mode 100644 app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragment.kt create mode 100644 app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt create mode 100644 app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragment.kt create mode 100644 app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt create mode 100644 app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragment.kt create mode 100644 app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt diff --git a/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt b/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt index d89e5b1297b..f18f50a0077 100644 --- a/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt +++ b/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt @@ -29,9 +29,11 @@ import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedFragment import org.oppia.android.app.mydownloads.DownloadsTabFragment import org.oppia.android.app.mydownloads.MyDownloadsFragment import org.oppia.android.app.mydownloads.UpdatesTabFragment -import org.oppia.android.app.notice.AutomaticAppDeprecationNoticeDialogFragment +import org.oppia.android.app.notice.ForcedAppDeprecationNoticeDialogFragment import org.oppia.android.app.notice.BetaNoticeDialogFragment import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeDialogFragment +import org.oppia.android.app.notice.OptionalAppDeprecationNoticeDialogFragment +import org.oppia.android.app.notice.OsDeprecationNoticeDialogFragment import org.oppia.android.app.onboarding.OnboardingFragment import org.oppia.android.app.ongoingtopiclist.OngoingTopicListFragment import org.oppia.android.app.options.AppLanguageFragment @@ -113,7 +115,6 @@ interface FragmentComponentImpl : FragmentComponent, ViewComponentBuilderInjecto fun inject(appVersionFragment: AppVersionFragment) fun inject(audioFragment: AudioFragment) fun inject(audioLanguageFragment: AudioLanguageFragment) - fun inject(autoAppDeprecationNoticeDialogFragment: AutomaticAppDeprecationNoticeDialogFragment) fun inject(betaNoticeDialogFragment: BetaNoticeDialogFragment) fun inject(cellularAudioDialogFragment: CellularAudioDialogFragment) fun inject(completedStoryListFragment: CompletedStoryListFragment) @@ -127,6 +128,7 @@ interface FragmentComponentImpl : FragmentComponent, ViewComponentBuilderInjecto fun inject(explorationTestActivityTestFragment: ExplorationTestActivityPresenter.TestFragment) fun inject(faqListFragment: FAQListFragment) fun inject(forceNetworkTypeFragment: ForceNetworkTypeFragment) + fun inject(forcedAppDeprecationNoticeDialogFragment: ForcedAppDeprecationNoticeDialogFragment) fun inject(fragment: GeneralAvailabilityUpgradeNoticeDialogFragment) fun inject(helpFragment: HelpFragment) fun inject(hintsAndSolutionDialogFragment: HintsAndSolutionDialogFragment) @@ -146,7 +148,9 @@ interface FragmentComponentImpl : FragmentComponent, ViewComponentBuilderInjecto fun inject(navigationDrawerFragment: NavigationDrawerFragment) fun inject(onboardingFragment: OnboardingFragment) fun inject(ongoingTopicListFragment: OngoingTopicListFragment) + fun inject(optionalAppDeprecationNoticeDialogFragment: OptionalAppDeprecationNoticeDialogFragment) fun inject(optionFragment: OptionsFragment) + fun inject(osDeprecationNoticeDialogFragment: OsDeprecationNoticeDialogFragment) fun inject(policiesFragment: PoliciesFragment) fun inject(profileAndDeviceIdFragment: ProfileAndDeviceIdFragment) fun inject(profileChooserFragment: ProfileChooserFragment) diff --git a/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragment.kt b/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragment.kt deleted file mode 100644 index f4f8beed7fe..00000000000 --- a/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragment.kt +++ /dev/null @@ -1,37 +0,0 @@ -package org.oppia.android.app.notice - -import android.app.Dialog -import android.content.Context -import android.os.Bundle -import org.oppia.android.app.fragment.FragmentComponentImpl -import org.oppia.android.app.fragment.InjectableDialogFragment -import javax.inject.Inject - -/** - * Dialog fragment to be shown when the pre-release version of the app should no longer be playable - * due to it being expired. - * - * This notice protects the app from unexpected issues being permanently shipped to individuals, and - * from the app being accessible to audience members for long-periods of time when it may not yet be - * ready for broad use or distribution. - */ -class AutomaticAppDeprecationNoticeDialogFragment : InjectableDialogFragment() { - companion object { - /** Returns a new instance of [AutomaticAppDeprecationNoticeDialogFragment]. */ - fun newInstance(): AutomaticAppDeprecationNoticeDialogFragment { - return AutomaticAppDeprecationNoticeDialogFragment() - } - } - - @Inject lateinit var automaticAppDeprecationNoticeDialogFragmentPresenter: - AutomaticAppDeprecationNoticeDialogFragmentPresenter - - override fun onAttach(context: Context) { - super.onAttach(context) - (fragmentComponent as FragmentComponentImpl).inject(this) - } - - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - return automaticAppDeprecationNoticeDialogFragmentPresenter.handleOnCreateDialog() - } -} diff --git a/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragmentPresenter.kt deleted file mode 100644 index b587df03185..00000000000 --- a/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragmentPresenter.kt +++ /dev/null @@ -1,31 +0,0 @@ -package org.oppia.android.app.notice - -import android.app.Dialog -import androidx.appcompat.app.AlertDialog -import androidx.appcompat.app.AppCompatActivity -import org.oppia.android.R -import javax.inject.Inject - -/** - * Presenter for the dialog that shows when the pre-release app is being automatically deprecated. - */ -class AutomaticAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( - private val activity: AppCompatActivity -) { - private val deprecationNoticeExitAppListener by lazy { - activity as DeprecationNoticeExitAppListener - } - - fun handleOnCreateDialog(): Dialog { - val dialog = AlertDialog.Builder(activity) - .setTitle(R.string.unsupported_app_version_dialog_title) - .setMessage(R.string.unsupported_app_version_dialog_message) - .setNegativeButton(R.string.unsupported_app_version_dialog_close_button_text) { _, _ -> - deprecationNoticeExitAppListener.onCloseAppButtonClicked() - } - .setCancelable(false) - .create() - dialog.setCanceledOnTouchOutside(false) - return dialog - } -} diff --git a/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeActionListener.kt b/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeActionListener.kt new file mode 100644 index 00000000000..300a869ae89 --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeActionListener.kt @@ -0,0 +1,12 @@ +package org.oppia.android.app.notice + +import org.oppia.android.app.splash.DeprecationNoticeActionType + +/** Listener for when an option on any deprecation dialog is clicked. */ +interface DeprecationNoticeActionListener { + /** Called when the positive dialog button is clicked. */ + fun onPositiveActionButtonClicked(noticeType: DeprecationNoticeActionType) + + /** Called when the negative dialog button is clicked. */ + fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) +} diff --git a/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeExitAppListener.kt b/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeExitAppListener.kt deleted file mode 100644 index ff3d7dd1671..00000000000 --- a/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeExitAppListener.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.oppia.android.app.notice - -/** Listener for when the app deprecation dialog is closed. */ -interface DeprecationNoticeExitAppListener { - /** Called when the deprecation dialog was closed. */ - fun onCloseAppButtonClicked() -} diff --git a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragment.kt b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragment.kt new file mode 100644 index 00000000000..9a363228c25 --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragment.kt @@ -0,0 +1,30 @@ +package org.oppia.android.app.notice + +import android.app.Dialog +import android.content.Context +import android.os.Bundle +import org.oppia.android.app.fragment.FragmentComponentImpl +import org.oppia.android.app.fragment.InjectableDialogFragment +import javax.inject.Inject + +/** Dialog fragment that informs the user of an app deprecation. */ +class ForcedAppDeprecationNoticeDialogFragment : InjectableDialogFragment() { + companion object { + /** Returns a new instance of [ForcedAppDeprecationNoticeDialogFragment]. */ + fun newInstance(): ForcedAppDeprecationNoticeDialogFragment { + return ForcedAppDeprecationNoticeDialogFragment() + } + } + + @Inject lateinit var forcedAppDeprecationNoticeDialogFragmentPresenter: + ForcedAppDeprecationNoticeDialogFragmentPresenter + + override fun onAttach(context: Context) { + super.onAttach(context) + (fragmentComponent as FragmentComponentImpl).inject(this) + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + return forcedAppDeprecationNoticeDialogFragmentPresenter.handleOnCreateDialog() + } +} diff --git a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt new file mode 100644 index 00000000000..f1b4a085bb0 --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt @@ -0,0 +1,37 @@ +package org.oppia.android.app.notice + +import android.app.Dialog +import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatActivity +import org.oppia.android.R +import javax.inject.Inject +import org.oppia.android.app.splash.DeprecationNoticeActionType + +/** Presenter class responsible for showing an app deprecation dialog to the user. */ +class ForcedAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( + private val activity: AppCompatActivity +) { + private val deprecationNoticeExitAppListener by lazy { + activity as DeprecationNoticeActionListener + } + + fun handleOnCreateDialog(): Dialog { + val dialog = AlertDialog.Builder(activity, R.style.DeprecationAlertDialogTheme) + .setTitle(R.string.unsupported_app_version_dialog_title) + .setMessage(R.string.unsupported_app_version_dialog_message) + .setPositiveButton(R.string.unsupported_app_version_dialog_update_button_text) { _, _ -> + deprecationNoticeExitAppListener.onPositiveActionButtonClicked( + DeprecationNoticeActionType.UPDATE + ) + } + .setNegativeButton(R.string.unsupported_app_version_dialog_close_button_text) { _, _ -> + deprecationNoticeExitAppListener.onNegativeActionButtonClicked( + DeprecationNoticeActionType.CLOSE + ) + } + .setCancelable(false) + .create() + dialog.setCanceledOnTouchOutside(false) + return dialog + } +} diff --git a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragment.kt b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragment.kt new file mode 100644 index 00000000000..ff7d1b0451c --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragment.kt @@ -0,0 +1,30 @@ +package org.oppia.android.app.notice + +import android.app.Dialog +import android.content.Context +import android.os.Bundle +import org.oppia.android.app.fragment.FragmentComponentImpl +import org.oppia.android.app.fragment.InjectableDialogFragment +import javax.inject.Inject + +/** Dialog fragment that informs the user that a new app version is available for download. */ +class OptionalAppDeprecationNoticeDialogFragment : InjectableDialogFragment() { + companion object { + /** Returns a new instance of [OptionalAppDeprecationNoticeDialogFragment]. */ + fun newInstance(): OptionalAppDeprecationNoticeDialogFragment { + return OptionalAppDeprecationNoticeDialogFragment() + } + } + + @Inject lateinit var optionalAppDeprecationNoticeDialogFragmentPresenter: + OptionalAppDeprecationNoticeDialogFragmentPresenter + + override fun onAttach(context: Context) { + super.onAttach(context) + (fragmentComponent as FragmentComponentImpl).inject(this) + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + return optionalAppDeprecationNoticeDialogFragmentPresenter.handleOnCreateDialog() + } +} \ No newline at end of file diff --git a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt new file mode 100644 index 00000000000..1376bb48c8b --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt @@ -0,0 +1,37 @@ +package org.oppia.android.app.notice + +import android.app.Dialog +import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatActivity +import org.oppia.android.R +import org.oppia.android.app.splash.DeprecationNoticeActionType +import javax.inject.Inject + +/** Presenter class responsible for showing an optional update dialog to the user. */ +class OptionalAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( + private val activity: AppCompatActivity +) { + private val deprecationNoticeExitAppListener by lazy { + activity as DeprecationNoticeActionListener + } + + fun handleOnCreateDialog(): Dialog { + val dialog = AlertDialog.Builder(activity, R.style.DeprecationAlertDialogTheme) + .setTitle(R.string.optional_app_update_dialog_title) + .setMessage(R.string.optional_app_update_dialog_message) + .setPositiveButton(R.string.optional_app_update_dialog_update_button_text) { _, _ -> + deprecationNoticeExitAppListener.onPositiveActionButtonClicked( + DeprecationNoticeActionType.UPDATE + ) + } + .setNegativeButton(R.string.optional_app_update_dialog_dismiss_button_text) { _, _ -> + deprecationNoticeExitAppListener.onPositiveActionButtonClicked( + DeprecationNoticeActionType.DISMISS + ) + } + .setCancelable(false) + .create() + dialog.setCanceledOnTouchOutside(false) + return dialog + } +} \ No newline at end of file diff --git a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragment.kt b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragment.kt new file mode 100644 index 00000000000..a831bcad460 --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragment.kt @@ -0,0 +1,33 @@ +package org.oppia.android.app.notice + +import android.app.Dialog +import android.content.Context +import android.os.Bundle +import org.oppia.android.app.fragment.FragmentComponentImpl +import org.oppia.android.app.fragment.InjectableDialogFragment +import javax.inject.Inject + +/** + * Dialog fragment that informs the user that their phone OS is no longer supported by Oppia and + * they will no longer be able to update their app to the latest version. + */ +class OsDeprecationNoticeDialogFragment : InjectableDialogFragment() { + companion object { + /** Returns a new instance of [OsDeprecationNoticeDialogFragment]. */ + fun newInstance(): OsDeprecationNoticeDialogFragment { + return OsDeprecationNoticeDialogFragment() + } + } + + @Inject lateinit var osDeprecationNoticeDialogFragmentPresenter: + OsDeprecationNoticeDialogFragmentPresenter + + override fun onAttach(context: Context) { + super.onAttach(context) + (fragmentComponent as FragmentComponentImpl).inject(this) + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + return osDeprecationNoticeDialogFragmentPresenter.handleOnCreateDialog() + } +} \ No newline at end of file diff --git a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt new file mode 100644 index 00000000000..5cab46ad02a --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt @@ -0,0 +1,32 @@ +package org.oppia.android.app.notice + +import android.app.Dialog +import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatActivity +import org.oppia.android.R +import org.oppia.android.app.splash.DeprecationNoticeActionType +import javax.inject.Inject + +/** Presenter class responsible for showing an OS deprecation dialog to the user. */ +class OsDeprecationNoticeDialogFragmentPresenter @Inject constructor( + private val activity: AppCompatActivity +) { + private val deprecationNoticeExitAppListener by lazy { + activity as DeprecationNoticeActionListener + } + + fun handleOnCreateDialog(): Dialog { + val dialog = AlertDialog.Builder(activity, R.style.DeprecationAlertDialogTheme) + .setTitle(R.string.os_deprecation_dialog_title) + .setMessage(R.string.os_deprecation_dialog_message) + .setNegativeButton(R.string.os_deprecation_dialog_dismiss_button_text) { _, _ -> + deprecationNoticeExitAppListener.onPositiveActionButtonClicked( + DeprecationNoticeActionType.DISMISS + ) + } + .setCancelable(false) + .create() + dialog.setCanceledOnTouchOutside(false) + return dialog + } +} \ No newline at end of file diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt index 1952e72ae3b..0186df174c0 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt @@ -11,11 +11,17 @@ import org.oppia.android.app.fragment.FragmentComponentBuilderInjector import org.oppia.android.app.fragment.FragmentComponentFactory import org.oppia.android.app.model.ScreenName.SPLASH_ACTIVITY import org.oppia.android.app.notice.BetaNoticeClosedListener -import org.oppia.android.app.notice.DeprecationNoticeExitAppListener +import org.oppia.android.app.notice.DeprecationNoticeActionListener import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeClosedListener import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName import javax.inject.Inject +enum class DeprecationNoticeActionType { + CLOSE, + DISMISS, + UPDATE +} + /** * An activity that shows a temporary loading page until the app is fully loaded then navigates to * the profile selection screen. @@ -27,7 +33,7 @@ import javax.inject.Inject class SplashActivity : AppCompatActivity(), FragmentComponentFactory, - DeprecationNoticeExitAppListener, + DeprecationNoticeActionListener, BetaNoticeClosedListener, GeneralAvailabilityUpgradeNoticeClosedListener { @@ -50,7 +56,21 @@ class SplashActivity : return builderInjector.getFragmentComponentBuilderProvider().get().setFragment(fragment).build() } - override fun onCloseAppButtonClicked() = splashActivityPresenter.handleOnCloseAppButtonClicked() + override fun onPositiveActionButtonClicked(noticeType: DeprecationNoticeActionType) { + when (noticeType) { + DeprecationNoticeActionType.CLOSE -> splashActivityPresenter.handleOnCloseAppButtonClicked() + DeprecationNoticeActionType.DISMISS -> splashActivityPresenter.handleOnDismissButtonClicked() + DeprecationNoticeActionType.UPDATE -> splashActivityPresenter.handleOnUpdateButtonClicked() + } + } + + override fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) { + when (noticeType) { + DeprecationNoticeActionType.CLOSE -> splashActivityPresenter.handleOnCloseAppButtonClicked() + DeprecationNoticeActionType.DISMISS -> splashActivityPresenter.handleOnDismissButtonClicked() + DeprecationNoticeActionType.UPDATE -> splashActivityPresenter.handleOnUpdateButtonClicked() + } + } override fun onBetaNoticeOkayButtonClicked(permanentlyDismiss: Boolean) = splashActivityPresenter.handleOnBetaNoticeOkayButtonClicked(permanentlyDismiss) diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt index cfdf37874bf..9330d13ae43 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt @@ -1,5 +1,8 @@ package org.oppia.android.app.splash +import android.content.ActivityNotFoundException +import android.content.Intent +import android.net.Uri import androidx.appcompat.app.AppCompatActivity import androidx.databinding.DataBindingUtil import androidx.fragment.app.DialogFragment @@ -10,7 +13,7 @@ import org.oppia.android.app.model.AppStartupState import org.oppia.android.app.model.AppStartupState.BuildFlavorNoticeMode import org.oppia.android.app.model.AppStartupState.StartupMode import org.oppia.android.app.model.BuildFlavor -import org.oppia.android.app.notice.AutomaticAppDeprecationNoticeDialogFragment +import org.oppia.android.app.notice.ForcedAppDeprecationNoticeDialogFragment import org.oppia.android.app.notice.BetaNoticeDialogFragment import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeDialogFragment import org.oppia.android.app.onboarding.OnboardingActivity @@ -29,6 +32,8 @@ import org.oppia.android.util.data.DataProviders.Companion.combineWith import org.oppia.android.util.data.DataProviders.Companion.toLiveData import org.oppia.android.util.locale.OppiaLocale import javax.inject.Inject +import org.oppia.android.app.notice.OptionalAppDeprecationNoticeDialogFragment +import org.oppia.android.app.notice.OsDeprecationNoticeDialogFragment private const val AUTO_DEPRECATION_NOTICE_DIALOG_FRAGMENT_TAG = "auto_deprecation_notice_dialog" private const val BETA_NOTICE_DIALOG_FRAGMENT_TAG = "beta_notice_dialog" @@ -64,12 +69,48 @@ class SplashActivityPresenter @Inject constructor( subscribeToOnboardingFlow() } + /** */ fun handleOnCloseAppButtonClicked() { // If the app close button is clicked for the deprecation notice, finish the activity to close // the app. activity.finish() } + /** */ + fun handleOnUpdateButtonClicked() { + // If the Update button is clicked for the deprecation notice, launch the Play Store and open + // the Oppia app's page. + + // Launch profile selection activity in case the user presses the back button + activity.startActivity(ProfileChooserActivity.createProfileChooserActivity(activity)) + activity.finish() + + val packageName = activity.packageName + + try { + activity.startActivity( + Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName")) + ) + } catch (e: ActivityNotFoundException) { + activity.startActivity( + Intent( + Intent.ACTION_VIEW, + Uri.parse( + "https://play.google.com/store/apps/details?id=$packageName" + ) + ) + ) + } + } + + /** */ + fun handleOnDismissButtonClicked() { + // If the Dismiss button is clicked for the deprecation notice, the dialog is automatically + // dismissed. Navigate to profile chooser activity. + activity.startActivity(ProfileChooserActivity.createProfileChooserActivity(activity)) + activity.finish() + } + /** Handles cases when the user dismisses the beta notice dialog. */ fun handleOnBetaNoticeOkayButtonClicked(permanentlyDismiss: Boolean) { if (permanentlyDismiss) { @@ -171,7 +212,7 @@ class SplashActivityPresenter @Inject constructor( StartupMode.APP_IS_DEPRECATED -> { showDialog( AUTO_DEPRECATION_NOTICE_DIALOG_FRAGMENT_TAG, - AutomaticAppDeprecationNoticeDialogFragment::newInstance + ForcedAppDeprecationNoticeDialogFragment::newInstance ) } else -> { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cad5b0772ed..ea635244f62 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -500,14 +500,38 @@ Please select all correct choices. - Unsupported app version + App update required - This version of the app is no longer supported. Please update it through the Play Store. + A new version of Oppia is now available. The new version is more secure, and improves your learning experience.\n\nThis version is no longer supported. To continue using the app, please update to the latest version. Close app + + Update + + + New update available + + + A new version of Oppia is now available. We recommend that you update the app for bug fixes and a better learning experience. + + + Dismiss + + + Update + + + Update your Android OS + + + We recommend updating your Android OS to take advantage of Oppia\'s new features and lessons.\n\nVisit your phone\'s Settings app to update your OS. + + + Dismiss + Developer Build Alpha Beta From 61ea673c71de66ab24616824963c99b23212b5d9 Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Wed, 19 Jul 2023 18:29:40 +0300 Subject: [PATCH 02/13] fix: Fix linting issues --- .../org/oppia/android/app/fragment/FragmentComponentImpl.kt | 2 +- .../ForcedAppDeprecationNoticeDialogFragmentPresenter.kt | 2 +- .../app/notice/OptionalAppDeprecationNoticeDialogFragment.kt | 2 +- .../OptionalAppDeprecationNoticeDialogFragmentPresenter.kt | 2 +- .../android/app/notice/OsDeprecationNoticeDialogFragment.kt | 2 +- .../app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt | 2 +- .../org/oppia/android/app/splash/SplashActivityPresenter.kt | 4 +--- 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt b/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt index f18f50a0077..fbda0072bec 100644 --- a/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt +++ b/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt @@ -29,8 +29,8 @@ import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedFragment import org.oppia.android.app.mydownloads.DownloadsTabFragment import org.oppia.android.app.mydownloads.MyDownloadsFragment import org.oppia.android.app.mydownloads.UpdatesTabFragment -import org.oppia.android.app.notice.ForcedAppDeprecationNoticeDialogFragment import org.oppia.android.app.notice.BetaNoticeDialogFragment +import org.oppia.android.app.notice.ForcedAppDeprecationNoticeDialogFragment import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeDialogFragment import org.oppia.android.app.notice.OptionalAppDeprecationNoticeDialogFragment import org.oppia.android.app.notice.OsDeprecationNoticeDialogFragment diff --git a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt index f1b4a085bb0..ec8eacffeb2 100644 --- a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt @@ -4,8 +4,8 @@ import android.app.Dialog import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import org.oppia.android.R -import javax.inject.Inject import org.oppia.android.app.splash.DeprecationNoticeActionType +import javax.inject.Inject /** Presenter class responsible for showing an app deprecation dialog to the user. */ class ForcedAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( diff --git a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragment.kt b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragment.kt index ff7d1b0451c..29eb21fd005 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragment.kt @@ -27,4 +27,4 @@ class OptionalAppDeprecationNoticeDialogFragment : InjectableDialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return optionalAppDeprecationNoticeDialogFragmentPresenter.handleOnCreateDialog() } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt index 1376bb48c8b..c585e6d71a1 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt @@ -34,4 +34,4 @@ class OptionalAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( dialog.setCanceledOnTouchOutside(false) return dialog } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragment.kt b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragment.kt index a831bcad460..48e5fb59181 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragment.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragment.kt @@ -30,4 +30,4 @@ class OsDeprecationNoticeDialogFragment : InjectableDialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return osDeprecationNoticeDialogFragmentPresenter.handleOnCreateDialog() } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt index 5cab46ad02a..1b0b98d350c 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt @@ -29,4 +29,4 @@ class OsDeprecationNoticeDialogFragmentPresenter @Inject constructor( dialog.setCanceledOnTouchOutside(false) return dialog } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt index 9330d13ae43..94079dbe192 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt @@ -13,8 +13,8 @@ import org.oppia.android.app.model.AppStartupState import org.oppia.android.app.model.AppStartupState.BuildFlavorNoticeMode import org.oppia.android.app.model.AppStartupState.StartupMode import org.oppia.android.app.model.BuildFlavor -import org.oppia.android.app.notice.ForcedAppDeprecationNoticeDialogFragment import org.oppia.android.app.notice.BetaNoticeDialogFragment +import org.oppia.android.app.notice.ForcedAppDeprecationNoticeDialogFragment import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeDialogFragment import org.oppia.android.app.onboarding.OnboardingActivity import org.oppia.android.app.profile.ProfileChooserActivity @@ -32,8 +32,6 @@ import org.oppia.android.util.data.DataProviders.Companion.combineWith import org.oppia.android.util.data.DataProviders.Companion.toLiveData import org.oppia.android.util.locale.OppiaLocale import javax.inject.Inject -import org.oppia.android.app.notice.OptionalAppDeprecationNoticeDialogFragment -import org.oppia.android.app.notice.OsDeprecationNoticeDialogFragment private const val AUTO_DEPRECATION_NOTICE_DIALOG_FRAGMENT_TAG = "auto_deprecation_notice_dialog" private const val BETA_NOTICE_DIALOG_FRAGMENT_TAG = "beta_notice_dialog" From 9951c5a31a671bb24d8c31c318327d84701a202f Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Wed, 9 Aug 2023 02:27:28 +0300 Subject: [PATCH 03/13] fix: Fix testfile, Kdocs validation and string resource validation tests --- ...cedAppDeprecationNoticeDialogFragmentPresenter.kt | 12 ++++++++++-- ...nalAppDeprecationNoticeDialogFragmentPresenter.kt | 12 ++++++++++-- .../OsDeprecationNoticeDialogFragmentPresenter.kt | 12 ++++++++++-- .../org/oppia/android/app/splash/SplashActivity.kt | 4 ++++ .../android/app/splash/SplashActivityPresenter.kt | 2 ++ app/src/main/res/values-ar/strings.xml | 1 - app/src/main/res/values-pcm-rNG/strings.xml | 1 - app/src/main/res/values-pt-rBR/strings.xml | 1 - app/src/main/res/values-sw/strings.xml | 1 - app/src/main/res/values/strings.xml | 8 ++++---- scripts/assets/kdoc_validity_exemptions.textproto | 1 - 11 files changed, 40 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt index ec8eacffeb2..f5129d97f28 100644 --- a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt @@ -6,19 +6,27 @@ import androidx.appcompat.app.AppCompatActivity import org.oppia.android.R import org.oppia.android.app.splash.DeprecationNoticeActionType import javax.inject.Inject +import org.oppia.android.app.translation.AppLanguageResourceHandler /** Presenter class responsible for showing an app deprecation dialog to the user. */ class ForcedAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( - private val activity: AppCompatActivity + private val activity: AppCompatActivity, + private val resourceHandler: AppLanguageResourceHandler ) { private val deprecationNoticeExitAppListener by lazy { activity as DeprecationNoticeActionListener } + /** Handles dialog creation for the forced app deprecation notice. */ fun handleOnCreateDialog(): Dialog { + val appName = resourceHandler.getStringInLocale(R.string.app_name) + val dialog = AlertDialog.Builder(activity, R.style.DeprecationAlertDialogTheme) .setTitle(R.string.unsupported_app_version_dialog_title) - .setMessage(R.string.unsupported_app_version_dialog_message) + .setMessage(resourceHandler.getStringInLocaleWithWrapping( + R.string.unsupported_app_version_dialog_message, + appName + )) .setPositiveButton(R.string.unsupported_app_version_dialog_update_button_text) { _, _ -> deprecationNoticeExitAppListener.onPositiveActionButtonClicked( DeprecationNoticeActionType.UPDATE diff --git a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt index c585e6d71a1..e16f68ff6d1 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt @@ -6,19 +6,27 @@ import androidx.appcompat.app.AppCompatActivity import org.oppia.android.R import org.oppia.android.app.splash.DeprecationNoticeActionType import javax.inject.Inject +import org.oppia.android.app.translation.AppLanguageResourceHandler /** Presenter class responsible for showing an optional update dialog to the user. */ class OptionalAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( - private val activity: AppCompatActivity + private val activity: AppCompatActivity, + private val resourceHandler: AppLanguageResourceHandler ) { private val deprecationNoticeExitAppListener by lazy { activity as DeprecationNoticeActionListener } + /** Handles dialog creation for the optional app deprecation notice. */ fun handleOnCreateDialog(): Dialog { + val appName = resourceHandler.getStringInLocale(R.string.app_name) + val dialog = AlertDialog.Builder(activity, R.style.DeprecationAlertDialogTheme) .setTitle(R.string.optional_app_update_dialog_title) - .setMessage(R.string.optional_app_update_dialog_message) + .setMessage(resourceHandler.getStringInLocaleWithWrapping( + R.string.optional_app_update_dialog_message, + appName + )) .setPositiveButton(R.string.optional_app_update_dialog_update_button_text) { _, _ -> deprecationNoticeExitAppListener.onPositiveActionButtonClicked( DeprecationNoticeActionType.UPDATE diff --git a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt index 1b0b98d350c..ff3f94860be 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt @@ -6,19 +6,27 @@ import androidx.appcompat.app.AppCompatActivity import org.oppia.android.R import org.oppia.android.app.splash.DeprecationNoticeActionType import javax.inject.Inject +import org.oppia.android.app.translation.AppLanguageResourceHandler /** Presenter class responsible for showing an OS deprecation dialog to the user. */ class OsDeprecationNoticeDialogFragmentPresenter @Inject constructor( - private val activity: AppCompatActivity + private val activity: AppCompatActivity, + private val resourceHandler: AppLanguageResourceHandler ) { private val deprecationNoticeExitAppListener by lazy { activity as DeprecationNoticeActionListener } + /** Handles dialog creation for the OS deprecation notice. */ fun handleOnCreateDialog(): Dialog { + val appName = resourceHandler.getStringInLocale(R.string.app_name) + val dialog = AlertDialog.Builder(activity, R.style.DeprecationAlertDialogTheme) .setTitle(R.string.os_deprecation_dialog_title) - .setMessage(R.string.os_deprecation_dialog_message) + .setMessage(resourceHandler.getStringInLocaleWithWrapping( + R.string.os_deprecation_dialog_message, + appName + )) .setNegativeButton(R.string.os_deprecation_dialog_dismiss_button_text) { _, _ -> deprecationNoticeExitAppListener.onPositiveActionButtonClicked( DeprecationNoticeActionType.DISMISS diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt index 0186df174c0..c442691a2a8 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt @@ -16,9 +16,13 @@ import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeClosedListen import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName import javax.inject.Inject +/** Enum class for the various deprecation notice actions available to the user. */ enum class DeprecationNoticeActionType { + /** Action for when the user presses the 'Close' option on a deprecation dialog. */ CLOSE, + /** Action for when the user presses the 'Dismiss' option on a deprecation dialog. */ DISMISS, + /** Action for when the user presses the 'Update' option on a deprecation dialog. */ UPDATE } diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt index 94079dbe192..44d3b278d45 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt @@ -32,6 +32,8 @@ import org.oppia.android.util.data.DataProviders.Companion.combineWith import org.oppia.android.util.data.DataProviders.Companion.toLiveData import org.oppia.android.util.locale.OppiaLocale import javax.inject.Inject +import org.oppia.android.app.notice.OptionalAppDeprecationNoticeDialogFragment +import org.oppia.android.app.notice.OsDeprecationNoticeDialogFragment private const val AUTO_DEPRECATION_NOTICE_DIALOG_FRAGMENT_TAG = "auto_deprecation_notice_dialog" private const val BETA_NOTICE_DIALOG_FRAGMENT_TAG = "beta_notice_dialog" diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 938f0dbc081..6bc4d2f5467 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -473,7 +473,6 @@ ongoing_recycler_view_tag برجاء اختيار خيار واحد على الأقل. إصدار تطبيق غير مدعوم - هذا الإصدار من التطبيق لم يعد مدعومًا. من فضلك قم بتحديث التطبيق من خلال متجر بلاي (Play Store) إغلاق التطبيق بناء المطور ألفا diff --git a/app/src/main/res/values-pcm-rNG/strings.xml b/app/src/main/res/values-pcm-rNG/strings.xml index 616d6e03f76..175bb2b82cd 100644 --- a/app/src/main/res/values-pcm-rNG/strings.xml +++ b/app/src/main/res/values-pcm-rNG/strings.xml @@ -435,7 +435,6 @@ ongoing_recycler_view_tag Abeg select all di correct choices. Unsupported app version - Dis version of di app no longer dey supported. Abeg update am from di Play Store. Close app Developer Build Alpha diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 9cb7c841127..81e310f413f 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -419,7 +419,6 @@ ongoing_recycler_view_tag Por favor, selecione todas as alternativas corretas. Versão do aplicativo não suportada - Esta versão do aplicativo não é mais suportada. Atualize-a na Play Store. Fechar aplicativo Versão do desenvolvedor Alfa diff --git a/app/src/main/res/values-sw/strings.xml b/app/src/main/res/values-sw/strings.xml index 1cf7fc4433c..78aef9545ae 100644 --- a/app/src/main/res/values-sw/strings.xml +++ b/app/src/main/res/values-sw/strings.xml @@ -392,7 +392,6 @@ Inaendelea_kuchakata tena_mtazamo_tag Tafadhali chagua angalau chaguo moja. Toleo la programu lisilotumika - Toleo hili la programu halitumiki tena. Tafadhali isasishe kupitia hifadhi ya michezo. Funga programu kwa Weka uwiano katika fomu x:y. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b1ca5320200..9c0d0771a9b 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -502,8 +502,8 @@ App update required - - A new version of Oppia is now available. The new version is more secure, and improves your learning experience.\n\nThis version is no longer supported. To continue using the app, please update to the latest version. + + A new version of %s is now available. The new version is more secure, and improves your learning experience.\n\nThis version is no longer supported. To continue using the app, please update to the latest version. Close app @@ -515,7 +515,7 @@ New update available - A new version of Oppia is now available. We recommend that you update the app for bug fixes and a better learning experience. + A new version of %s is now available. We recommend that you update the app for bug fixes and a better learning experience. Dismiss @@ -527,7 +527,7 @@ Update your Android OS - We recommend updating your Android OS to take advantage of Oppia\'s new features and lessons.\n\nVisit your phone\'s Settings app to update your OS. + We recommend updating your Android OS to take advantage of %s\'s new features and lessons.\n\nVisit your phone\'s Settings app to update your OS. Dismiss diff --git a/scripts/assets/kdoc_validity_exemptions.textproto b/scripts/assets/kdoc_validity_exemptions.textproto index 94f9f14c159..a3aa150b3ef 100644 --- a/scripts/assets/kdoc_validity_exemptions.textproto +++ b/scripts/assets/kdoc_validity_exemptions.textproto @@ -4,7 +4,6 @@ exempted_file_path: "app/src/main/java/org/oppia/android/app/application/Applica exempted_file_path: "app/src/main/java/org/oppia/android/app/application/ApplicationStartupListenerModule.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/administratorcontrols/RouteToProfileListListener.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/SurveyOnboardingBackgroundView.kt" -exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragmentPresenter.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsActivityPresenter.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsFragment.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsFragmentPresenter.kt" From 200d78161c34560fcef1c5a01e94c7a5d00db11a Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Tue, 15 Aug 2023 22:19:50 +0300 Subject: [PATCH 04/13] feat: Add test config for the three deprecation dialogs --- app/src/main/AndroidManifest.xml | 12 + .../app/activity/ActivityComponentImpl.kt | 1 + ...orcedAppDeprecationNoticeDialogFragment.kt | 5 +- ...eprecationNoticeDialogFragmentPresenter.kt | 12 +- ...eprecationNoticeDialogFragmentPresenter.kt | 12 +- ...eprecationNoticeDialogFragmentPresenter.kt | 12 +- .../android/app/notice/testing/BUILD.bazel | 39 +++ ...ecationNoticeDialogFragmentTestActivity.kt | 34 +++ ...ecationNoticeDialogFragmentTestActivity.kt | 33 +++ ...ecationNoticeDialogFragmentTestActivity.kt | 33 +++ .../app/splash/SplashActivityPresenter.kt | 2 - .../org/oppia/android/app/notice/BUILD.bazel | 111 +++++++++ ...dAppDeprecationNoticeDialogFragmentTest.kt | 227 ++++++++++++++++++ ...lAppDeprecationNoticeDialogFragmentTest.kt | 218 +++++++++++++++++ .../OsDeprecationNoticeDialogFragmentTest.kt | 221 +++++++++++++++++ 15 files changed, 952 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt create mode 100644 app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt create mode 100644 app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt create mode 100644 app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt create mode 100644 app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt create mode 100644 app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a27551a2005..7bfec1dc98d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -92,6 +92,18 @@ android:name=".app.notice.testing.GeneralAvailabilityUpgradeNoticeDialogFragmentTestActivity" android:label="@string/test_activity_label" android:theme="@style/OppiaThemeWithoutActionBar" /> + + + deprecationNoticeExitAppListener.onPositiveActionButtonClicked( DeprecationNoticeActionType.UPDATE diff --git a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt index e16f68ff6d1..57fca4f9e5a 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt @@ -5,8 +5,8 @@ import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import org.oppia.android.R import org.oppia.android.app.splash.DeprecationNoticeActionType -import javax.inject.Inject import org.oppia.android.app.translation.AppLanguageResourceHandler +import javax.inject.Inject /** Presenter class responsible for showing an optional update dialog to the user. */ class OptionalAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( @@ -23,10 +23,12 @@ class OptionalAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( val dialog = AlertDialog.Builder(activity, R.style.DeprecationAlertDialogTheme) .setTitle(R.string.optional_app_update_dialog_title) - .setMessage(resourceHandler.getStringInLocaleWithWrapping( - R.string.optional_app_update_dialog_message, - appName - )) + .setMessage( + resourceHandler.getStringInLocaleWithWrapping( + R.string.optional_app_update_dialog_message, + appName + ) + ) .setPositiveButton(R.string.optional_app_update_dialog_update_button_text) { _, _ -> deprecationNoticeExitAppListener.onPositiveActionButtonClicked( DeprecationNoticeActionType.UPDATE diff --git a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt index ff3f94860be..e69d5b08dcc 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt @@ -5,8 +5,8 @@ import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import org.oppia.android.R import org.oppia.android.app.splash.DeprecationNoticeActionType -import javax.inject.Inject import org.oppia.android.app.translation.AppLanguageResourceHandler +import javax.inject.Inject /** Presenter class responsible for showing an OS deprecation dialog to the user. */ class OsDeprecationNoticeDialogFragmentPresenter @Inject constructor( @@ -23,10 +23,12 @@ class OsDeprecationNoticeDialogFragmentPresenter @Inject constructor( val dialog = AlertDialog.Builder(activity, R.style.DeprecationAlertDialogTheme) .setTitle(R.string.os_deprecation_dialog_title) - .setMessage(resourceHandler.getStringInLocaleWithWrapping( - R.string.os_deprecation_dialog_message, - appName - )) + .setMessage( + resourceHandler.getStringInLocaleWithWrapping( + R.string.os_deprecation_dialog_message, + appName + ) + ) .setNegativeButton(R.string.os_deprecation_dialog_dismiss_button_text) { _, _ -> deprecationNoticeExitAppListener.onPositiveActionButtonClicked( DeprecationNoticeActionType.DISMISS diff --git a/app/src/main/java/org/oppia/android/app/notice/testing/BUILD.bazel b/app/src/main/java/org/oppia/android/app/notice/testing/BUILD.bazel index 92f1a0ae62b..da1da0d1d2b 100644 --- a/app/src/main/java/org/oppia/android/app/notice/testing/BUILD.bazel +++ b/app/src/main/java/org/oppia/android/app/notice/testing/BUILD.bazel @@ -31,4 +31,43 @@ kt_android_library( ], ) +kt_android_library( + name = "forced_app_deprecation_notice_dialog_fragment_test_activity", + testonly = True, + srcs = [ + "ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt" + ], + visibility = ["//app:app_testing_visibility"], + deps = [ + "//app", + "//app/src/main/java/org/oppia/android/app/testing/activity:test_activity", + ], +) + +kt_android_library( + name = "optional_app_deprecation_notice_dialog_fragment_test_activity", + testonly = True, + srcs = [ + "OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt" + ], + visibility = ["//app:app_testing_visibility"], + deps = [ + "//app", + "//app/src/main/java/org/oppia/android/app/testing/activity:test_activity", + ], +) + +kt_android_library( + name = "os_deprecation_notice_dialog_fragment_test_activity", + testonly = True, + srcs = [ + "OsDeprecationNoticeDialogFragmentTestActivity.kt" + ], + visibility = ["//app:app_testing_visibility"], + deps = [ + "//app", + "//app/src/main/java/org/oppia/android/app/testing/activity:test_activity", + ], +) + dagger_rules() diff --git a/app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt new file mode 100644 index 00000000000..809682234e9 --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt @@ -0,0 +1,34 @@ +package org.oppia.android.app.notice.testing + +import android.os.Bundle +import org.oppia.android.app.notice.DeprecationNoticeActionListener +import org.oppia.android.app.notice.ForcedAppDeprecationNoticeDialogFragment +import org.oppia.android.app.splash.DeprecationNoticeActionType +import org.oppia.android.app.testing.activity.TestActivity + +/** [TestActivity] for setting up a test environment for testing the beta notice dialog. */ +class ForcedAppDeprecationNoticeDialogFragmentTestActivity: TestActivity(), + DeprecationNoticeActionListener { + /** + * [DeprecationNoticeActionListener] that must be initialized by the test, and is presumed to be a + * Mockito mock (though this is not, strictly speaking, required). + * + * This listener will be used as the callback for the dialog in response to UI operations. + */ + lateinit var mockCallbackListener: DeprecationNoticeActionListener + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + ForcedAppDeprecationNoticeDialogFragment.newInstance() + .showNow(supportFragmentManager, "forced_app_deprecation_dialog") + } + + override fun onPositiveActionButtonClicked(noticeType: DeprecationNoticeActionType) { + mockCallbackListener.onPositiveActionButtonClicked(noticeType) + } + + override fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) { + mockCallbackListener.onNegativeActionButtonClicked(noticeType) + } + +} \ No newline at end of file diff --git a/app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt new file mode 100644 index 00000000000..9b8537ed8bd --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt @@ -0,0 +1,33 @@ +package org.oppia.android.app.notice.testing + +import android.os.Bundle +import org.oppia.android.app.notice.DeprecationNoticeActionListener +import org.oppia.android.app.notice.OptionalAppDeprecationNoticeDialogFragment +import org.oppia.android.app.splash.DeprecationNoticeActionType +import org.oppia.android.app.testing.activity.TestActivity + +/** [TestActivity] for setting up a test environment for testing the beta notice dialog. */ +class OptionalAppDeprecationNoticeDialogFragmentTestActivity: TestActivity(), + DeprecationNoticeActionListener { + /** + * [DeprecationNoticeActionListener] that must be initialized by the test, and is presumed to be a + * Mockito mock (though this is not, strictly speaking, required). + * + * This listener will be used as the callback for the dialog in response to UI operations. + */ + lateinit var mockCallbackListener: DeprecationNoticeActionListener + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + OptionalAppDeprecationNoticeDialogFragment.newInstance() + .showNow(supportFragmentManager, "optional_app_deprecation_dialog") + } + + override fun onPositiveActionButtonClicked(noticeType: DeprecationNoticeActionType) { + mockCallbackListener.onPositiveActionButtonClicked(noticeType) + } + + override fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) { + mockCallbackListener.onNegativeActionButtonClicked(noticeType) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt new file mode 100644 index 00000000000..4a61079ef2e --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt @@ -0,0 +1,33 @@ +package org.oppia.android.app.notice.testing + +import android.os.Bundle +import org.oppia.android.app.notice.DeprecationNoticeActionListener +import org.oppia.android.app.notice.OsDeprecationNoticeDialogFragment +import org.oppia.android.app.splash.DeprecationNoticeActionType +import org.oppia.android.app.testing.activity.TestActivity + +/** [TestActivity] for setting up a test environment for testing the beta notice dialog. */ +class OsDeprecationNoticeDialogFragmentTestActivity: TestActivity(), + DeprecationNoticeActionListener { + /** + * [DeprecationNoticeActionListener] that must be initialized by the test, and is presumed to be a + * Mockito mock (though this is not, strictly speaking, required). + * + * This listener will be used as the callback for the dialog in response to UI operations. + */ + lateinit var mockCallbackListener: DeprecationNoticeActionListener + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + OsDeprecationNoticeDialogFragment.newInstance() + .showNow(supportFragmentManager, "os_deprecation_dialog") + } + + override fun onPositiveActionButtonClicked(noticeType: DeprecationNoticeActionType) { + mockCallbackListener.onPositiveActionButtonClicked(noticeType) + } + + override fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) { + mockCallbackListener.onNegativeActionButtonClicked(noticeType) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt index 44d3b278d45..94079dbe192 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt @@ -32,8 +32,6 @@ import org.oppia.android.util.data.DataProviders.Companion.combineWith import org.oppia.android.util.data.DataProviders.Companion.toLiveData import org.oppia.android.util.locale.OppiaLocale import javax.inject.Inject -import org.oppia.android.app.notice.OptionalAppDeprecationNoticeDialogFragment -import org.oppia.android.app.notice.OsDeprecationNoticeDialogFragment private const val AUTO_DEPRECATION_NOTICE_DIALOG_FRAGMENT_TAG = "auto_deprecation_notice_dialog" private const val BETA_NOTICE_DIALOG_FRAGMENT_TAG = "beta_notice_dialog" diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/BUILD.bazel b/app/src/sharedTest/java/org/oppia/android/app/notice/BUILD.bazel index 20d4828910e..dbde970cc29 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/BUILD.bazel +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/BUILD.bazel @@ -80,4 +80,115 @@ app_test( ], ) +app_test( + name = "ForcedAppDeprecationNoticeDialogFragmentTest", + processed_src = test_with_resources("ForcedAppDeprecationNoticeDialogFragmentTest.kt"), + test_class = "org.oppia.android.app.notice.ForcedAppDeprecationNoticeDialogFragmentTest", + deps = [ + ":dagger", + "//app", + "//app/src/main/java/org/oppia/android/app/application:application_component", + "//app/src/main/java/org/oppia/android/app/application:application_injector", + "//app/src/main/java/org/oppia/android/app/application:application_injector_provider", + "//app/src/main/java/org/oppia/android/app/application:common_application_modules", + "//app/src/main/java/org/oppia/android/app/application/testing:testing_build_flavor_module", + "//app/src/main/java/org/oppia/android/app/notice/testing:forced_app_deprecation_notice_dialog_fragment_test_activity", + "//app/src/main/java/org/oppia/android/app/translation/testing:test_module", + "//data/src/main/java/org/oppia/android/data/backends/gae:prod_module", + "//domain/src/main/java/org/oppia/android/domain/onboarding/testing:retriever_test_module", + "//testing", + "//testing/src/main/java/org/oppia/android/testing/junit:initialize_default_locale_rule", + "//testing/src/main/java/org/oppia/android/testing/robolectric:test_module", + "//testing/src/main/java/org/oppia/android/testing/threading:test_module", + "//testing/src/main/java/org/oppia/android/testing/time:test_module", + "//third_party:androidx_test_espresso_espresso-core", + "//third_party:androidx_test_ext_junit", + "//third_party:org_robolectric_robolectric", + "//third_party:robolectric_android-all", + "//utility/src/main/java/org/oppia/android/util/accessibility:test_module", + "//utility/src/main/java/org/oppia/android/util/caching:asset_prod_module", + "//utility/src/main/java/org/oppia/android/util/caching/testing:caching_test_module", + "//utility/src/main/java/org/oppia/android/util/locale/testing:test_module", + "//utility/src/main/java/org/oppia/android/util/logging:prod_module", + "//utility/src/main/java/org/oppia/android/util/logging:standard_event_logging_configuration_module", + "//utility/src/main/java/org/oppia/android/util/logging/firebase:debug_module", + "//utility/src/main/java/org/oppia/android/util/networking:debug_module", + "//utility/src/main/java/org/oppia/android/util/networking:debug_util_module", + ], +) + +app_test( + name = "OptionalAppDeprecationNoticeDialogFragmentTest", + processed_src = test_with_resources("OptionalAppDeprecationNoticeDialogFragmentTest.kt"), + test_class = "org.oppia.android.app.notice.OptionalAppDeprecationNoticeDialogFragmentTest", + deps = [ + ":dagger", + "//app", + "//app/src/main/java/org/oppia/android/app/application:application_component", + "//app/src/main/java/org/oppia/android/app/application:application_injector", + "//app/src/main/java/org/oppia/android/app/application:application_injector_provider", + "//app/src/main/java/org/oppia/android/app/application:common_application_modules", + "//app/src/main/java/org/oppia/android/app/application/testing:testing_build_flavor_module", + "//app/src/main/java/org/oppia/android/app/notice/testing:optional_app_deprecation_notice_dialog_fragment_test_activity", + "//app/src/main/java/org/oppia/android/app/translation/testing:test_module", + "//data/src/main/java/org/oppia/android/data/backends/gae:prod_module", + "//domain/src/main/java/org/oppia/android/domain/onboarding/testing:retriever_test_module", + "//testing", + "//testing/src/main/java/org/oppia/android/testing/junit:initialize_default_locale_rule", + "//testing/src/main/java/org/oppia/android/testing/robolectric:test_module", + "//testing/src/main/java/org/oppia/android/testing/threading:test_module", + "//testing/src/main/java/org/oppia/android/testing/time:test_module", + "//third_party:androidx_test_espresso_espresso-core", + "//third_party:androidx_test_ext_junit", + "//third_party:org_robolectric_robolectric", + "//third_party:robolectric_android-all", + "//utility/src/main/java/org/oppia/android/util/accessibility:test_module", + "//utility/src/main/java/org/oppia/android/util/caching:asset_prod_module", + "//utility/src/main/java/org/oppia/android/util/caching/testing:caching_test_module", + "//utility/src/main/java/org/oppia/android/util/locale/testing:test_module", + "//utility/src/main/java/org/oppia/android/util/logging:prod_module", + "//utility/src/main/java/org/oppia/android/util/logging:standard_event_logging_configuration_module", + "//utility/src/main/java/org/oppia/android/util/logging/firebase:debug_module", + "//utility/src/main/java/org/oppia/android/util/networking:debug_module", + "//utility/src/main/java/org/oppia/android/util/networking:debug_util_module", + ], +) + +app_test( + name = "OsDeprecationNoticeDialogFragmentTest", + processed_src = test_with_resources("OsDeprecationNoticeDialogFragmentTest.kt"), + test_class = "org.oppia.android.app.notice.OsDeprecationNoticeDialogFragmentTest", + deps = [ + ":dagger", + "//app", + "//app/src/main/java/org/oppia/android/app/application:application_component", + "//app/src/main/java/org/oppia/android/app/application:application_injector", + "//app/src/main/java/org/oppia/android/app/application:application_injector_provider", + "//app/src/main/java/org/oppia/android/app/application:common_application_modules", + "//app/src/main/java/org/oppia/android/app/application/testing:testing_build_flavor_module", + "//app/src/main/java/org/oppia/android/app/notice/testing:os_deprecation_notice_dialog_fragment_test_activity", + "//app/src/main/java/org/oppia/android/app/translation/testing:test_module", + "//data/src/main/java/org/oppia/android/data/backends/gae:prod_module", + "//domain/src/main/java/org/oppia/android/domain/onboarding/testing:retriever_test_module", + "//testing", + "//testing/src/main/java/org/oppia/android/testing/junit:initialize_default_locale_rule", + "//testing/src/main/java/org/oppia/android/testing/robolectric:test_module", + "//testing/src/main/java/org/oppia/android/testing/threading:test_module", + "//testing/src/main/java/org/oppia/android/testing/time:test_module", + "//third_party:androidx_test_espresso_espresso-core", + "//third_party:androidx_test_ext_junit", + "//third_party:org_robolectric_robolectric", + "//third_party:robolectric_android-all", + "//utility/src/main/java/org/oppia/android/util/accessibility:test_module", + "//utility/src/main/java/org/oppia/android/util/caching:asset_prod_module", + "//utility/src/main/java/org/oppia/android/util/caching/testing:caching_test_module", + "//utility/src/main/java/org/oppia/android/util/locale/testing:test_module", + "//utility/src/main/java/org/oppia/android/util/logging:prod_module", + "//utility/src/main/java/org/oppia/android/util/logging:standard_event_logging_configuration_module", + "//utility/src/main/java/org/oppia/android/util/logging/firebase:debug_module", + "//utility/src/main/java/org/oppia/android/util/networking:debug_module", + "//utility/src/main/java/org/oppia/android/util/networking:debug_util_module", + ], +) + dagger_rules() diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt new file mode 100644 index 00000000000..8078160fcce --- /dev/null +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt @@ -0,0 +1,227 @@ +package org.oppia.android.app.notice + +import android.app.Application +import android.view.View +import androidx.appcompat.app.AppCompatActivity +import androidx.test.core.app.ActivityScenario +import androidx.test.core.app.ApplicationProvider +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.matcher.RootMatchers.isDialog +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.ext.junit.runners.AndroidJUnit4 +import dagger.BindsInstance +import dagger.Component +import javax.inject.Inject +import javax.inject.Singleton +import org.hamcrest.Matcher +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.junit.MockitoJUnit +import org.mockito.junit.MockitoRule +import org.oppia.android.R +import org.oppia.android.app.activity.ActivityComponent +import org.oppia.android.app.activity.ActivityComponentFactory +import org.oppia.android.app.activity.route.ActivityRouterModule +import org.oppia.android.app.application.ApplicationComponent +import org.oppia.android.app.application.ApplicationInjector +import org.oppia.android.app.application.ApplicationInjectorProvider +import org.oppia.android.app.application.ApplicationModule +import org.oppia.android.app.application.ApplicationStartupListenerModule +import org.oppia.android.app.application.testing.TestingBuildFlavorModule +import org.oppia.android.app.devoptions.DeveloperOptionsModule +import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule +import org.oppia.android.app.notice.testing.ForcedAppDeprecationNoticeDialogFragmentTestActivity +import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule +import org.oppia.android.app.shim.ViewBindingShimModule +import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule +import org.oppia.android.data.backends.gae.NetworkConfigProdModule +import org.oppia.android.data.backends.gae.NetworkModule +import org.oppia.android.domain.classify.InteractionsModule +import org.oppia.android.domain.classify.rules.algebraicexpressioninput.AlgebraicExpressionInputModule +import org.oppia.android.domain.classify.rules.continueinteraction.ContinueModule +import org.oppia.android.domain.classify.rules.dragAndDropSortInput.DragDropSortInputModule +import org.oppia.android.domain.classify.rules.fractioninput.FractionInputModule +import org.oppia.android.domain.classify.rules.imageClickInput.ImageClickInputModule +import org.oppia.android.domain.classify.rules.itemselectioninput.ItemSelectionInputModule +import org.oppia.android.domain.classify.rules.mathequationinput.MathEquationInputModule +import org.oppia.android.domain.classify.rules.multiplechoiceinput.MultipleChoiceInputModule +import org.oppia.android.domain.classify.rules.numberwithunits.NumberWithUnitsRuleModule +import org.oppia.android.domain.classify.rules.numericexpressioninput.NumericExpressionInputModule +import org.oppia.android.domain.classify.rules.numericinput.NumericInputRuleModule +import org.oppia.android.domain.classify.rules.ratioinput.RatioInputModule +import org.oppia.android.domain.classify.rules.textinput.TextInputRuleModule +import org.oppia.android.domain.exploration.ExplorationProgressModule +import org.oppia.android.domain.exploration.ExplorationStorageModule +import org.oppia.android.domain.hintsandsolution.HintsAndSolutionConfigFastShowTestModule +import org.oppia.android.domain.hintsandsolution.HintsAndSolutionProdModule +import org.oppia.android.domain.onboarding.ExpirationMetaDataRetrieverModule +import org.oppia.android.domain.oppialogger.LogStorageModule +import org.oppia.android.domain.oppialogger.LoggingIdentifierModule +import org.oppia.android.domain.oppialogger.analytics.ApplicationLifecycleModule +import org.oppia.android.domain.oppialogger.analytics.CpuPerformanceSnapshotterModule +import org.oppia.android.domain.oppialogger.logscheduler.MetricLogSchedulerModule +import org.oppia.android.domain.oppialogger.loguploader.LogReportWorkerModule +import org.oppia.android.domain.platformparameter.PlatformParameterModule +import org.oppia.android.domain.platformparameter.PlatformParameterSingletonModule +import org.oppia.android.domain.question.QuestionModule +import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule +import org.oppia.android.domain.workmanager.WorkManagerConfigurationModule +import org.oppia.android.testing.OppiaTestRule +import org.oppia.android.testing.TestImageLoaderModule +import org.oppia.android.testing.TestLogReportingModule +import org.oppia.android.testing.junit.InitializeDefaultLocaleRule +import org.oppia.android.testing.robolectric.RobolectricModule +import org.oppia.android.testing.threading.TestCoroutineDispatchers +import org.oppia.android.testing.threading.TestDispatcherModule +import org.oppia.android.testing.time.FakeOppiaClockModule +import org.oppia.android.util.accessibility.AccessibilityTestModule +import org.oppia.android.util.caching.AssetModule +import org.oppia.android.util.caching.testing.CachingTestModule +import org.oppia.android.util.gcsresource.GcsResourceModule +import org.oppia.android.util.locale.LocaleProdModule +import org.oppia.android.util.logging.EventLoggingConfigurationModule +import org.oppia.android.util.logging.LoggerModule +import org.oppia.android.util.logging.SyncStatusModule +import org.oppia.android.util.logging.firebase.FirebaseLogUploaderModule +import org.oppia.android.util.networking.NetworkConnectionDebugUtilModule +import org.oppia.android.util.networking.NetworkConnectionUtilDebugModule +import org.oppia.android.util.parser.html.HtmlParserEntityTypeModule +import org.oppia.android.util.parser.image.ImageParsingModule +import org.robolectric.annotation.Config +import org.robolectric.annotation.LooperMode + +/** Tests for [ForcedAppDeprecationNoticeDialogFragment]. */ +// FunctionName: test names are conventionally named with underscores. +@Suppress("FunctionName") +@RunWith(AndroidJUnit4::class) +@Config( + application = ForcedAppDeprecationNoticeDialogFragmentTest.TestApplication::class, + qualifiers = "port-xxhdpi" +) +@LooperMode(LooperMode.Mode.PAUSED) +class ForcedAppDeprecationNoticeDialogFragmentTest { + @get:Rule + val initializeDefaultLocaleRule = InitializeDefaultLocaleRule() + + @get:Rule + val oppiaTestRule = OppiaTestRule() + + @field:[Rule JvmField] val mockitoRule: MockitoRule = MockitoJUnit.rule() + + @Inject + lateinit var testCoroutineDispatchers: TestCoroutineDispatchers + + @Mock + lateinit var mockDeprecationNoticeActionListener: DeprecationNoticeActionListener + + @Before + fun setUp() { + setUpTestApplicationComponent() + } + + @Test + fun dummyTest() { + launchForcedAppDeprecationNoticeDialogFragmentTestActivity { + assert(true).equals(true) + } + } + + @Test + fun testFragment_hasExpectedTitle() { + launchForcedAppDeprecationNoticeDialogFragmentTestActivity { + onDialogView(ViewMatchers.withText(R.string.unsupported_app_version_dialog_title)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + } + + private fun launchForcedAppDeprecationNoticeDialogFragmentTestActivity( + testBlock: () -> Unit + ) { + // Launch the test activity, but make sure that it's properly set up & time is given for it to + // initialize. + ActivityScenario.launch( + ForcedAppDeprecationNoticeDialogFragmentTestActivity::class.java + ).use { scenario -> + scenario.onActivity { it.mockCallbackListener = mockDeprecationNoticeActionListener } + testCoroutineDispatchers.runCurrent() + testBlock() + } + } + + private fun clickOnDialogView(matcher: Matcher) { + onDialogView(matcher).perform(ViewActions.click()) + testCoroutineDispatchers.runCurrent() + } + + private fun setUpTestApplicationComponent() { + ApplicationProvider.getApplicationContext().inject(this) + } + + private companion object { + private fun onDialogView(matcher: Matcher) = onView(matcher).inRoot(isDialog()) + } + + @Singleton + @Component( + modules = [ + RobolectricModule::class, PlatformParameterModule::class, + TestDispatcherModule::class, ApplicationModule::class, LoggerModule::class, + ContinueModule::class, FractionInputModule::class, ItemSelectionInputModule::class, + MultipleChoiceInputModule::class, NumberWithUnitsRuleModule::class, + NumericInputRuleModule::class, TextInputRuleModule::class, DragDropSortInputModule::class, + ImageClickInputModule::class, InteractionsModule::class, GcsResourceModule::class, + TestImageLoaderModule::class, ImageParsingModule::class, HtmlParserEntityTypeModule::class, + QuestionModule::class, TestLogReportingModule::class, AccessibilityTestModule::class, + LogStorageModule::class, PrimeTopicAssetsControllerModule::class, + ExpirationMetaDataRetrieverModule::class, ViewBindingShimModule::class, + RatioInputModule::class, ApplicationStartupListenerModule::class, + HintsAndSolutionConfigFastShowTestModule::class, HintsAndSolutionProdModule::class, + WorkManagerConfigurationModule::class, LogReportWorkerModule::class, + FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, + DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class, + ExplorationStorageModule::class, NetworkConnectionUtilDebugModule::class, + NetworkConnectionDebugUtilModule::class, NetworkModule::class, NetworkConfigProdModule::class, + AssetModule::class, LocaleProdModule::class, ActivityRecreatorTestModule::class, + PlatformParameterSingletonModule::class, NumericExpressionInputModule::class, + AlgebraicExpressionInputModule::class, MathEquationInputModule::class, + SplitScreenInteractionModule::class, LoggingIdentifierModule::class, + ApplicationLifecycleModule::class, SyncStatusModule::class, TestingBuildFlavorModule::class, + CachingTestModule::class, MetricLogSchedulerModule::class, + EventLoggingConfigurationModule::class, ActivityRouterModule::class, + CpuPerformanceSnapshotterModule::class, ExplorationProgressModule::class + ] + ) + + interface TestApplicationComponent : ApplicationComponent { + @Component.Builder + interface Builder { + @BindsInstance + fun setApplication(application: Application): Builder + + fun build(): TestApplicationComponent + } + + fun inject(test: ForcedAppDeprecationNoticeDialogFragmentTest) + } + + class TestApplication : Application(), ActivityComponentFactory, ApplicationInjectorProvider { + private val component: TestApplicationComponent by lazy { + DaggerForcedAppDeprecationNoticeDialogFragmentTest_TestApplicationComponent.builder() + .setApplication(this) + .build() + } + + fun inject(test: ForcedAppDeprecationNoticeDialogFragmentTest) = component.inject(test) + + override fun createActivityComponent(activity: AppCompatActivity): ActivityComponent { + return component.getActivityComponentBuilderProvider().get().setActivity(activity).build() + } + + override fun getApplicationInjector(): ApplicationInjector = component + } +} \ No newline at end of file diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt new file mode 100644 index 00000000000..7a250ad2881 --- /dev/null +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt @@ -0,0 +1,218 @@ +package org.oppia.android.app.notice + +import android.app.Application +import android.view.View +import androidx.appcompat.app.AppCompatActivity +import androidx.test.core.app.ActivityScenario +import androidx.test.core.app.ApplicationProvider +import androidx.test.espresso.Espresso +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.matcher.RootMatchers +import androidx.test.ext.junit.runners.AndroidJUnit4 +import dagger.BindsInstance +import dagger.Component +import javax.inject.Inject +import javax.inject.Singleton +import org.hamcrest.Matcher +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.junit.MockitoJUnit +import org.mockito.junit.MockitoRule +import org.oppia.android.app.activity.ActivityComponent +import org.oppia.android.app.activity.ActivityComponentFactory +import org.oppia.android.app.activity.route.ActivityRouterModule +import org.oppia.android.app.application.ApplicationComponent +import org.oppia.android.app.application.ApplicationInjector +import org.oppia.android.app.application.ApplicationInjectorProvider +import org.oppia.android.app.application.ApplicationModule +import org.oppia.android.app.application.ApplicationStartupListenerModule +import org.oppia.android.app.application.testing.TestingBuildFlavorModule +import org.oppia.android.app.devoptions.DeveloperOptionsModule +import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule +import org.oppia.android.app.notice.testing.ForcedAppDeprecationNoticeDialogFragmentTestActivity +import org.oppia.android.app.notice.testing.OptionalAppDeprecationNoticeDialogFragmentTestActivity +import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule +import org.oppia.android.app.shim.ViewBindingShimModule +import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule +import org.oppia.android.data.backends.gae.NetworkConfigProdModule +import org.oppia.android.data.backends.gae.NetworkModule +import org.oppia.android.domain.classify.InteractionsModule +import org.oppia.android.domain.classify.rules.algebraicexpressioninput.AlgebraicExpressionInputModule +import org.oppia.android.domain.classify.rules.continueinteraction.ContinueModule +import org.oppia.android.domain.classify.rules.dragAndDropSortInput.DragDropSortInputModule +import org.oppia.android.domain.classify.rules.fractioninput.FractionInputModule +import org.oppia.android.domain.classify.rules.imageClickInput.ImageClickInputModule +import org.oppia.android.domain.classify.rules.itemselectioninput.ItemSelectionInputModule +import org.oppia.android.domain.classify.rules.mathequationinput.MathEquationInputModule +import org.oppia.android.domain.classify.rules.multiplechoiceinput.MultipleChoiceInputModule +import org.oppia.android.domain.classify.rules.numberwithunits.NumberWithUnitsRuleModule +import org.oppia.android.domain.classify.rules.numericexpressioninput.NumericExpressionInputModule +import org.oppia.android.domain.classify.rules.numericinput.NumericInputRuleModule +import org.oppia.android.domain.classify.rules.ratioinput.RatioInputModule +import org.oppia.android.domain.classify.rules.textinput.TextInputRuleModule +import org.oppia.android.domain.exploration.ExplorationProgressModule +import org.oppia.android.domain.exploration.ExplorationStorageModule +import org.oppia.android.domain.hintsandsolution.HintsAndSolutionConfigFastShowTestModule +import org.oppia.android.domain.hintsandsolution.HintsAndSolutionProdModule +import org.oppia.android.domain.onboarding.ExpirationMetaDataRetrieverModule +import org.oppia.android.domain.oppialogger.LogStorageModule +import org.oppia.android.domain.oppialogger.LoggingIdentifierModule +import org.oppia.android.domain.oppialogger.analytics.ApplicationLifecycleModule +import org.oppia.android.domain.oppialogger.analytics.CpuPerformanceSnapshotterModule +import org.oppia.android.domain.oppialogger.logscheduler.MetricLogSchedulerModule +import org.oppia.android.domain.oppialogger.loguploader.LogReportWorkerModule +import org.oppia.android.domain.platformparameter.PlatformParameterModule +import org.oppia.android.domain.platformparameter.PlatformParameterSingletonModule +import org.oppia.android.domain.question.QuestionModule +import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule +import org.oppia.android.domain.workmanager.WorkManagerConfigurationModule +import org.oppia.android.testing.OppiaTestRule +import org.oppia.android.testing.TestImageLoaderModule +import org.oppia.android.testing.TestLogReportingModule +import org.oppia.android.testing.junit.InitializeDefaultLocaleRule +import org.oppia.android.testing.robolectric.RobolectricModule +import org.oppia.android.testing.threading.TestCoroutineDispatchers +import org.oppia.android.testing.threading.TestDispatcherModule +import org.oppia.android.testing.time.FakeOppiaClockModule +import org.oppia.android.util.accessibility.AccessibilityTestModule +import org.oppia.android.util.caching.AssetModule +import org.oppia.android.util.caching.testing.CachingTestModule +import org.oppia.android.util.gcsresource.GcsResourceModule +import org.oppia.android.util.locale.LocaleProdModule +import org.oppia.android.util.logging.EventLoggingConfigurationModule +import org.oppia.android.util.logging.LoggerModule +import org.oppia.android.util.logging.SyncStatusModule +import org.oppia.android.util.logging.firebase.FirebaseLogUploaderModule +import org.oppia.android.util.networking.NetworkConnectionDebugUtilModule +import org.oppia.android.util.networking.NetworkConnectionUtilDebugModule +import org.oppia.android.util.parser.html.HtmlParserEntityTypeModule +import org.oppia.android.util.parser.image.ImageParsingModule +import org.robolectric.annotation.Config +import org.robolectric.annotation.LooperMode + +/** Tests for [ForcedAppDeprecationNoticeDialogFragment]. */ +// FunctionName: test names are conventionally named with underscores. +@Suppress("FunctionName") +@RunWith(AndroidJUnit4::class) +@Config( + application = OptionalAppDeprecationNoticeDialogFragmentTest.TestApplication::class, + qualifiers = "port-xxhdpi" +) +@LooperMode(LooperMode.Mode.PAUSED) +class OptionalAppDeprecationNoticeDialogFragmentTest { + @get:Rule + val initializeDefaultLocaleRule = InitializeDefaultLocaleRule() + + @get:Rule + val oppiaTestRule = OppiaTestRule() + + @field:[Rule JvmField] val mockitoRule: MockitoRule = MockitoJUnit.rule() + + @Inject + lateinit var testCoroutineDispatchers: TestCoroutineDispatchers + + @Mock + lateinit var mockDeprecationNoticeActionListener: DeprecationNoticeActionListener + + @Before + fun setUp() { + setUpTestApplicationComponent() + } + + @Test + fun dummyTest() { + launchForcedAppDeprecationNoticeDialogFragmentTestActivity { + assert(true).equals(true) + } + } + + private fun launchForcedAppDeprecationNoticeDialogFragmentTestActivity( + testBlock: () -> Unit + ) { + // Launch the test activity, but make sure that it's properly set up & time is given for it to + // initialize. + ActivityScenario.launch( + OptionalAppDeprecationNoticeDialogFragmentTestActivity::class.java + ).use { scenario -> + scenario.onActivity { it.mockCallbackListener = mockDeprecationNoticeActionListener } + testCoroutineDispatchers.runCurrent() + testBlock() + } + } + + private fun clickOnDialogView(matcher: Matcher) { + onDialogView(matcher).perform(ViewActions.click()) + testCoroutineDispatchers.runCurrent() + } + + private fun setUpTestApplicationComponent() { + ApplicationProvider.getApplicationContext().inject(this) + } + + private companion object { + private fun onDialogView(matcher: Matcher) = Espresso.onView(matcher) + .inRoot(RootMatchers.isDialog()) + } + + @Singleton + @Component( + modules = [ + RobolectricModule::class, PlatformParameterModule::class, + TestDispatcherModule::class, ApplicationModule::class, LoggerModule::class, + ContinueModule::class, FractionInputModule::class, ItemSelectionInputModule::class, + MultipleChoiceInputModule::class, NumberWithUnitsRuleModule::class, + NumericInputRuleModule::class, TextInputRuleModule::class, DragDropSortInputModule::class, + ImageClickInputModule::class, InteractionsModule::class, GcsResourceModule::class, + TestImageLoaderModule::class, ImageParsingModule::class, HtmlParserEntityTypeModule::class, + QuestionModule::class, TestLogReportingModule::class, AccessibilityTestModule::class, + LogStorageModule::class, PrimeTopicAssetsControllerModule::class, + ExpirationMetaDataRetrieverModule::class, ViewBindingShimModule::class, + RatioInputModule::class, ApplicationStartupListenerModule::class, + HintsAndSolutionConfigFastShowTestModule::class, HintsAndSolutionProdModule::class, + WorkManagerConfigurationModule::class, LogReportWorkerModule::class, + FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, + DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class, + ExplorationStorageModule::class, NetworkConnectionUtilDebugModule::class, + NetworkConnectionDebugUtilModule::class, NetworkModule::class, NetworkConfigProdModule::class, + AssetModule::class, LocaleProdModule::class, ActivityRecreatorTestModule::class, + PlatformParameterSingletonModule::class, NumericExpressionInputModule::class, + AlgebraicExpressionInputModule::class, MathEquationInputModule::class, + SplitScreenInteractionModule::class, LoggingIdentifierModule::class, + ApplicationLifecycleModule::class, SyncStatusModule::class, TestingBuildFlavorModule::class, + CachingTestModule::class, MetricLogSchedulerModule::class, + EventLoggingConfigurationModule::class, ActivityRouterModule::class, + CpuPerformanceSnapshotterModule::class, ExplorationProgressModule::class + ] + ) + + interface TestApplicationComponent : ApplicationComponent { + @Component.Builder + interface Builder { + @BindsInstance + fun setApplication(application: Application): Builder + + fun build(): TestApplicationComponent + } + + fun inject(test: OptionalAppDeprecationNoticeDialogFragmentTest) + } + + class TestApplication : Application(), ActivityComponentFactory, ApplicationInjectorProvider { + private val component: TestApplicationComponent by lazy { + DaggerOptionalAppDeprecationNoticeDialogFragmentTest_TestApplicationComponent.builder() + .setApplication(this) + .build() + } + + fun inject(test: OptionalAppDeprecationNoticeDialogFragmentTest) = component.inject(test) + + override fun createActivityComponent(activity: AppCompatActivity): ActivityComponent { + return component.getActivityComponentBuilderProvider().get().setActivity(activity).build() + } + + override fun getApplicationInjector(): ApplicationInjector = component + } +} \ No newline at end of file diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt new file mode 100644 index 00000000000..d1ad267e94e --- /dev/null +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt @@ -0,0 +1,221 @@ +package org.oppia.android.app.notice + +import android.app.Application +import android.view.View +import androidx.appcompat.app.AppCompatActivity +import androidx.test.core.app.ActivityScenario +import androidx.test.core.app.ApplicationProvider +import androidx.test.espresso.Espresso +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.matcher.RootMatchers +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.ext.junit.runners.AndroidJUnit4 +import dagger.BindsInstance +import dagger.Component +import javax.inject.Inject +import javax.inject.Singleton +import org.hamcrest.Matcher +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.junit.MockitoJUnit +import org.mockito.junit.MockitoRule +import org.oppia.android.R +import org.oppia.android.app.activity.ActivityComponent +import org.oppia.android.app.activity.ActivityComponentFactory +import org.oppia.android.app.activity.route.ActivityRouterModule +import org.oppia.android.app.application.ApplicationComponent +import org.oppia.android.app.application.ApplicationInjector +import org.oppia.android.app.application.ApplicationInjectorProvider +import org.oppia.android.app.application.ApplicationModule +import org.oppia.android.app.application.ApplicationStartupListenerModule +import org.oppia.android.app.application.testing.TestingBuildFlavorModule +import org.oppia.android.app.devoptions.DeveloperOptionsModule +import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule +import org.oppia.android.app.notice.testing.ForcedAppDeprecationNoticeDialogFragmentTestActivity +import org.oppia.android.app.notice.testing.OsDeprecationNoticeDialogFragmentTestActivity +import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule +import org.oppia.android.app.shim.ViewBindingShimModule +import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule +import org.oppia.android.data.backends.gae.NetworkConfigProdModule +import org.oppia.android.data.backends.gae.NetworkModule +import org.oppia.android.domain.classify.InteractionsModule +import org.oppia.android.domain.classify.rules.algebraicexpressioninput.AlgebraicExpressionInputModule +import org.oppia.android.domain.classify.rules.continueinteraction.ContinueModule +import org.oppia.android.domain.classify.rules.dragAndDropSortInput.DragDropSortInputModule +import org.oppia.android.domain.classify.rules.fractioninput.FractionInputModule +import org.oppia.android.domain.classify.rules.imageClickInput.ImageClickInputModule +import org.oppia.android.domain.classify.rules.itemselectioninput.ItemSelectionInputModule +import org.oppia.android.domain.classify.rules.mathequationinput.MathEquationInputModule +import org.oppia.android.domain.classify.rules.multiplechoiceinput.MultipleChoiceInputModule +import org.oppia.android.domain.classify.rules.numberwithunits.NumberWithUnitsRuleModule +import org.oppia.android.domain.classify.rules.numericexpressioninput.NumericExpressionInputModule +import org.oppia.android.domain.classify.rules.numericinput.NumericInputRuleModule +import org.oppia.android.domain.classify.rules.ratioinput.RatioInputModule +import org.oppia.android.domain.classify.rules.textinput.TextInputRuleModule +import org.oppia.android.domain.exploration.ExplorationProgressModule +import org.oppia.android.domain.exploration.ExplorationStorageModule +import org.oppia.android.domain.hintsandsolution.HintsAndSolutionConfigFastShowTestModule +import org.oppia.android.domain.hintsandsolution.HintsAndSolutionProdModule +import org.oppia.android.domain.onboarding.ExpirationMetaDataRetrieverModule +import org.oppia.android.domain.oppialogger.LogStorageModule +import org.oppia.android.domain.oppialogger.LoggingIdentifierModule +import org.oppia.android.domain.oppialogger.analytics.ApplicationLifecycleModule +import org.oppia.android.domain.oppialogger.analytics.CpuPerformanceSnapshotterModule +import org.oppia.android.domain.oppialogger.logscheduler.MetricLogSchedulerModule +import org.oppia.android.domain.oppialogger.loguploader.LogReportWorkerModule +import org.oppia.android.domain.platformparameter.PlatformParameterModule +import org.oppia.android.domain.platformparameter.PlatformParameterSingletonModule +import org.oppia.android.domain.question.QuestionModule +import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule +import org.oppia.android.domain.workmanager.WorkManagerConfigurationModule +import org.oppia.android.testing.OppiaTestRule +import org.oppia.android.testing.TestImageLoaderModule +import org.oppia.android.testing.TestLogReportingModule +import org.oppia.android.testing.junit.InitializeDefaultLocaleRule +import org.oppia.android.testing.robolectric.RobolectricModule +import org.oppia.android.testing.threading.TestCoroutineDispatchers +import org.oppia.android.testing.threading.TestDispatcherModule +import org.oppia.android.testing.time.FakeOppiaClockModule +import org.oppia.android.util.accessibility.AccessibilityTestModule +import org.oppia.android.util.caching.AssetModule +import org.oppia.android.util.caching.testing.CachingTestModule +import org.oppia.android.util.gcsresource.GcsResourceModule +import org.oppia.android.util.locale.LocaleProdModule +import org.oppia.android.util.logging.EventLoggingConfigurationModule +import org.oppia.android.util.logging.LoggerModule +import org.oppia.android.util.logging.SyncStatusModule +import org.oppia.android.util.logging.firebase.FirebaseLogUploaderModule +import org.oppia.android.util.networking.NetworkConnectionDebugUtilModule +import org.oppia.android.util.networking.NetworkConnectionUtilDebugModule +import org.oppia.android.util.parser.html.HtmlParserEntityTypeModule +import org.oppia.android.util.parser.image.ImageParsingModule +import org.robolectric.annotation.Config +import org.robolectric.annotation.LooperMode + +/** Tests for [ForcedAppDeprecationNoticeDialogFragment]. */ +// FunctionName: test names are conventionally named with underscores. +@Suppress("FunctionName") +@RunWith(AndroidJUnit4::class) +@Config( + application = OsDeprecationNoticeDialogFragmentTest.TestApplication::class, + qualifiers = "port-xxhdpi" +) +@LooperMode(LooperMode.Mode.PAUSED) +class OsDeprecationNoticeDialogFragmentTest { + @get:Rule + val initializeDefaultLocaleRule = InitializeDefaultLocaleRule() + + @get:Rule + val oppiaTestRule = OppiaTestRule() + + @field:[Rule JvmField] val mockitoRule: MockitoRule = MockitoJUnit.rule() + + @Inject + lateinit var testCoroutineDispatchers: TestCoroutineDispatchers + + @Mock + lateinit var mockDeprecationNoticeActionListener: DeprecationNoticeActionListener + + @Before + fun setUp() { + setUpTestApplicationComponent() + } + + @Test + fun dummyTest() { + launchForcedAppDeprecationNoticeDialogFragmentTestActivity { + assert(true).equals(true) + } + } + + private fun launchForcedAppDeprecationNoticeDialogFragmentTestActivity( + testBlock: () -> Unit + ) { + // Launch the test activity, but make sure that it's properly set up & time is given for it to + // initialize. + ActivityScenario.launch( + OsDeprecationNoticeDialogFragmentTestActivity::class.java + ).use { scenario -> + scenario.onActivity { it.mockCallbackListener = mockDeprecationNoticeActionListener } + testCoroutineDispatchers.runCurrent() + testBlock() + } + } + + private fun clickOnDialogView(matcher: Matcher) { + onDialogView(matcher).perform(ViewActions.click()) + testCoroutineDispatchers.runCurrent() + } + + private fun setUpTestApplicationComponent() { + ApplicationProvider.getApplicationContext().inject(this) + } + + private companion object { + private fun onDialogView(matcher: Matcher) = Espresso.onView(matcher) + .inRoot(RootMatchers.isDialog()) + } + + @Singleton + @Component( + modules = [ + RobolectricModule::class, PlatformParameterModule::class, + TestDispatcherModule::class, ApplicationModule::class, LoggerModule::class, + ContinueModule::class, FractionInputModule::class, ItemSelectionInputModule::class, + MultipleChoiceInputModule::class, NumberWithUnitsRuleModule::class, + NumericInputRuleModule::class, TextInputRuleModule::class, DragDropSortInputModule::class, + ImageClickInputModule::class, InteractionsModule::class, GcsResourceModule::class, + TestImageLoaderModule::class, ImageParsingModule::class, HtmlParserEntityTypeModule::class, + QuestionModule::class, TestLogReportingModule::class, AccessibilityTestModule::class, + LogStorageModule::class, PrimeTopicAssetsControllerModule::class, + ExpirationMetaDataRetrieverModule::class, ViewBindingShimModule::class, + RatioInputModule::class, ApplicationStartupListenerModule::class, + HintsAndSolutionConfigFastShowTestModule::class, HintsAndSolutionProdModule::class, + WorkManagerConfigurationModule::class, LogReportWorkerModule::class, + FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, + DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class, + ExplorationStorageModule::class, NetworkConnectionUtilDebugModule::class, + NetworkConnectionDebugUtilModule::class, NetworkModule::class, NetworkConfigProdModule::class, + AssetModule::class, LocaleProdModule::class, ActivityRecreatorTestModule::class, + PlatformParameterSingletonModule::class, NumericExpressionInputModule::class, + AlgebraicExpressionInputModule::class, MathEquationInputModule::class, + SplitScreenInteractionModule::class, LoggingIdentifierModule::class, + ApplicationLifecycleModule::class, SyncStatusModule::class, TestingBuildFlavorModule::class, + CachingTestModule::class, MetricLogSchedulerModule::class, + EventLoggingConfigurationModule::class, ActivityRouterModule::class, + CpuPerformanceSnapshotterModule::class, ExplorationProgressModule::class + ] + ) + + interface TestApplicationComponent : ApplicationComponent { + @Component.Builder + interface Builder { + @BindsInstance + fun setApplication(application: Application): Builder + + fun build(): TestApplicationComponent + } + + fun inject(test: OsDeprecationNoticeDialogFragmentTest) + } + + class TestApplication : Application(), ActivityComponentFactory, ApplicationInjectorProvider { + private val component: TestApplicationComponent by lazy { + DaggerOsDeprecationNoticeDialogFragmentTest_TestApplicationComponent.builder() + .setApplication(this) + .build() + } + + fun inject(test: OsDeprecationNoticeDialogFragmentTest) = component.inject(test) + + override fun createActivityComponent(activity: AppCompatActivity): ActivityComponent { + return component.getActivityComponentBuilderProvider().get().setActivity(activity).build() + } + + override fun getApplicationInjector(): ApplicationInjector = component + } +} \ No newline at end of file From 81a15197c014bbcd6c8b3aadd82cdca206e8d254 Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Wed, 16 Aug 2023 02:24:31 +0300 Subject: [PATCH 05/13] test: Add tests for all newly added dialog fragments --- .../app/activity/ActivityComponentImpl.kt | 1 - ...eprecationNoticeDialogFragmentPresenter.kt | 2 +- ...eprecationNoticeDialogFragmentPresenter.kt | 2 +- .../android/app/notice/testing/BUILD.bazel | 12 +-- ...ecationNoticeDialogFragmentTestActivity.kt | 6 +- ...ecationNoticeDialogFragmentTestActivity.kt | 5 +- ...ecationNoticeDialogFragmentTestActivity.kt | 5 +- ...dAppDeprecationNoticeDialogFragmentTest.kt | 70 ++++++++++++++-- ...lAppDeprecationNoticeDialogFragmentTest.kt | 79 +++++++++++++++++-- .../OsDeprecationNoticeDialogFragmentTest.kt | 53 +++++++++++-- scripts/assets/test_file_exemptions.textproto | 7 ++ 11 files changed, 202 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/activity/ActivityComponentImpl.kt b/app/src/main/java/org/oppia/android/app/activity/ActivityComponentImpl.kt index 776cd8f53bc..6641b39e76c 100644 --- a/app/src/main/java/org/oppia/android/app/activity/ActivityComponentImpl.kt +++ b/app/src/main/java/org/oppia/android/app/activity/ActivityComponentImpl.kt @@ -31,7 +31,6 @@ import org.oppia.android.app.help.thirdparty.ThirdPartyDependencyListActivity import org.oppia.android.app.home.HomeActivity import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedActivity import org.oppia.android.app.mydownloads.MyDownloadsActivity -import org.oppia.android.app.notice.testing.ForcedAppDeprecationNoticeDialogFragmentTestActivity import org.oppia.android.app.onboarding.OnboardingActivity import org.oppia.android.app.ongoingtopiclist.OngoingTopicListActivity import org.oppia.android.app.options.AppLanguageActivity diff --git a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt index 57fca4f9e5a..04f9a84eeb6 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt @@ -35,7 +35,7 @@ class OptionalAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( ) } .setNegativeButton(R.string.optional_app_update_dialog_dismiss_button_text) { _, _ -> - deprecationNoticeExitAppListener.onPositiveActionButtonClicked( + deprecationNoticeExitAppListener.onNegativeActionButtonClicked( DeprecationNoticeActionType.DISMISS ) } diff --git a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt index e69d5b08dcc..edfd0ab83de 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt @@ -30,7 +30,7 @@ class OsDeprecationNoticeDialogFragmentPresenter @Inject constructor( ) ) .setNegativeButton(R.string.os_deprecation_dialog_dismiss_button_text) { _, _ -> - deprecationNoticeExitAppListener.onPositiveActionButtonClicked( + deprecationNoticeExitAppListener.onNegativeActionButtonClicked( DeprecationNoticeActionType.DISMISS ) } diff --git a/app/src/main/java/org/oppia/android/app/notice/testing/BUILD.bazel b/app/src/main/java/org/oppia/android/app/notice/testing/BUILD.bazel index da1da0d1d2b..00ba0065c2b 100644 --- a/app/src/main/java/org/oppia/android/app/notice/testing/BUILD.bazel +++ b/app/src/main/java/org/oppia/android/app/notice/testing/BUILD.bazel @@ -19,10 +19,10 @@ kt_android_library( ) kt_android_library( - name = "general_availability_upgrade_notice_dialog_fragment_test_activity", + name = "forced_app_deprecation_notice_dialog_fragment_test_activity", testonly = True, srcs = [ - "GeneralAvailabilityUpgradeNoticeDialogFragmentTestActivity.kt", + "ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt", ], visibility = ["//app:app_testing_visibility"], deps = [ @@ -32,10 +32,10 @@ kt_android_library( ) kt_android_library( - name = "forced_app_deprecation_notice_dialog_fragment_test_activity", + name = "general_availability_upgrade_notice_dialog_fragment_test_activity", testonly = True, srcs = [ - "ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt" + "GeneralAvailabilityUpgradeNoticeDialogFragmentTestActivity.kt", ], visibility = ["//app:app_testing_visibility"], deps = [ @@ -48,7 +48,7 @@ kt_android_library( name = "optional_app_deprecation_notice_dialog_fragment_test_activity", testonly = True, srcs = [ - "OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt" + "OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt", ], visibility = ["//app:app_testing_visibility"], deps = [ @@ -61,7 +61,7 @@ kt_android_library( name = "os_deprecation_notice_dialog_fragment_test_activity", testonly = True, srcs = [ - "OsDeprecationNoticeDialogFragmentTestActivity.kt" + "OsDeprecationNoticeDialogFragmentTestActivity.kt", ], visibility = ["//app:app_testing_visibility"], deps = [ diff --git a/app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt index 809682234e9..e1dbe3483bc 100644 --- a/app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt @@ -7,7 +7,8 @@ import org.oppia.android.app.splash.DeprecationNoticeActionType import org.oppia.android.app.testing.activity.TestActivity /** [TestActivity] for setting up a test environment for testing the beta notice dialog. */ -class ForcedAppDeprecationNoticeDialogFragmentTestActivity: TestActivity(), +class ForcedAppDeprecationNoticeDialogFragmentTestActivity : + TestActivity(), DeprecationNoticeActionListener { /** * [DeprecationNoticeActionListener] that must be initialized by the test, and is presumed to be a @@ -30,5 +31,4 @@ class ForcedAppDeprecationNoticeDialogFragmentTestActivity: TestActivity(), override fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) { mockCallbackListener.onNegativeActionButtonClicked(noticeType) } - -} \ No newline at end of file +} diff --git a/app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt index 9b8537ed8bd..f63e7518c47 100644 --- a/app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt @@ -7,7 +7,8 @@ import org.oppia.android.app.splash.DeprecationNoticeActionType import org.oppia.android.app.testing.activity.TestActivity /** [TestActivity] for setting up a test environment for testing the beta notice dialog. */ -class OptionalAppDeprecationNoticeDialogFragmentTestActivity: TestActivity(), +class OptionalAppDeprecationNoticeDialogFragmentTestActivity : + TestActivity(), DeprecationNoticeActionListener { /** * [DeprecationNoticeActionListener] that must be initialized by the test, and is presumed to be a @@ -30,4 +31,4 @@ class OptionalAppDeprecationNoticeDialogFragmentTestActivity: TestActivity(), override fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) { mockCallbackListener.onNegativeActionButtonClicked(noticeType) } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt index 4a61079ef2e..707b41ae895 100644 --- a/app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt @@ -7,7 +7,8 @@ import org.oppia.android.app.splash.DeprecationNoticeActionType import org.oppia.android.app.testing.activity.TestActivity /** [TestActivity] for setting up a test environment for testing the beta notice dialog. */ -class OsDeprecationNoticeDialogFragmentTestActivity: TestActivity(), +class OsDeprecationNoticeDialogFragmentTestActivity : + TestActivity(), DeprecationNoticeActionListener { /** * [DeprecationNoticeActionListener] that must be initialized by the test, and is presumed to be a @@ -30,4 +31,4 @@ class OsDeprecationNoticeDialogFragmentTestActivity: TestActivity(), override fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) { mockCallbackListener.onNegativeActionButtonClicked(noticeType) } -} \ No newline at end of file +} diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt index 8078160fcce..fd0e85b9cc7 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt @@ -1,26 +1,26 @@ package org.oppia.android.app.notice import android.app.Application +import android.content.Context import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider -import androidx.test.espresso.action.ViewActions import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions import androidx.test.espresso.assertion.ViewAssertions import androidx.test.espresso.matcher.RootMatchers.isDialog import androidx.test.espresso.matcher.ViewMatchers import androidx.test.ext.junit.runners.AndroidJUnit4 import dagger.BindsInstance import dagger.Component -import javax.inject.Inject -import javax.inject.Singleton import org.hamcrest.Matcher import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock +import org.mockito.Mockito.verify import org.mockito.junit.MockitoJUnit import org.mockito.junit.MockitoRule import org.oppia.android.R @@ -38,6 +38,7 @@ import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule import org.oppia.android.app.notice.testing.ForcedAppDeprecationNoticeDialogFragmentTestActivity import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule import org.oppia.android.app.shim.ViewBindingShimModule +import org.oppia.android.app.splash.DeprecationNoticeActionType import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule import org.oppia.android.data.backends.gae.NetworkConfigProdModule import org.oppia.android.data.backends.gae.NetworkModule @@ -94,6 +95,8 @@ import org.oppia.android.util.parser.html.HtmlParserEntityTypeModule import org.oppia.android.util.parser.image.ImageParsingModule import org.robolectric.annotation.Config import org.robolectric.annotation.LooperMode +import javax.inject.Inject +import javax.inject.Singleton /** Tests for [ForcedAppDeprecationNoticeDialogFragment]. */ // FunctionName: test names are conventionally named with underscores. @@ -119,26 +122,77 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { @Mock lateinit var mockDeprecationNoticeActionListener: DeprecationNoticeActionListener + @Inject + lateinit var context: Context + @Before fun setUp() { setUpTestApplicationComponent() } @Test - fun dummyTest() { + fun testFragment_hasExpectedTitle() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - assert(true).equals(true) + onDialogView(ViewMatchers.withText(R.string.unsupported_app_version_dialog_title)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) } } @Test - fun testFragment_hasExpectedTitle() { + fun testFragment_hasExpectedContentMessageTextUnderTitle() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView(ViewMatchers.withText(R.string.unsupported_app_version_dialog_title)) + val appName = context.resources.getString(R.string.app_name) + val expectedString = context.resources.getString( + R.string.unsupported_app_version_dialog_message, + appName + ) + onDialogView(ViewMatchers.withText(expectedString)) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) } } + @Test + fun testFragment_hasUpdateButton() { + launchForcedAppDeprecationNoticeDialogFragmentTestActivity { + onDialogView( + ViewMatchers.withText(R.string.unsupported_app_version_dialog_update_button_text) + ).check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + } + + @Test + fun testFragment_clickOnUpdateButton_callsCallbackListener_withUpdateDeprecationActionType() { + launchForcedAppDeprecationNoticeDialogFragmentTestActivity { + clickOnDialogView( + ViewMatchers.withText(R.string.unsupported_app_version_dialog_update_button_text) + ) + + verify(mockDeprecationNoticeActionListener) + .onPositiveActionButtonClicked(DeprecationNoticeActionType.UPDATE) + } + } + + @Test + fun testFragment_hasCloseAppButton() { + launchForcedAppDeprecationNoticeDialogFragmentTestActivity { + onDialogView( + ViewMatchers.withText(R.string.unsupported_app_version_dialog_close_button_text) + ).check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + } + + @Test + fun testFragment_clockOnCloseAppButton_callsCallbackListener_withCloseDeprecationActionType() { + launchForcedAppDeprecationNoticeDialogFragmentTestActivity { + clickOnDialogView( + ViewMatchers.withText(R.string.unsupported_app_version_dialog_close_button_text) + ) + + verify(mockDeprecationNoticeActionListener) + .onNegativeActionButtonClicked(DeprecationNoticeActionType.CLOSE) + } + } + private fun launchForcedAppDeprecationNoticeDialogFragmentTestActivity( testBlock: () -> Unit ) { @@ -224,4 +278,4 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { override fun getApplicationInjector(): ApplicationInjector = component } -} \ No newline at end of file +} diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt index 7a250ad2881..fe94d13c8f8 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt @@ -1,26 +1,29 @@ package org.oppia.android.app.notice import android.app.Application +import android.content.Context import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.assertion.ViewAssertions import androidx.test.espresso.matcher.RootMatchers +import androidx.test.espresso.matcher.ViewMatchers import androidx.test.ext.junit.runners.AndroidJUnit4 import dagger.BindsInstance import dagger.Component -import javax.inject.Inject -import javax.inject.Singleton import org.hamcrest.Matcher import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock +import org.mockito.Mockito.verify import org.mockito.junit.MockitoJUnit import org.mockito.junit.MockitoRule +import org.oppia.android.R import org.oppia.android.app.activity.ActivityComponent import org.oppia.android.app.activity.ActivityComponentFactory import org.oppia.android.app.activity.route.ActivityRouterModule @@ -32,10 +35,10 @@ import org.oppia.android.app.application.ApplicationStartupListenerModule import org.oppia.android.app.application.testing.TestingBuildFlavorModule import org.oppia.android.app.devoptions.DeveloperOptionsModule import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule -import org.oppia.android.app.notice.testing.ForcedAppDeprecationNoticeDialogFragmentTestActivity import org.oppia.android.app.notice.testing.OptionalAppDeprecationNoticeDialogFragmentTestActivity import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule import org.oppia.android.app.shim.ViewBindingShimModule +import org.oppia.android.app.splash.DeprecationNoticeActionType import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule import org.oppia.android.data.backends.gae.NetworkConfigProdModule import org.oppia.android.data.backends.gae.NetworkModule @@ -92,6 +95,8 @@ import org.oppia.android.util.parser.html.HtmlParserEntityTypeModule import org.oppia.android.util.parser.image.ImageParsingModule import org.robolectric.annotation.Config import org.robolectric.annotation.LooperMode +import javax.inject.Inject +import javax.inject.Singleton /** Tests for [ForcedAppDeprecationNoticeDialogFragment]. */ // FunctionName: test names are conventionally named with underscores. @@ -117,19 +122,77 @@ class OptionalAppDeprecationNoticeDialogFragmentTest { @Mock lateinit var mockDeprecationNoticeActionListener: DeprecationNoticeActionListener + @Inject + lateinit var context: Context + @Before fun setUp() { setUpTestApplicationComponent() } @Test - fun dummyTest() { - launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - assert(true).equals(true) + fun testFragment_hasExpectedTitle() { + launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { + onDialogView(ViewMatchers.withText(R.string.optional_app_update_dialog_title)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + } + + @Test + fun testFragment_hasExpectedContentMessageTextUnderTitle() { + launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { + val appName = context.resources.getString(R.string.app_name) + val expectedString = context.resources.getString( + R.string.optional_app_update_dialog_message, + appName + ) + onDialogView(ViewMatchers.withText(expectedString)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + } + + @Test + fun testFragment_hasUpdateButton() { + launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { + onDialogView(ViewMatchers.withText(R.string.optional_app_update_dialog_update_button_text)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + } + + @Test + fun testFragment_clickOnUpdateButton_callsCallbackListener_withUpdateDeprecationActionType() { + launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { + clickOnDialogView( + ViewMatchers.withText(R.string.optional_app_update_dialog_update_button_text) + ) + + verify(mockDeprecationNoticeActionListener) + .onPositiveActionButtonClicked(DeprecationNoticeActionType.UPDATE) + } + } + + @Test + fun testFragment_hasDismissButton() { + launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { + onDialogView( + ViewMatchers.withText(R.string.optional_app_update_dialog_dismiss_button_text) + ).check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + } + + @Test + fun testFragment_clickOnDismissButton_callsCallbackListener_withDismissDeprecationActionType() { + launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { + clickOnDialogView( + ViewMatchers.withText(R.string.optional_app_update_dialog_dismiss_button_text) + ) + + verify(mockDeprecationNoticeActionListener) + .onNegativeActionButtonClicked(DeprecationNoticeActionType.DISMISS) } } - private fun launchForcedAppDeprecationNoticeDialogFragmentTestActivity( + private fun launchOptionalAppDeprecationNoticeDialogFragmentTestActivity( testBlock: () -> Unit ) { // Launch the test activity, but make sure that it's properly set up & time is given for it to @@ -215,4 +278,4 @@ class OptionalAppDeprecationNoticeDialogFragmentTest { override fun getApplicationInjector(): ApplicationInjector = component } -} \ No newline at end of file +} diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt index d1ad267e94e..1db89af76ad 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt @@ -1,6 +1,7 @@ package org.oppia.android.app.notice import android.app.Application +import android.content.Context import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.test.core.app.ActivityScenario @@ -13,14 +14,13 @@ import androidx.test.espresso.matcher.ViewMatchers import androidx.test.ext.junit.runners.AndroidJUnit4 import dagger.BindsInstance import dagger.Component -import javax.inject.Inject -import javax.inject.Singleton import org.hamcrest.Matcher import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock +import org.mockito.Mockito.verify import org.mockito.junit.MockitoJUnit import org.mockito.junit.MockitoRule import org.oppia.android.R @@ -35,10 +35,10 @@ import org.oppia.android.app.application.ApplicationStartupListenerModule import org.oppia.android.app.application.testing.TestingBuildFlavorModule import org.oppia.android.app.devoptions.DeveloperOptionsModule import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule -import org.oppia.android.app.notice.testing.ForcedAppDeprecationNoticeDialogFragmentTestActivity import org.oppia.android.app.notice.testing.OsDeprecationNoticeDialogFragmentTestActivity import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule import org.oppia.android.app.shim.ViewBindingShimModule +import org.oppia.android.app.splash.DeprecationNoticeActionType import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule import org.oppia.android.data.backends.gae.NetworkConfigProdModule import org.oppia.android.data.backends.gae.NetworkModule @@ -95,6 +95,8 @@ import org.oppia.android.util.parser.html.HtmlParserEntityTypeModule import org.oppia.android.util.parser.image.ImageParsingModule import org.robolectric.annotation.Config import org.robolectric.annotation.LooperMode +import javax.inject.Inject +import javax.inject.Singleton /** Tests for [ForcedAppDeprecationNoticeDialogFragment]. */ // FunctionName: test names are conventionally named with underscores. @@ -120,19 +122,54 @@ class OsDeprecationNoticeDialogFragmentTest { @Mock lateinit var mockDeprecationNoticeActionListener: DeprecationNoticeActionListener + @Inject + lateinit var context: Context + @Before fun setUp() { setUpTestApplicationComponent() } @Test - fun dummyTest() { - launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - assert(true).equals(true) + fun testFragment_hasExpectedTitle() { + launchOsDeprecationNoticeDialogFragmentTestActivity { + onDialogView(ViewMatchers.withText(R.string.os_deprecation_dialog_title)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + } + + @Test + fun testFragment_hasExpectedContentMessageTextUnderTitle() { + launchOsDeprecationNoticeDialogFragmentTestActivity { + val appName = context.resources.getString(R.string.app_name) + val expectedString = context.resources.getString( + R.string.os_deprecation_dialog_message, + appName + ) + onDialogView(ViewMatchers.withText(expectedString)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + } + + @Test + fun testFragment_hasDismissButton() { + launchOsDeprecationNoticeDialogFragmentTestActivity { + onDialogView(ViewMatchers.withText(R.string.os_deprecation_dialog_dismiss_button_text)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + } + + @Test + fun testFragment_clickOnDismissButton_callsCallbackListener_withDismissDeprecationActionType() { + launchOsDeprecationNoticeDialogFragmentTestActivity { + clickOnDialogView(ViewMatchers.withText(R.string.os_deprecation_dialog_dismiss_button_text)) + + verify(mockDeprecationNoticeActionListener) + .onNegativeActionButtonClicked(DeprecationNoticeActionType.DISMISS) } } - private fun launchForcedAppDeprecationNoticeDialogFragmentTestActivity( + private fun launchOsDeprecationNoticeDialogFragmentTestActivity( testBlock: () -> Unit ) { // Launch the test activity, but make sure that it's properly set up & time is given for it to @@ -218,4 +255,4 @@ class OsDeprecationNoticeDialogFragmentTest { override fun getApplicationInjector(): ApplicationInjector = component } -} \ No newline at end of file +} diff --git a/scripts/assets/test_file_exemptions.textproto b/scripts/assets/test_file_exemptions.textproto index 699f8b9a9cd..382bd7c1efa 100644 --- a/scripts/assets/test_file_exemptions.textproto +++ b/scripts/assets/test_file_exemptions.textproto @@ -235,8 +235,15 @@ exempted_file_path: "app/src/main/java/org/oppia/android/app/mydownloads/MyDownl exempted_file_path: "app/src/main/java/org/oppia/android/app/mydownloads/MyDownloadsViewPagerAdapter.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/mydownloads/UpdatesTabFragment.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/mydownloads/UpdatesTabFragmentPresenter.kt" +exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeActionListener.kt" +exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt" +exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt" +exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/testing/BetaNoticeDialogFragmentTestActivity.kt" +exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/testing/GeneralAvailabilityUpgradeNoticeDialogFragmentTestActivity.kt" +exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt" +exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/onboarding/OnboadingSlideViewModel.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/onboarding/OnboardingActivityPresenter.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/onboarding/OnboardingFragmentPresenter.kt" From a6435045c072d533e32c0a097c9a417eea59c941 Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Thu, 17 Aug 2023 16:33:05 +0300 Subject: [PATCH 06/13] fix: Fix comments from the self-review. --- .../app/notice/DeprecationNoticeActionListener.kt | 7 ++----- ...orcedAppDeprecationNoticeDialogFragmentPresenter.kt | 4 ++-- ...ionalAppDeprecationNoticeDialogFragmentPresenter.kt | 4 ++-- .../OsDeprecationNoticeDialogFragmentPresenter.kt | 2 +- ...edAppDeprecationNoticeDialogFragmentTestActivity.kt | 8 ++------ ...alAppDeprecationNoticeDialogFragmentTestActivity.kt | 8 ++------ .../OsDeprecationNoticeDialogFragmentTestActivity.kt | 8 ++------ .../org/oppia/android/app/splash/SplashActivity.kt | 10 +--------- .../android/app/splash/SplashActivityPresenter.kt | 6 +++--- .../ForcedAppDeprecationNoticeDialogFragmentTest.kt | 4 ++-- .../OptionalAppDeprecationNoticeDialogFragmentTest.kt | 4 ++-- .../notice/OsDeprecationNoticeDialogFragmentTest.kt | 2 +- 12 files changed, 22 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeActionListener.kt b/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeActionListener.kt index 300a869ae89..b9edef60fcc 100644 --- a/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeActionListener.kt +++ b/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeActionListener.kt @@ -4,9 +4,6 @@ import org.oppia.android.app.splash.DeprecationNoticeActionType /** Listener for when an option on any deprecation dialog is clicked. */ interface DeprecationNoticeActionListener { - /** Called when the positive dialog button is clicked. */ - fun onPositiveActionButtonClicked(noticeType: DeprecationNoticeActionType) - - /** Called when the negative dialog button is clicked. */ - fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) + /** Called when a dialog button is clicked. */ + fun onActionButtonClicked(noticeType: DeprecationNoticeActionType) } diff --git a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt index 1033fa78281..55db6277bdb 100644 --- a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt @@ -30,12 +30,12 @@ class ForcedAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( ) ) .setPositiveButton(R.string.unsupported_app_version_dialog_update_button_text) { _, _ -> - deprecationNoticeExitAppListener.onPositiveActionButtonClicked( + deprecationNoticeExitAppListener.onActionButtonClicked( DeprecationNoticeActionType.UPDATE ) } .setNegativeButton(R.string.unsupported_app_version_dialog_close_button_text) { _, _ -> - deprecationNoticeExitAppListener.onNegativeActionButtonClicked( + deprecationNoticeExitAppListener.onActionButtonClicked( DeprecationNoticeActionType.CLOSE ) } diff --git a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt index 04f9a84eeb6..05b88679bf7 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt @@ -30,12 +30,12 @@ class OptionalAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( ) ) .setPositiveButton(R.string.optional_app_update_dialog_update_button_text) { _, _ -> - deprecationNoticeExitAppListener.onPositiveActionButtonClicked( + deprecationNoticeExitAppListener.onActionButtonClicked( DeprecationNoticeActionType.UPDATE ) } .setNegativeButton(R.string.optional_app_update_dialog_dismiss_button_text) { _, _ -> - deprecationNoticeExitAppListener.onNegativeActionButtonClicked( + deprecationNoticeExitAppListener.onActionButtonClicked( DeprecationNoticeActionType.DISMISS ) } diff --git a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt index edfd0ab83de..11b3db37414 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt @@ -30,7 +30,7 @@ class OsDeprecationNoticeDialogFragmentPresenter @Inject constructor( ) ) .setNegativeButton(R.string.os_deprecation_dialog_dismiss_button_text) { _, _ -> - deprecationNoticeExitAppListener.onNegativeActionButtonClicked( + deprecationNoticeExitAppListener.onActionButtonClicked( DeprecationNoticeActionType.DISMISS ) } diff --git a/app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt index e1dbe3483bc..e6b223af14d 100644 --- a/app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/notice/testing/ForcedAppDeprecationNoticeDialogFragmentTestActivity.kt @@ -24,11 +24,7 @@ class ForcedAppDeprecationNoticeDialogFragmentTestActivity : .showNow(supportFragmentManager, "forced_app_deprecation_dialog") } - override fun onPositiveActionButtonClicked(noticeType: DeprecationNoticeActionType) { - mockCallbackListener.onPositiveActionButtonClicked(noticeType) - } - - override fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) { - mockCallbackListener.onNegativeActionButtonClicked(noticeType) + override fun onActionButtonClicked(noticeType: DeprecationNoticeActionType) { + mockCallbackListener.onActionButtonClicked(noticeType) } } diff --git a/app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt index f63e7518c47..d3ffd8b519e 100644 --- a/app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/notice/testing/OptionalAppDeprecationNoticeDialogFragmentTestActivity.kt @@ -24,11 +24,7 @@ class OptionalAppDeprecationNoticeDialogFragmentTestActivity : .showNow(supportFragmentManager, "optional_app_deprecation_dialog") } - override fun onPositiveActionButtonClicked(noticeType: DeprecationNoticeActionType) { - mockCallbackListener.onPositiveActionButtonClicked(noticeType) - } - - override fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) { - mockCallbackListener.onNegativeActionButtonClicked(noticeType) + override fun onActionButtonClicked(noticeType: DeprecationNoticeActionType) { + mockCallbackListener.onActionButtonClicked(noticeType) } } diff --git a/app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt b/app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt index 707b41ae895..13923f43fd8 100644 --- a/app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt +++ b/app/src/main/java/org/oppia/android/app/notice/testing/OsDeprecationNoticeDialogFragmentTestActivity.kt @@ -24,11 +24,7 @@ class OsDeprecationNoticeDialogFragmentTestActivity : .showNow(supportFragmentManager, "os_deprecation_dialog") } - override fun onPositiveActionButtonClicked(noticeType: DeprecationNoticeActionType) { - mockCallbackListener.onPositiveActionButtonClicked(noticeType) - } - - override fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) { - mockCallbackListener.onNegativeActionButtonClicked(noticeType) + override fun onActionButtonClicked(noticeType: DeprecationNoticeActionType) { + mockCallbackListener.onActionButtonClicked(noticeType) } } diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt index c442691a2a8..b825bdbf43a 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt @@ -60,15 +60,7 @@ class SplashActivity : return builderInjector.getFragmentComponentBuilderProvider().get().setFragment(fragment).build() } - override fun onPositiveActionButtonClicked(noticeType: DeprecationNoticeActionType) { - when (noticeType) { - DeprecationNoticeActionType.CLOSE -> splashActivityPresenter.handleOnCloseAppButtonClicked() - DeprecationNoticeActionType.DISMISS -> splashActivityPresenter.handleOnDismissButtonClicked() - DeprecationNoticeActionType.UPDATE -> splashActivityPresenter.handleOnUpdateButtonClicked() - } - } - - override fun onNegativeActionButtonClicked(noticeType: DeprecationNoticeActionType) { + override fun onActionButtonClicked(noticeType: DeprecationNoticeActionType) { when (noticeType) { DeprecationNoticeActionType.CLOSE -> splashActivityPresenter.handleOnCloseAppButtonClicked() DeprecationNoticeActionType.DISMISS -> splashActivityPresenter.handleOnDismissButtonClicked() diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt index 94079dbe192..8b921b387a7 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt @@ -67,14 +67,14 @@ class SplashActivityPresenter @Inject constructor( subscribeToOnboardingFlow() } - /** */ + /** Handles cases where the user clicks the close app option on a deprecation notice dialog. */ fun handleOnCloseAppButtonClicked() { // If the app close button is clicked for the deprecation notice, finish the activity to close // the app. activity.finish() } - /** */ + /** Handle cases where the user clicks the update option on a deprecation notice dialog. */ fun handleOnUpdateButtonClicked() { // If the Update button is clicked for the deprecation notice, launch the Play Store and open // the Oppia app's page. @@ -101,7 +101,7 @@ class SplashActivityPresenter @Inject constructor( } } - /** */ + /** Handle cases where the user dismisses the deprecation notice dialog. */ fun handleOnDismissButtonClicked() { // If the Dismiss button is clicked for the deprecation notice, the dialog is automatically // dismissed. Navigate to profile chooser activity. diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt index fd0e85b9cc7..1dc8534d84b 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt @@ -168,7 +168,7 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { ) verify(mockDeprecationNoticeActionListener) - .onPositiveActionButtonClicked(DeprecationNoticeActionType.UPDATE) + .onActionButtonClicked(DeprecationNoticeActionType.UPDATE) } } @@ -189,7 +189,7 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { ) verify(mockDeprecationNoticeActionListener) - .onNegativeActionButtonClicked(DeprecationNoticeActionType.CLOSE) + .onActionButtonClicked(DeprecationNoticeActionType.CLOSE) } } diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt index fe94d13c8f8..adf2c2abe5a 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt @@ -167,7 +167,7 @@ class OptionalAppDeprecationNoticeDialogFragmentTest { ) verify(mockDeprecationNoticeActionListener) - .onPositiveActionButtonClicked(DeprecationNoticeActionType.UPDATE) + .onActionButtonClicked(DeprecationNoticeActionType.UPDATE) } } @@ -188,7 +188,7 @@ class OptionalAppDeprecationNoticeDialogFragmentTest { ) verify(mockDeprecationNoticeActionListener) - .onNegativeActionButtonClicked(DeprecationNoticeActionType.DISMISS) + .onActionButtonClicked(DeprecationNoticeActionType.DISMISS) } } diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt index 1db89af76ad..3be36bf47cf 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt @@ -165,7 +165,7 @@ class OsDeprecationNoticeDialogFragmentTest { clickOnDialogView(ViewMatchers.withText(R.string.os_deprecation_dialog_dismiss_button_text)) verify(mockDeprecationNoticeActionListener) - .onNegativeActionButtonClicked(DeprecationNoticeActionType.DISMISS) + .onActionButtonClicked(DeprecationNoticeActionType.DISMISS) } } From d40aabaca334b51ce3cb05a8029bccc80e23866c Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Thu, 17 Aug 2023 17:37:59 +0300 Subject: [PATCH 07/13] chore: Cleanup unused dependencies in the bazel file --- .../org/oppia/android/app/notice/BUILD.bazel | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/BUILD.bazel b/app/src/sharedTest/java/org/oppia/android/app/notice/BUILD.bazel index dbde970cc29..d0733552b3b 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/BUILD.bazel +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/BUILD.bazel @@ -94,26 +94,17 @@ app_test( "//app/src/main/java/org/oppia/android/app/application/testing:testing_build_flavor_module", "//app/src/main/java/org/oppia/android/app/notice/testing:forced_app_deprecation_notice_dialog_fragment_test_activity", "//app/src/main/java/org/oppia/android/app/translation/testing:test_module", - "//data/src/main/java/org/oppia/android/data/backends/gae:prod_module", - "//domain/src/main/java/org/oppia/android/domain/onboarding/testing:retriever_test_module", "//testing", "//testing/src/main/java/org/oppia/android/testing/junit:initialize_default_locale_rule", "//testing/src/main/java/org/oppia/android/testing/robolectric:test_module", "//testing/src/main/java/org/oppia/android/testing/threading:test_module", "//testing/src/main/java/org/oppia/android/testing/time:test_module", "//third_party:androidx_test_espresso_espresso-core", - "//third_party:androidx_test_ext_junit", - "//third_party:org_robolectric_robolectric", "//third_party:robolectric_android-all", "//utility/src/main/java/org/oppia/android/util/accessibility:test_module", - "//utility/src/main/java/org/oppia/android/util/caching:asset_prod_module", "//utility/src/main/java/org/oppia/android/util/caching/testing:caching_test_module", - "//utility/src/main/java/org/oppia/android/util/locale/testing:test_module", - "//utility/src/main/java/org/oppia/android/util/logging:prod_module", "//utility/src/main/java/org/oppia/android/util/logging:standard_event_logging_configuration_module", - "//utility/src/main/java/org/oppia/android/util/logging/firebase:debug_module", "//utility/src/main/java/org/oppia/android/util/networking:debug_module", - "//utility/src/main/java/org/oppia/android/util/networking:debug_util_module", ], ) @@ -131,26 +122,17 @@ app_test( "//app/src/main/java/org/oppia/android/app/application/testing:testing_build_flavor_module", "//app/src/main/java/org/oppia/android/app/notice/testing:optional_app_deprecation_notice_dialog_fragment_test_activity", "//app/src/main/java/org/oppia/android/app/translation/testing:test_module", - "//data/src/main/java/org/oppia/android/data/backends/gae:prod_module", - "//domain/src/main/java/org/oppia/android/domain/onboarding/testing:retriever_test_module", "//testing", "//testing/src/main/java/org/oppia/android/testing/junit:initialize_default_locale_rule", "//testing/src/main/java/org/oppia/android/testing/robolectric:test_module", "//testing/src/main/java/org/oppia/android/testing/threading:test_module", "//testing/src/main/java/org/oppia/android/testing/time:test_module", "//third_party:androidx_test_espresso_espresso-core", - "//third_party:androidx_test_ext_junit", - "//third_party:org_robolectric_robolectric", "//third_party:robolectric_android-all", "//utility/src/main/java/org/oppia/android/util/accessibility:test_module", - "//utility/src/main/java/org/oppia/android/util/caching:asset_prod_module", "//utility/src/main/java/org/oppia/android/util/caching/testing:caching_test_module", - "//utility/src/main/java/org/oppia/android/util/locale/testing:test_module", - "//utility/src/main/java/org/oppia/android/util/logging:prod_module", "//utility/src/main/java/org/oppia/android/util/logging:standard_event_logging_configuration_module", - "//utility/src/main/java/org/oppia/android/util/logging/firebase:debug_module", "//utility/src/main/java/org/oppia/android/util/networking:debug_module", - "//utility/src/main/java/org/oppia/android/util/networking:debug_util_module", ], ) @@ -168,26 +150,17 @@ app_test( "//app/src/main/java/org/oppia/android/app/application/testing:testing_build_flavor_module", "//app/src/main/java/org/oppia/android/app/notice/testing:os_deprecation_notice_dialog_fragment_test_activity", "//app/src/main/java/org/oppia/android/app/translation/testing:test_module", - "//data/src/main/java/org/oppia/android/data/backends/gae:prod_module", - "//domain/src/main/java/org/oppia/android/domain/onboarding/testing:retriever_test_module", "//testing", "//testing/src/main/java/org/oppia/android/testing/junit:initialize_default_locale_rule", "//testing/src/main/java/org/oppia/android/testing/robolectric:test_module", "//testing/src/main/java/org/oppia/android/testing/threading:test_module", "//testing/src/main/java/org/oppia/android/testing/time:test_module", "//third_party:androidx_test_espresso_espresso-core", - "//third_party:androidx_test_ext_junit", - "//third_party:org_robolectric_robolectric", "//third_party:robolectric_android-all", "//utility/src/main/java/org/oppia/android/util/accessibility:test_module", - "//utility/src/main/java/org/oppia/android/util/caching:asset_prod_module", "//utility/src/main/java/org/oppia/android/util/caching/testing:caching_test_module", - "//utility/src/main/java/org/oppia/android/util/locale/testing:test_module", - "//utility/src/main/java/org/oppia/android/util/logging:prod_module", "//utility/src/main/java/org/oppia/android/util/logging:standard_event_logging_configuration_module", - "//utility/src/main/java/org/oppia/android/util/logging/firebase:debug_module", "//utility/src/main/java/org/oppia/android/util/networking:debug_module", - "//utility/src/main/java/org/oppia/android/util/networking:debug_util_module", ], ) From 84f5446d2076d5149242389efd5e3f621031d29d Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Tue, 12 Sep 2023 22:53:00 +0300 Subject: [PATCH 08/13] chore: Update logic flow on deprecation dialog close action and variable naming --- .../ForcedAppDeprecationNoticeDialogFragmentPresenter.kt | 6 +++--- ...OptionalAppDeprecationNoticeDialogFragmentPresenter.kt | 6 +++--- .../notice/OsDeprecationNoticeDialogFragmentPresenter.kt | 4 ++-- .../oppia/android/app/splash/SplashActivityPresenter.kt | 8 +++----- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt index 55db6277bdb..ee486386bbf 100644 --- a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt @@ -13,7 +13,7 @@ class ForcedAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val resourceHandler: AppLanguageResourceHandler ) { - private val deprecationNoticeExitAppListener by lazy { + private val deprecationNoticeActionListener by lazy { activity as DeprecationNoticeActionListener } @@ -30,12 +30,12 @@ class ForcedAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( ) ) .setPositiveButton(R.string.unsupported_app_version_dialog_update_button_text) { _, _ -> - deprecationNoticeExitAppListener.onActionButtonClicked( + deprecationNoticeActionListener.onActionButtonClicked( DeprecationNoticeActionType.UPDATE ) } .setNegativeButton(R.string.unsupported_app_version_dialog_close_button_text) { _, _ -> - deprecationNoticeExitAppListener.onActionButtonClicked( + deprecationNoticeActionListener.onActionButtonClicked( DeprecationNoticeActionType.CLOSE ) } diff --git a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt index 05b88679bf7..be4b938c522 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentPresenter.kt @@ -13,7 +13,7 @@ class OptionalAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val resourceHandler: AppLanguageResourceHandler ) { - private val deprecationNoticeExitAppListener by lazy { + private val deprecationNoticeActionListener by lazy { activity as DeprecationNoticeActionListener } @@ -30,12 +30,12 @@ class OptionalAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( ) ) .setPositiveButton(R.string.optional_app_update_dialog_update_button_text) { _, _ -> - deprecationNoticeExitAppListener.onActionButtonClicked( + deprecationNoticeActionListener.onActionButtonClicked( DeprecationNoticeActionType.UPDATE ) } .setNegativeButton(R.string.optional_app_update_dialog_dismiss_button_text) { _, _ -> - deprecationNoticeExitAppListener.onActionButtonClicked( + deprecationNoticeActionListener.onActionButtonClicked( DeprecationNoticeActionType.DISMISS ) } diff --git a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt index 11b3db37414..efcfc84ed20 100644 --- a/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentPresenter.kt @@ -13,7 +13,7 @@ class OsDeprecationNoticeDialogFragmentPresenter @Inject constructor( private val activity: AppCompatActivity, private val resourceHandler: AppLanguageResourceHandler ) { - private val deprecationNoticeExitAppListener by lazy { + private val deprecationNoticeActionListener by lazy { activity as DeprecationNoticeActionListener } @@ -30,7 +30,7 @@ class OsDeprecationNoticeDialogFragmentPresenter @Inject constructor( ) ) .setNegativeButton(R.string.os_deprecation_dialog_dismiss_button_text) { _, _ -> - deprecationNoticeExitAppListener.onActionButtonClicked( + deprecationNoticeActionListener.onActionButtonClicked( DeprecationNoticeActionType.DISMISS ) } diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt index 8b921b387a7..237a298bc9b 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt @@ -78,11 +78,6 @@ class SplashActivityPresenter @Inject constructor( fun handleOnUpdateButtonClicked() { // If the Update button is clicked for the deprecation notice, launch the Play Store and open // the Oppia app's page. - - // Launch profile selection activity in case the user presses the back button - activity.startActivity(ProfileChooserActivity.createProfileChooserActivity(activity)) - activity.finish() - val packageName = activity.packageName try { @@ -99,6 +94,9 @@ class SplashActivityPresenter @Inject constructor( ) ) } + + // Finish splash activity to close the app in anticipation of an update. + activity.finish() } /** Handle cases where the user dismisses the deprecation notice dialog. */ From e5fd7866980dd9069eb4c0c31d34e9cf06ca7baa Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Fri, 29 Sep 2023 00:36:21 +0300 Subject: [PATCH 09/13] chore: Reinstate the existing code before this feature --- .../app/fragment/FragmentComponentImpl.kt | 3 ++ ...maticAppDeprecationNoticeDialogFragment.kt | 37 +++++++++++++++++++ ...eprecationNoticeDialogFragmentPresenter.kt | 31 ++++++++++++++++ .../DeprecationNoticeExitAppListener.kt | 7 ++++ ...eprecationNoticeDialogFragmentPresenter.kt | 8 ++-- .../android/app/splash/SplashActivity.kt | 4 ++ .../app/splash/SplashActivityPresenter.kt | 3 +- app/src/main/res/values-ar/strings.xml | 1 + app/src/main/res/values-pcm-rNG/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values/strings.xml | 17 +++++++-- ...dAppDeprecationNoticeDialogFragmentTest.kt | 12 +++--- 12 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragment.kt create mode 100644 app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragmentPresenter.kt create mode 100644 app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeExitAppListener.kt diff --git a/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt b/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt index fbda0072bec..40c9c14ac12 100644 --- a/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt +++ b/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt @@ -29,6 +29,7 @@ import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedFragment import org.oppia.android.app.mydownloads.DownloadsTabFragment import org.oppia.android.app.mydownloads.MyDownloadsFragment import org.oppia.android.app.mydownloads.UpdatesTabFragment +import org.oppia.android.app.notice.AutomaticAppDeprecationNoticeDialogFragment import org.oppia.android.app.notice.BetaNoticeDialogFragment import org.oppia.android.app.notice.ForcedAppDeprecationNoticeDialogFragment import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeDialogFragment @@ -115,6 +116,8 @@ interface FragmentComponentImpl : FragmentComponent, ViewComponentBuilderInjecto fun inject(appVersionFragment: AppVersionFragment) fun inject(audioFragment: AudioFragment) fun inject(audioLanguageFragment: AudioLanguageFragment) + fun inject(automaticAppDeprecationNoticeDialogFragment: + AutomaticAppDeprecationNoticeDialogFragment) fun inject(betaNoticeDialogFragment: BetaNoticeDialogFragment) fun inject(cellularAudioDialogFragment: CellularAudioDialogFragment) fun inject(completedStoryListFragment: CompletedStoryListFragment) diff --git a/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragment.kt b/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragment.kt new file mode 100644 index 00000000000..f4f8beed7fe --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragment.kt @@ -0,0 +1,37 @@ +package org.oppia.android.app.notice + +import android.app.Dialog +import android.content.Context +import android.os.Bundle +import org.oppia.android.app.fragment.FragmentComponentImpl +import org.oppia.android.app.fragment.InjectableDialogFragment +import javax.inject.Inject + +/** + * Dialog fragment to be shown when the pre-release version of the app should no longer be playable + * due to it being expired. + * + * This notice protects the app from unexpected issues being permanently shipped to individuals, and + * from the app being accessible to audience members for long-periods of time when it may not yet be + * ready for broad use or distribution. + */ +class AutomaticAppDeprecationNoticeDialogFragment : InjectableDialogFragment() { + companion object { + /** Returns a new instance of [AutomaticAppDeprecationNoticeDialogFragment]. */ + fun newInstance(): AutomaticAppDeprecationNoticeDialogFragment { + return AutomaticAppDeprecationNoticeDialogFragment() + } + } + + @Inject lateinit var automaticAppDeprecationNoticeDialogFragmentPresenter: + AutomaticAppDeprecationNoticeDialogFragmentPresenter + + override fun onAttach(context: Context) { + super.onAttach(context) + (fragmentComponent as FragmentComponentImpl).inject(this) + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + return automaticAppDeprecationNoticeDialogFragmentPresenter.handleOnCreateDialog() + } +} diff --git a/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragmentPresenter.kt new file mode 100644 index 00000000000..b587df03185 --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragmentPresenter.kt @@ -0,0 +1,31 @@ +package org.oppia.android.app.notice + +import android.app.Dialog +import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatActivity +import org.oppia.android.R +import javax.inject.Inject + +/** + * Presenter for the dialog that shows when the pre-release app is being automatically deprecated. + */ +class AutomaticAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( + private val activity: AppCompatActivity +) { + private val deprecationNoticeExitAppListener by lazy { + activity as DeprecationNoticeExitAppListener + } + + fun handleOnCreateDialog(): Dialog { + val dialog = AlertDialog.Builder(activity) + .setTitle(R.string.unsupported_app_version_dialog_title) + .setMessage(R.string.unsupported_app_version_dialog_message) + .setNegativeButton(R.string.unsupported_app_version_dialog_close_button_text) { _, _ -> + deprecationNoticeExitAppListener.onCloseAppButtonClicked() + } + .setCancelable(false) + .create() + dialog.setCanceledOnTouchOutside(false) + return dialog + } +} diff --git a/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeExitAppListener.kt b/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeExitAppListener.kt new file mode 100644 index 00000000000..ff3d7dd1671 --- /dev/null +++ b/app/src/main/java/org/oppia/android/app/notice/DeprecationNoticeExitAppListener.kt @@ -0,0 +1,7 @@ +package org.oppia.android.app.notice + +/** Listener for when the app deprecation dialog is closed. */ +interface DeprecationNoticeExitAppListener { + /** Called when the deprecation dialog was closed. */ + fun onCloseAppButtonClicked() +} diff --git a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt index ee486386bbf..265670fb3be 100644 --- a/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentPresenter.kt @@ -22,19 +22,19 @@ class ForcedAppDeprecationNoticeDialogFragmentPresenter @Inject constructor( val appName = resourceHandler.getStringInLocale(R.string.app_name) val dialog = AlertDialog.Builder(activity, R.style.DeprecationAlertDialogTheme) - .setTitle(R.string.unsupported_app_version_dialog_title) + .setTitle(R.string.forced_app_update_dialog_title) .setMessage( resourceHandler.getStringInLocaleWithWrapping( - R.string.unsupported_app_version_dialog_message, + R.string.forced_app_update_dialog_message, appName ) ) - .setPositiveButton(R.string.unsupported_app_version_dialog_update_button_text) { _, _ -> + .setPositiveButton(R.string.forced_app_update_dialog_update_button_text) { _, _ -> deprecationNoticeActionListener.onActionButtonClicked( DeprecationNoticeActionType.UPDATE ) } - .setNegativeButton(R.string.unsupported_app_version_dialog_close_button_text) { _, _ -> + .setNegativeButton(R.string.forced_app_update_dialog_close_button_text) { _, _ -> deprecationNoticeActionListener.onActionButtonClicked( DeprecationNoticeActionType.CLOSE ) diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt index b825bdbf43a..d94479f5049 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt @@ -15,6 +15,7 @@ import org.oppia.android.app.notice.DeprecationNoticeActionListener import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeClosedListener import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName import javax.inject.Inject +import org.oppia.android.app.notice.DeprecationNoticeExitAppListener /** Enum class for the various deprecation notice actions available to the user. */ enum class DeprecationNoticeActionType { @@ -37,6 +38,7 @@ enum class DeprecationNoticeActionType { class SplashActivity : AppCompatActivity(), FragmentComponentFactory, + DeprecationNoticeExitAppListener, DeprecationNoticeActionListener, BetaNoticeClosedListener, GeneralAvailabilityUpgradeNoticeClosedListener { @@ -68,6 +70,8 @@ class SplashActivity : } } + override fun onCloseAppButtonClicked() = splashActivityPresenter.handleOnCloseAppButtonClicked() + override fun onBetaNoticeOkayButtonClicked(permanentlyDismiss: Boolean) = splashActivityPresenter.handleOnBetaNoticeOkayButtonClicked(permanentlyDismiss) diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt index 237a298bc9b..6456b742699 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt @@ -32,6 +32,7 @@ import org.oppia.android.util.data.DataProviders.Companion.combineWith import org.oppia.android.util.data.DataProviders.Companion.toLiveData import org.oppia.android.util.locale.OppiaLocale import javax.inject.Inject +import org.oppia.android.app.notice.AutomaticAppDeprecationNoticeDialogFragment private const val AUTO_DEPRECATION_NOTICE_DIALOG_FRAGMENT_TAG = "auto_deprecation_notice_dialog" private const val BETA_NOTICE_DIALOG_FRAGMENT_TAG = "beta_notice_dialog" @@ -208,7 +209,7 @@ class SplashActivityPresenter @Inject constructor( StartupMode.APP_IS_DEPRECATED -> { showDialog( AUTO_DEPRECATION_NOTICE_DIALOG_FRAGMENT_TAG, - ForcedAppDeprecationNoticeDialogFragment::newInstance + AutomaticAppDeprecationNoticeDialogFragment::newInstance ) } else -> { diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 6bc4d2f5467..938f0dbc081 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -473,6 +473,7 @@ ongoing_recycler_view_tag برجاء اختيار خيار واحد على الأقل. إصدار تطبيق غير مدعوم + هذا الإصدار من التطبيق لم يعد مدعومًا. من فضلك قم بتحديث التطبيق من خلال متجر بلاي (Play Store) إغلاق التطبيق بناء المطور ألفا diff --git a/app/src/main/res/values-pcm-rNG/strings.xml b/app/src/main/res/values-pcm-rNG/strings.xml index 175bb2b82cd..616d6e03f76 100644 --- a/app/src/main/res/values-pcm-rNG/strings.xml +++ b/app/src/main/res/values-pcm-rNG/strings.xml @@ -435,6 +435,7 @@ ongoing_recycler_view_tag Abeg select all di correct choices. Unsupported app version + Dis version of di app no longer dey supported. Abeg update am from di Play Store. Close app Developer Build Alpha diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 81e310f413f..9cb7c841127 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -419,6 +419,7 @@ ongoing_recycler_view_tag Por favor, selecione todas as alternativas corretas. Versão do aplicativo não suportada + Esta versão do aplicativo não é mais suportada. Atualize-a na Play Store. Fechar aplicativo Versão do desenvolvedor Alfa diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 987374d08d3..0482949184d 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -500,17 +500,26 @@ Please select all correct choices. - App update required + Unsupported app version - - A new version of %s is now available. The new version is more secure, and improves your learning experience.\n\nThis version is no longer supported. To continue using the app, please update to the latest version. + + This version of the app is no longer supported. Please update it through the Play Store. Close app - + + App update required + + + A new version of %s is now available. The new version is more secure, and improves your learning experience.\n\nThis version is no longer supported. To continue using the app, please update to the latest version. + + Update + + Close app + New update available diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt index 1dc8534d84b..cb6c9237273 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt @@ -133,7 +133,7 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasExpectedTitle() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView(ViewMatchers.withText(R.string.unsupported_app_version_dialog_title)) + onDialogView(ViewMatchers.withText(R.string.forced_app_update_dialog_title)) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) } } @@ -143,7 +143,7 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { val appName = context.resources.getString(R.string.app_name) val expectedString = context.resources.getString( - R.string.unsupported_app_version_dialog_message, + R.string.forced_app_update_dialog_message, appName ) onDialogView(ViewMatchers.withText(expectedString)) @@ -155,7 +155,7 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { fun testFragment_hasUpdateButton() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { onDialogView( - ViewMatchers.withText(R.string.unsupported_app_version_dialog_update_button_text) + ViewMatchers.withText(R.string.forced_app_update_dialog_update_button_text) ).check(ViewAssertions.matches(ViewMatchers.isDisplayed())) } } @@ -164,7 +164,7 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { fun testFragment_clickOnUpdateButton_callsCallbackListener_withUpdateDeprecationActionType() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { clickOnDialogView( - ViewMatchers.withText(R.string.unsupported_app_version_dialog_update_button_text) + ViewMatchers.withText(R.string.forced_app_update_dialog_update_button_text) ) verify(mockDeprecationNoticeActionListener) @@ -176,7 +176,7 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { fun testFragment_hasCloseAppButton() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { onDialogView( - ViewMatchers.withText(R.string.unsupported_app_version_dialog_close_button_text) + ViewMatchers.withText(R.string.forced_app_update_dialog_close_button_text) ).check(ViewAssertions.matches(ViewMatchers.isDisplayed())) } } @@ -185,7 +185,7 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { fun testFragment_clockOnCloseAppButton_callsCallbackListener_withCloseDeprecationActionType() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { clickOnDialogView( - ViewMatchers.withText(R.string.unsupported_app_version_dialog_close_button_text) + ViewMatchers.withText(R.string.forced_app_update_dialog_close_button_text) ) verify(mockDeprecationNoticeActionListener) From 305cd2201f0c4718b76c21f90cc84d98817bde51 Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Fri, 29 Sep 2023 00:38:42 +0300 Subject: [PATCH 10/13] fix: Fix linting issues --- .../org/oppia/android/app/fragment/FragmentComponentImpl.kt | 6 ++++-- .../java/org/oppia/android/app/splash/SplashActivity.kt | 2 +- .../org/oppia/android/app/splash/SplashActivityPresenter.kt | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt b/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt index 40c9c14ac12..029d214a41a 100644 --- a/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt +++ b/app/src/main/java/org/oppia/android/app/fragment/FragmentComponentImpl.kt @@ -116,8 +116,10 @@ interface FragmentComponentImpl : FragmentComponent, ViewComponentBuilderInjecto fun inject(appVersionFragment: AppVersionFragment) fun inject(audioFragment: AudioFragment) fun inject(audioLanguageFragment: AudioLanguageFragment) - fun inject(automaticAppDeprecationNoticeDialogFragment: - AutomaticAppDeprecationNoticeDialogFragment) + fun inject( + automaticAppDeprecationNoticeDialogFragment: + AutomaticAppDeprecationNoticeDialogFragment + ) fun inject(betaNoticeDialogFragment: BetaNoticeDialogFragment) fun inject(cellularAudioDialogFragment: CellularAudioDialogFragment) fun inject(completedStoryListFragment: CompletedStoryListFragment) diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt index d94479f5049..d1bec798126 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt @@ -12,10 +12,10 @@ import org.oppia.android.app.fragment.FragmentComponentFactory import org.oppia.android.app.model.ScreenName.SPLASH_ACTIVITY import org.oppia.android.app.notice.BetaNoticeClosedListener import org.oppia.android.app.notice.DeprecationNoticeActionListener +import org.oppia.android.app.notice.DeprecationNoticeExitAppListener import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeClosedListener import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName import javax.inject.Inject -import org.oppia.android.app.notice.DeprecationNoticeExitAppListener /** Enum class for the various deprecation notice actions available to the user. */ enum class DeprecationNoticeActionType { diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt index 6456b742699..efb76d0e862 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt @@ -13,8 +13,8 @@ import org.oppia.android.app.model.AppStartupState import org.oppia.android.app.model.AppStartupState.BuildFlavorNoticeMode import org.oppia.android.app.model.AppStartupState.StartupMode import org.oppia.android.app.model.BuildFlavor +import org.oppia.android.app.notice.AutomaticAppDeprecationNoticeDialogFragment import org.oppia.android.app.notice.BetaNoticeDialogFragment -import org.oppia.android.app.notice.ForcedAppDeprecationNoticeDialogFragment import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeDialogFragment import org.oppia.android.app.onboarding.OnboardingActivity import org.oppia.android.app.profile.ProfileChooserActivity @@ -32,7 +32,6 @@ import org.oppia.android.util.data.DataProviders.Companion.combineWith import org.oppia.android.util.data.DataProviders.Companion.toLiveData import org.oppia.android.util.locale.OppiaLocale import javax.inject.Inject -import org.oppia.android.app.notice.AutomaticAppDeprecationNoticeDialogFragment private const val AUTO_DEPRECATION_NOTICE_DIALOG_FRAGMENT_TAG = "auto_deprecation_notice_dialog" private const val BETA_NOTICE_DIALOG_FRAGMENT_TAG = "beta_notice_dialog" From 4c5d3b8b5834e055d39f744579028050d2856e61 Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Fri, 29 Sep 2023 00:50:50 +0300 Subject: [PATCH 11/13] fix: Add missing swahili translation and fix failing kdoc check --- app/src/main/res/values-sw/strings.xml | 1 + scripts/assets/kdoc_validity_exemptions.textproto | 1 + 2 files changed, 2 insertions(+) diff --git a/app/src/main/res/values-sw/strings.xml b/app/src/main/res/values-sw/strings.xml index 78aef9545ae..1cf7fc4433c 100644 --- a/app/src/main/res/values-sw/strings.xml +++ b/app/src/main/res/values-sw/strings.xml @@ -392,6 +392,7 @@ Inaendelea_kuchakata tena_mtazamo_tag Tafadhali chagua angalau chaguo moja. Toleo la programu lisilotumika + Toleo hili la programu halitumiki tena. Tafadhali isasishe kupitia hifadhi ya michezo. Funga programu kwa Weka uwiano katika fomu x:y. diff --git a/scripts/assets/kdoc_validity_exemptions.textproto b/scripts/assets/kdoc_validity_exemptions.textproto index a3aa150b3ef..94f9f14c159 100644 --- a/scripts/assets/kdoc_validity_exemptions.textproto +++ b/scripts/assets/kdoc_validity_exemptions.textproto @@ -4,6 +4,7 @@ exempted_file_path: "app/src/main/java/org/oppia/android/app/application/Applica exempted_file_path: "app/src/main/java/org/oppia/android/app/application/ApplicationStartupListenerModule.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/administratorcontrols/RouteToProfileListListener.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/SurveyOnboardingBackgroundView.kt" +exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragmentPresenter.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsActivityPresenter.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsFragment.kt" exempted_file_path: "app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsFragmentPresenter.kt" From bffbd4b77d1c5409220957836b0e64b72bbd17de Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Tue, 17 Oct 2023 22:10:35 +0300 Subject: [PATCH 12/13] fix: Make minor changes on the code for consistency with the rest of the codebase --- .../android/app/splash/SplashActivity.kt | 11 +------ .../app/splash/SplashActivityPresenter.kt | 10 +++---- ...dAppDeprecationNoticeDialogFragmentTest.kt | 27 ++++++----------- ...lAppDeprecationNoticeDialogFragmentTest.kt | 30 +++++++------------ .../OsDeprecationNoticeDialogFragmentTest.kt | 20 ++++++------- 5 files changed, 35 insertions(+), 63 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt index d1bec798126..84f15baf317 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt @@ -39,7 +39,6 @@ class SplashActivity : AppCompatActivity(), FragmentComponentFactory, DeprecationNoticeExitAppListener, - DeprecationNoticeActionListener, BetaNoticeClosedListener, GeneralAvailabilityUpgradeNoticeClosedListener { @@ -62,15 +61,7 @@ class SplashActivity : return builderInjector.getFragmentComponentBuilderProvider().get().setFragment(fragment).build() } - override fun onActionButtonClicked(noticeType: DeprecationNoticeActionType) { - when (noticeType) { - DeprecationNoticeActionType.CLOSE -> splashActivityPresenter.handleOnCloseAppButtonClicked() - DeprecationNoticeActionType.DISMISS -> splashActivityPresenter.handleOnDismissButtonClicked() - DeprecationNoticeActionType.UPDATE -> splashActivityPresenter.handleOnUpdateButtonClicked() - } - } - - override fun onCloseAppButtonClicked() = splashActivityPresenter.handleOnCloseAppButtonClicked() + override fun onCloseAppButtonClicked() = splashActivityPresenter.handleOnDeprecationNoticeCloseAppButtonClicked() override fun onBetaNoticeOkayButtonClicked(permanentlyDismiss: Boolean) = splashActivityPresenter.handleOnBetaNoticeOkayButtonClicked(permanentlyDismiss) diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt index efb76d0e862..dd926f56612 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivityPresenter.kt @@ -68,14 +68,14 @@ class SplashActivityPresenter @Inject constructor( } /** Handles cases where the user clicks the close app option on a deprecation notice dialog. */ - fun handleOnCloseAppButtonClicked() { + fun handleOnDeprecationNoticeCloseAppButtonClicked() { // If the app close button is clicked for the deprecation notice, finish the activity to close // the app. activity.finish() } - /** Handle cases where the user clicks the update option on a deprecation notice dialog. */ - fun handleOnUpdateButtonClicked() { + /** Handles cases where the user clicks the update option on a deprecation notice dialog. */ + fun handleOnDeprecationNoticeUpdateButtonClicked() { // If the Update button is clicked for the deprecation notice, launch the Play Store and open // the Oppia app's page. val packageName = activity.packageName @@ -99,8 +99,8 @@ class SplashActivityPresenter @Inject constructor( activity.finish() } - /** Handle cases where the user dismisses the deprecation notice dialog. */ - fun handleOnDismissButtonClicked() { + /** Handles cases where the user dismisses the deprecation notice dialog. */ + fun handleOnDeprecationNoticeDialogDismissed() { // If the Dismiss button is clicked for the deprecation notice, the dialog is automatically // dismissed. Navigate to profile chooser activity. activity.startActivity(ProfileChooserActivity.createProfileChooserActivity(activity)) diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt index cb6c9237273..e0fd116c3dc 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt @@ -8,9 +8,10 @@ import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions -import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.RootMatchers.isDialog -import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 import dagger.BindsInstance import dagger.Component @@ -133,8 +134,7 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasExpectedTitle() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView(ViewMatchers.withText(R.string.forced_app_update_dialog_title)) - .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + onDialogView(withText(R.string.forced_app_update_dialog_title)).check(matches(isDisplayed())) } } @@ -146,26 +146,21 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { R.string.forced_app_update_dialog_message, appName ) - onDialogView(ViewMatchers.withText(expectedString)) - .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + onDialogView(withText(expectedString)).check(matches(isDisplayed())) } } @Test fun testFragment_hasUpdateButton() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView( - ViewMatchers.withText(R.string.forced_app_update_dialog_update_button_text) - ).check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + onDialogView(withText(R.string.forced_app_update_dialog_update_button_text)).check(matches(isDisplayed())) } } @Test fun testFragment_clickOnUpdateButton_callsCallbackListener_withUpdateDeprecationActionType() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - clickOnDialogView( - ViewMatchers.withText(R.string.forced_app_update_dialog_update_button_text) - ) + clickOnDialogView(withText(R.string.forced_app_update_dialog_update_button_text)) verify(mockDeprecationNoticeActionListener) .onActionButtonClicked(DeprecationNoticeActionType.UPDATE) @@ -175,18 +170,14 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasCloseAppButton() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView( - ViewMatchers.withText(R.string.forced_app_update_dialog_close_button_text) - ).check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + onDialogView(withText(R.string.forced_app_update_dialog_close_button_text)).check(matches(isDisplayed())) } } @Test fun testFragment_clockOnCloseAppButton_callsCallbackListener_withCloseDeprecationActionType() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - clickOnDialogView( - ViewMatchers.withText(R.string.forced_app_update_dialog_close_button_text) - ) + clickOnDialogView(withText(R.string.forced_app_update_dialog_close_button_text)) verify(mockDeprecationNoticeActionListener) .onActionButtonClicked(DeprecationNoticeActionType.CLOSE) diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt index adf2c2abe5a..6b25761a390 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt @@ -8,9 +8,10 @@ import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso import androidx.test.espresso.action.ViewActions -import androidx.test.espresso.assertion.ViewAssertions -import androidx.test.espresso.matcher.RootMatchers -import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.RootMatchers.isDialog +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 import dagger.BindsInstance import dagger.Component @@ -133,8 +134,7 @@ class OptionalAppDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasExpectedTitle() { launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView(ViewMatchers.withText(R.string.optional_app_update_dialog_title)) - .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + onDialogView(withText(R.string.optional_app_update_dialog_title)).check(matches(isDisplayed())) } } @@ -146,25 +146,21 @@ class OptionalAppDeprecationNoticeDialogFragmentTest { R.string.optional_app_update_dialog_message, appName ) - onDialogView(ViewMatchers.withText(expectedString)) - .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + onDialogView(withText(expectedString)).check(matches(isDisplayed())) } } @Test fun testFragment_hasUpdateButton() { launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView(ViewMatchers.withText(R.string.optional_app_update_dialog_update_button_text)) - .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + onDialogView(withText(R.string.optional_app_update_dialog_update_button_text)).check(matches(isDisplayed())) } } @Test fun testFragment_clickOnUpdateButton_callsCallbackListener_withUpdateDeprecationActionType() { launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { - clickOnDialogView( - ViewMatchers.withText(R.string.optional_app_update_dialog_update_button_text) - ) + clickOnDialogView(withText(R.string.optional_app_update_dialog_update_button_text)) verify(mockDeprecationNoticeActionListener) .onActionButtonClicked(DeprecationNoticeActionType.UPDATE) @@ -174,18 +170,14 @@ class OptionalAppDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasDismissButton() { launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView( - ViewMatchers.withText(R.string.optional_app_update_dialog_dismiss_button_text) - ).check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + onDialogView(withText(R.string.optional_app_update_dialog_dismiss_button_text)).check(matches(isDisplayed())) } } @Test fun testFragment_clickOnDismissButton_callsCallbackListener_withDismissDeprecationActionType() { launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { - clickOnDialogView( - ViewMatchers.withText(R.string.optional_app_update_dialog_dismiss_button_text) - ) + clickOnDialogView(withText(R.string.optional_app_update_dialog_dismiss_button_text)) verify(mockDeprecationNoticeActionListener) .onActionButtonClicked(DeprecationNoticeActionType.DISMISS) @@ -217,7 +209,7 @@ class OptionalAppDeprecationNoticeDialogFragmentTest { private companion object { private fun onDialogView(matcher: Matcher) = Espresso.onView(matcher) - .inRoot(RootMatchers.isDialog()) + .inRoot(isDialog()) } @Singleton diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt index 3be36bf47cf..41907e1aad8 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt @@ -8,9 +8,10 @@ import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso import androidx.test.espresso.action.ViewActions -import androidx.test.espresso.assertion.ViewAssertions -import androidx.test.espresso.matcher.RootMatchers -import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.RootMatchers.isDialog +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.ext.junit.runners.AndroidJUnit4 import dagger.BindsInstance import dagger.Component @@ -133,8 +134,7 @@ class OsDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasExpectedTitle() { launchOsDeprecationNoticeDialogFragmentTestActivity { - onDialogView(ViewMatchers.withText(R.string.os_deprecation_dialog_title)) - .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + onDialogView(withText(R.string.os_deprecation_dialog_title)).check(matches(isDisplayed())) } } @@ -146,23 +146,21 @@ class OsDeprecationNoticeDialogFragmentTest { R.string.os_deprecation_dialog_message, appName ) - onDialogView(ViewMatchers.withText(expectedString)) - .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + onDialogView(withText(expectedString)).check(matches(isDisplayed())) } } @Test fun testFragment_hasDismissButton() { launchOsDeprecationNoticeDialogFragmentTestActivity { - onDialogView(ViewMatchers.withText(R.string.os_deprecation_dialog_dismiss_button_text)) - .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + onDialogView(withText(R.string.os_deprecation_dialog_dismiss_button_text)).check(matches(isDisplayed())) } } @Test fun testFragment_clickOnDismissButton_callsCallbackListener_withDismissDeprecationActionType() { launchOsDeprecationNoticeDialogFragmentTestActivity { - clickOnDialogView(ViewMatchers.withText(R.string.os_deprecation_dialog_dismiss_button_text)) + clickOnDialogView(withText(R.string.os_deprecation_dialog_dismiss_button_text)) verify(mockDeprecationNoticeActionListener) .onActionButtonClicked(DeprecationNoticeActionType.DISMISS) @@ -194,7 +192,7 @@ class OsDeprecationNoticeDialogFragmentTest { private companion object { private fun onDialogView(matcher: Matcher) = Espresso.onView(matcher) - .inRoot(RootMatchers.isDialog()) + .inRoot(isDialog()) } @Singleton From ba44ff68c4c39627fed429bdf0fd9bbc4d2a525d Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Tue, 17 Oct 2023 22:15:08 +0300 Subject: [PATCH 13/13] fix: Fix linting issues --- .../java/org/oppia/android/app/splash/SplashActivity.kt | 7 ++++--- .../ForcedAppDeprecationNoticeDialogFragmentTest.kt | 6 ++++-- .../OptionalAppDeprecationNoticeDialogFragmentTest.kt | 9 ++++++--- .../app/notice/OsDeprecationNoticeDialogFragmentTest.kt | 8 +++++--- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt index 84f15baf317..f9310821ddb 100644 --- a/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt +++ b/app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt @@ -11,7 +11,6 @@ import org.oppia.android.app.fragment.FragmentComponentBuilderInjector import org.oppia.android.app.fragment.FragmentComponentFactory import org.oppia.android.app.model.ScreenName.SPLASH_ACTIVITY import org.oppia.android.app.notice.BetaNoticeClosedListener -import org.oppia.android.app.notice.DeprecationNoticeActionListener import org.oppia.android.app.notice.DeprecationNoticeExitAppListener import org.oppia.android.app.notice.GeneralAvailabilityUpgradeNoticeClosedListener import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.decorateWithScreenName @@ -58,10 +57,12 @@ class SplashActivity : override fun createFragmentComponent(fragment: Fragment): FragmentComponent { val builderInjector = activityComponent as FragmentComponentBuilderInjector - return builderInjector.getFragmentComponentBuilderProvider().get().setFragment(fragment).build() + return builderInjector.getFragmentComponentBuilderProvider().get() + .setFragment(fragment).build() } - override fun onCloseAppButtonClicked() = splashActivityPresenter.handleOnDeprecationNoticeCloseAppButtonClicked() + override fun onCloseAppButtonClicked() = splashActivityPresenter + .handleOnDeprecationNoticeCloseAppButtonClicked() override fun onBetaNoticeOkayButtonClicked(permanentlyDismiss: Boolean) = splashActivityPresenter.handleOnBetaNoticeOkayButtonClicked(permanentlyDismiss) diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt index e0fd116c3dc..d0b1aa4fc7e 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/ForcedAppDeprecationNoticeDialogFragmentTest.kt @@ -153,7 +153,8 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasUpdateButton() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView(withText(R.string.forced_app_update_dialog_update_button_text)).check(matches(isDisplayed())) + onDialogView(withText(R.string.forced_app_update_dialog_update_button_text)) + .check(matches(isDisplayed())) } } @@ -170,7 +171,8 @@ class ForcedAppDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasCloseAppButton() { launchForcedAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView(withText(R.string.forced_app_update_dialog_close_button_text)).check(matches(isDisplayed())) + onDialogView(withText(R.string.forced_app_update_dialog_close_button_text)) + .check(matches(isDisplayed())) } } diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt index 6b25761a390..c9545e4e324 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/OptionalAppDeprecationNoticeDialogFragmentTest.kt @@ -134,7 +134,8 @@ class OptionalAppDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasExpectedTitle() { launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView(withText(R.string.optional_app_update_dialog_title)).check(matches(isDisplayed())) + onDialogView(withText(R.string.optional_app_update_dialog_title)) + .check(matches(isDisplayed())) } } @@ -153,7 +154,8 @@ class OptionalAppDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasUpdateButton() { launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView(withText(R.string.optional_app_update_dialog_update_button_text)).check(matches(isDisplayed())) + onDialogView(withText(R.string.optional_app_update_dialog_update_button_text)) + .check(matches(isDisplayed())) } } @@ -170,7 +172,8 @@ class OptionalAppDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasDismissButton() { launchOptionalAppDeprecationNoticeDialogFragmentTestActivity { - onDialogView(withText(R.string.optional_app_update_dialog_dismiss_button_text)).check(matches(isDisplayed())) + onDialogView(withText(R.string.optional_app_update_dialog_dismiss_button_text)) + .check(matches(isDisplayed())) } } diff --git a/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt index 41907e1aad8..becd031ecdb 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/notice/OsDeprecationNoticeDialogFragmentTest.kt @@ -10,8 +10,8 @@ import androidx.test.espresso.Espresso import androidx.test.espresso.action.ViewActions import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.RootMatchers.isDialog -import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 import dagger.BindsInstance import dagger.Component @@ -134,7 +134,8 @@ class OsDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasExpectedTitle() { launchOsDeprecationNoticeDialogFragmentTestActivity { - onDialogView(withText(R.string.os_deprecation_dialog_title)).check(matches(isDisplayed())) + onDialogView(withText(R.string.os_deprecation_dialog_title)) + .check(matches(isDisplayed())) } } @@ -153,7 +154,8 @@ class OsDeprecationNoticeDialogFragmentTest { @Test fun testFragment_hasDismissButton() { launchOsDeprecationNoticeDialogFragmentTestActivity { - onDialogView(withText(R.string.os_deprecation_dialog_dismiss_button_text)).check(matches(isDisplayed())) + onDialogView(withText(R.string.os_deprecation_dialog_dismiss_button_text)) + .check(matches(isDisplayed())) } }