diff --git a/app/BUILD.bazel b/app/BUILD.bazel index 33dd48294a5..edd7efe8145 100644 --- a/app/BUILD.bazel +++ b/app/BUILD.bazel @@ -731,6 +731,7 @@ kt_android_library( "//app/src/main/java/org/oppia/android/app/activity:ActivityComponentImpl.kt", "//app/src/main/java/org/oppia/android/app/activity:ActivityIntentFactoriesModule.kt", "//app/src/main/java/org/oppia/android/app/activity:ActivityModule.kt", + "//app/src/main/java/org/oppia/android/app/activity/route:activity_router_module", "//app/src/main/java/org/oppia/android/app/fragment:FragmentComponentBuilderModule.kt", "//app/src/main/java/org/oppia/android/app/fragment:FragmentComponentImpl.kt", "//app/src/main/java/org/oppia/android/app/fragment:FragmentModule.kt", diff --git a/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouter.kt b/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouter.kt index 670cf1225d6..a2c3e43ecfc 100644 --- a/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouter.kt +++ b/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouter.kt @@ -8,20 +8,21 @@ import org.oppia.android.util.logging.ConsoleLogger import javax.inject.Inject /** - * ActivityRouter used to route to given [DestinationScreen]. + * A central router that can navigate the user to a specific activity based on a provided + * [DestinationScreen]. */ class ActivityRouter @Inject constructor( private val activity: AppCompatActivity, private val consoleLogger: ConsoleLogger ) { - /** Checks the value of [DestinationScreen] and routes to different activities accordingly. */ + /** Opens the activity corresponding to the specified [destinationScreen]. */ fun routeToScreen(destinationScreen: DestinationScreen) { - when (destinationScreen.destinationScreenCase) { + when (destinationScreen.destinationScreenCase!!) { DestinationScreen.DestinationScreenCase.RECENTLY_PLAYED_ACTIVITY_PARAMS -> { openRecentlyPlayedActivity(destinationScreen.recentlyPlayedActivityParams) } - else -> { + DestinationScreen.DestinationScreenCase.DESTINATIONSCREEN_NOT_SET -> { consoleLogger.w("ActivityRouter", "Destination screen case is not identified.") } } diff --git a/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouterModule.kt b/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouterModule.kt index a7c1dfbe229..048daa071c0 100644 --- a/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouterModule.kt +++ b/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouterModule.kt @@ -6,7 +6,7 @@ import dagger.multibindings.IntoMap import dagger.multibindings.StringKey import org.oppia.android.app.model.DestinationScreen -/** RouterModule to bind [DestinationScreen]. */ +/** Module to bind [DestinationScreen]. */ @Module class ActivityRouterModule { @Provides diff --git a/app/src/main/java/org/oppia/android/app/activity/route/BUILD.bazel b/app/src/main/java/org/oppia/android/app/activity/route/BUILD.bazel index ef82ba4c0ff..11199abfaae 100644 --- a/app/src/main/java/org/oppia/android/app/activity/route/BUILD.bazel +++ b/app/src/main/java/org/oppia/android/app/activity/route/BUILD.bazel @@ -1,5 +1,5 @@ """ -Constructs for setting up ActivityRoute for injection in the Dagger graph. +Constructs for setting up activity routing support for injection in the Dagger graph. """ load("@dagger//:workspace_defs.bzl", "dagger_rules") @@ -16,7 +16,7 @@ kt_android_library( "ActivityRouterModule.kt", ], visibility = [ - "//app:app_visibility", + "//:oppia_prod_module_visibility", ], deps = [ ":dagger", diff --git a/app/src/main/java/org/oppia/android/app/application/alpha/AlphaApplicationComponent.kt b/app/src/main/java/org/oppia/android/app/application/alpha/AlphaApplicationComponent.kt index 8aa2c20f6bd..19b02633297 100644 --- a/app/src/main/java/org/oppia/android/app/application/alpha/AlphaApplicationComponent.kt +++ b/app/src/main/java/org/oppia/android/app/application/alpha/AlphaApplicationComponent.kt @@ -58,6 +58,7 @@ import org.oppia.android.util.parser.image.ImageParsingModule import org.oppia.android.util.system.OppiaClockModule import org.oppia.android.util.threading.DispatcherModule import javax.inject.Singleton +import org.oppia.android.app.activity.route.ActivityRouterModule /** * Root Dagger component for alpha versions of the application. @@ -83,7 +84,7 @@ import javax.inject.Singleton PlatformParameterModule::class, PlatformParameterSingletonModule::class, ExplorationStorageModule::class, DeveloperOptionsModule::class, PlatformParameterSyncUpWorkerModule::class, NetworkConfigProdModule::class, AssetModule::class, - LocaleProdModule::class, ActivityRecreatorProdModule::class, + LocaleProdModule::class, ActivityRecreatorProdModule::class, ActivityRouterModule::class, NumericExpressionInputModule::class, AlgebraicExpressionInputModule::class, MathEquationInputModule::class, SplitScreenInteractionModule::class, LoggingIdentifierModule::class, ApplicationLifecycleModule::class, diff --git a/app/src/main/java/org/oppia/android/app/application/alphakenya/AlphaKenyaApplicationComponent.kt b/app/src/main/java/org/oppia/android/app/application/alphakenya/AlphaKenyaApplicationComponent.kt index e1d8659e043..4deeb1cdbb2 100644 --- a/app/src/main/java/org/oppia/android/app/application/alphakenya/AlphaKenyaApplicationComponent.kt +++ b/app/src/main/java/org/oppia/android/app/application/alphakenya/AlphaKenyaApplicationComponent.kt @@ -58,6 +58,7 @@ import org.oppia.android.util.parser.image.ImageParsingModule import org.oppia.android.util.system.OppiaClockModule import org.oppia.android.util.threading.DispatcherModule import javax.inject.Singleton +import org.oppia.android.app.activity.route.ActivityRouterModule /** * Root Dagger component for the alpha version of the application specific to a user study in Kenya. @@ -83,7 +84,7 @@ import javax.inject.Singleton PlatformParameterAlphaKenyaModule::class, PlatformParameterSingletonModule::class, ExplorationStorageModule::class, DeveloperOptionsModule::class, PlatformParameterSyncUpWorkerModule::class, NetworkConfigProdModule::class, AssetModule::class, - LocaleProdModule::class, ActivityRecreatorProdModule::class, + LocaleProdModule::class, ActivityRecreatorProdModule::class, ActivityRouterModule::class, NumericExpressionInputModule::class, AlgebraicExpressionInputModule::class, MathEquationInputModule::class, SplitScreenInteractionModule::class, LoggingIdentifierModule::class, ApplicationLifecycleModule::class, diff --git a/app/src/sharedTest/java/org/oppia/android/app/profileprogress/ProfileProgressFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/profileprogress/ProfileProgressFragmentTest.kt index b8dc4a46e37..91e77d62364 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/profileprogress/ProfileProgressFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/profileprogress/ProfileProgressFragmentTest.kt @@ -35,6 +35,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 import com.google.android.material.card.MaterialCardView import com.google.common.truth.Truth.assertThat +import com.google.protobuf.MessageLite import dagger.Component import dagger.Module import dagger.Provides @@ -668,9 +669,10 @@ class ProfileProgressFragmentTest { .setActivityTitle(RecentlyPlayedActivityTitle.RECENTLY_PLAYED_STORIES) .build() clickProfileProgressItem(itemPosition = 0, targetViewId = R.id.view_all_text_view) + intended(hasComponent(RecentlyPlayedActivity::class.java.name)) intended( - hasExtra( + hasProtoExtra( RecentlyPlayedActivity.RECENTLY_PLAYED_ACTIVITY_INTENT_EXTRAS_KEY, recentlyPlayedActivityParams ) @@ -819,6 +821,10 @@ class ProfileProgressFragmentTest { .check(matches(isDisplayed())) } + private fun hasProtoExtra(keyName: String, expectedProto: T): Matcher { + return hasExtra(keyName, expectedProto.toByteString()) + } + @Module class TestModule { // TODO(#59): Either isolate these to their own shared test module, or use the real logging