Skip to content

Commit

Permalink
Fixes #3095, #2824: Use protos with intent extras in RecentlyPlayedAc…
Browse files Browse the repository at this point in the history
…tivity (#4511)

* RecentlyPlayedActivityParams proto created with ActivityRouter

* Nit changes

* Optimize imports

* Shifted applicationComponent to developerApplicationComponent

* Optimized import

* ActivityRouterModule updated

* Updated RECENTLY_PLAYED_ACTIVITY_INTENT_EXTRAS_KEY in ProfileProgressFragmentTest

* Static checks fixed

* setTitle added in ReceltyPlayedActivityPresenter

* bazel added and set title to toolbar

* removed unused import

* nit changes

* test updated and made changes in bazel

* dependencies added BUILD.bazel

* static and lint checks fixed

* protobuf lint issue fixed

* Revert "protobuf lint issue fixed"

This reverts commit 8b0c707.

* protofub lint test fixed

* UNSPECIFIED enum renamed

* order changed in bazel

* src of bazel fixed

* dagger deps added in bazel

* KDoc updated for bazel

* nit changes

* Revert "nit changes"

This reverts commit 00c426a.

* Updated kdoc and optimized code

* klint issue fixed

* reformated route/BUILD.bazel

* regex pattern checks fixed

* optimized import

* Nit changes

* Test updated and RecentlyPlayedActivityTitle used

* Optimized import

* Added newline EOF

* ActivityRouter added to bazel

* reformat bazel

* corrected path

* made nit changes

* Nit changes

* added new line

* New approach implemented for dagger

* code optimized

* Fix broken builds for #4511.

* Fixed intentname failing tests

* Imports optimized

* Added tests for ActivityRouter and ActivityRouterModule

* optimized code

* Added KDoc and ActivityRouter in bazel

* fixed typo

* removed practicetab

* ActivityRouterModule added in BottomSheetOptionsMenu

* Optimized imports

* Updated failing tests

* Added activityRouterModule in Intrumentation

* removed activity_router_module from bazel in Instrumentation

* removed activityRouterModule from LogReportingModuleTest

* removed activity_component_factory from bazel in route/BUILD.bazel

* Nit changes

* Optimized import

* Tests for ActivityRouter and ActivityRouterModule updated

* Optimized code for null safety in ProfileProgressHeaderViewModel

* Optimized code

* Updated KDoc

* Updated kDoc

* Nit changes

* Added new tests and updated ActivityRouter to fix failing CI

* Update app/src/sharedTest/java/org/oppia/android/app/profileprogress/ProfileProgressFragmentTest.kt

Co-authored-by: Ben Henning <[email protected]>

* Revert "Update app/src/sharedTest/java/org/oppia/android/app/profileprogress/ProfileProgressFragmentTest.kt"

This reverts commit 3c141fb.

* Updated testname

* Updated logic in ActivityRouter

Co-authored-by: Ben Henning <[email protected]>
Co-authored-by: Ben Henning <[email protected]>
  • Loading branch information
3 people authored Oct 5, 2022
1 parent 23795b9 commit 162a50e
Show file tree
Hide file tree
Showing 182 changed files with 1,334 additions and 293 deletions.
2 changes: 2 additions & 0 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,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:ActivityRouterModule.kt",
"//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",
Expand All @@ -758,6 +759,7 @@ kt_android_library(
":views",
"//app/src/main/java/org/oppia/android/app/activity:activity_intent_factories_shim",
"//app/src/main/java/org/oppia/android/app/activity:injectable_app_compat_activity",
"//app/src/main/java/org/oppia/android/app/activity/route:activity_router",
"//app/src/main/java/org/oppia/android/app/fragment:injectable_bottom_sheet_dialog_fragment",
"//app/src/main/java/org/oppia/android/app/fragment:injectable_dialog_fragment",
"//app/src/main/java/org/oppia/android/app/fragment:injectable_fragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.oppia.android.app.activity

import android.content.Intent
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.RecentlyPlayedActivityParams

// TODO(#59): Split this up into separate interfaces & move them to the corresponding activities.
// This pattern will probably need to be used for all activities (& maybe fragments) as part of app
Expand Down Expand Up @@ -33,6 +34,6 @@ interface ActivityIntentFactories {
*/
interface RecentlyPlayedActivityIntentFactory {
/** Returns a new [Intent] to start the recently played activity for the specified profile. */
fun createIntent(profileId: ProfileId): Intent
fun createIntent(recentlyPlayedActivityParams: RecentlyPlayedActivityParams): Intent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ kt_android_library(
"//app:app_visibility",
],
deps = [
"//model/src/main/proto:arguments_java_proto_lite",
"//model/src/main/proto:profile_java_proto_lite",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.oppia.android.app.activity.route

import androidx.appcompat.app.AppCompatActivity
import org.oppia.android.app.model.DestinationScreen
import org.oppia.android.app.model.DestinationScreen.DestinationScreenCase
import org.oppia.android.util.logging.ConsoleLogger
import javax.inject.Inject

/**
* 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 destinationRoutes: Map<DestinationScreenCase, @JvmSuppressWildcards Route>,
private val consoleLogger: ConsoleLogger
) {
/** Opens the activity corresponding to the specified [destinationScreen]. */
fun routeToScreen(destinationScreen: DestinationScreen) {
val routeIntent = destinationRoutes[destinationScreen.destinationScreenCase]
?.createIntent(
activity,
destinationScreen
)
if (routeIntent != null) {
activity.startActivity(routeIntent)
} else {
consoleLogger.w("ActivityRouter", "Destination screen case is not identified.")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.oppia.android.app.activity.route

import android.content.Context
import android.content.Intent
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedActivity
import org.oppia.android.app.model.DestinationScreen

/** Module to bind destination screens to navigable activity routes. */
@Module
class ActivityRouterModule {
@Provides
@IntoMap
@RouteKey(DestinationScreen.DestinationScreenCase.RECENTLY_PLAYED_ACTIVITY_PARAMS)
fun provideRecentlyPlayedActivityRoute(): Route {
return object : Route {
override fun createIntent(
context: Context,
destinationScreen: DestinationScreen
): Intent {
return RecentlyPlayedActivity.createRecentlyPlayedActivityIntent(
context,
destinationScreen.recentlyPlayedActivityParams
)
}
}
}
}
29 changes: 29 additions & 0 deletions app/src/main/java/org/oppia/android/app/activity/route/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Constructs for setting up activity routing support in the Dagger graph.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

# TODO(#59): Define these exported files as separate libraries from top-level targets.
exports_files([
"ActivityRouterModule.kt",
])

kt_android_library(
name = "activity_router",
srcs = [
"ActivityRouter.kt",
"Route.kt",
"RouteKey.kt",
],
visibility = ["//:oppia_api_visibility"],
deps = [
":dagger",
"//model/src/main/proto:arguments_java_proto_lite",
"//third_party:androidx_appcompat_appcompat",
"//utility/src/main/java/org/oppia/android/util/logging:console_logger",
],
)

dagger_rules()
20 changes: 20 additions & 0 deletions app/src/main/java/org/oppia/android/app/activity/route/Route.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.oppia.android.app.activity.route

import android.content.Context
import android.content.Intent
import org.oppia.android.app.model.DestinationScreen

/** Represents a possible navigation route to a specific activity in the app. */
interface Route {
/**
* Creates an [Intent] to route to the activity corresponding to this route.
*
* @param context the context to be used for creating the [Intent]
* @param params the parameters to pass to the activity via its extras bundle
* @return the intent that can be used to navigate to this route's activity
*/
fun createIntent(
context: Context,
destinationScreen: DestinationScreen
): Intent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.oppia.android.app.activity.route

import dagger.MapKey
import org.oppia.android.app.model.DestinationScreen

/** Specifies [DestinationScreenCase] which can be used to pass in activity Route. */
@MapKey
annotation class RouteKey(val value: DestinationScreen.DestinationScreenCase)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oppia.android.app.application.alpha

import dagger.Component
import org.oppia.android.app.activity.route.ActivityRouterModule
import org.oppia.android.app.application.ApplicationComponent
import org.oppia.android.app.application.ApplicationModule
import org.oppia.android.app.application.ApplicationStartupListenerModule
Expand Down Expand Up @@ -87,7 +88,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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oppia.android.app.application.alphakenya

import dagger.Component
import org.oppia.android.app.activity.route.ActivityRouterModule
import org.oppia.android.app.application.ApplicationComponent
import org.oppia.android.app.application.ApplicationModule
import org.oppia.android.app.application.ApplicationStartupListenerModule
Expand Down Expand Up @@ -88,7 +89,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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oppia.android.app.application.beta

import dagger.Component
import org.oppia.android.app.activity.route.ActivityRouterModule
import org.oppia.android.app.application.ApplicationComponent
import org.oppia.android.app.application.ApplicationModule
import org.oppia.android.app.application.ApplicationStartupListenerModule
Expand Down Expand Up @@ -96,7 +97,7 @@ import javax.inject.Singleton
HintsAndSolutionProdModule::class, MetricLogSchedulerModule::class,
ActivityLifecycleObserverModule::class, PerformanceMetricsAssessorModule::class,
PerformanceMetricsConfigurationsModule::class, BetaBuildFlavorModule::class,
EventLoggingConfigurationModule::class
EventLoggingConfigurationModule::class, ActivityRouterModule::class
]
)
interface BetaApplicationComponent : ApplicationComponent {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oppia.android.app.application.dev

import dagger.Component
import org.oppia.android.app.activity.route.ActivityRouterModule
import org.oppia.android.app.application.ApplicationComponent
import org.oppia.android.app.application.ApplicationModule
import org.oppia.android.app.application.ApplicationStartupListenerModule
Expand Down Expand Up @@ -90,7 +91,7 @@ import javax.inject.Singleton
ExplorationStorageModule::class, DeveloperOptionsStarterModule::class,
DeveloperOptionsModule::class, PlatformParameterSyncUpWorkerModule::class,
NetworkConnectionUtilDebugModule::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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oppia.android.app.application.ga

import dagger.Component
import org.oppia.android.app.activity.route.ActivityRouterModule
import org.oppia.android.app.application.ApplicationComponent
import org.oppia.android.app.application.ApplicationModule
import org.oppia.android.app.application.ApplicationStartupListenerModule
Expand Down Expand Up @@ -96,7 +97,7 @@ import javax.inject.Singleton
HintsAndSolutionProdModule::class, MetricLogSchedulerModule::class,
ActivityLifecycleObserverModule::class, PerformanceMetricsAssessorModule::class,
PerformanceMetricsConfigurationsModule::class, GaBuildFlavorModule::class,
EventLoggingConfigurationModule::class
EventLoggingConfigurationModule::class, ActivityRouterModule::class
]
)
interface GaApplicationComponent : ApplicationComponent {
Expand Down
27 changes: 20 additions & 7 deletions app/src/main/java/org/oppia/android/app/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import android.os.Bundle
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAppCompatActivity
import org.oppia.android.app.activity.route.ActivityRouter
import org.oppia.android.app.drawer.ExitProfileDialogFragment
import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY
import org.oppia.android.app.drawer.TAG_SWITCH_PROFILE_DIALOG
import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedActivity
import org.oppia.android.app.model.DestinationScreen
import org.oppia.android.app.model.ExitProfileDialogArguments
import org.oppia.android.app.model.HighlightItem
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.RecentlyPlayedActivityParams
import org.oppia.android.app.model.RecentlyPlayedActivityTitle
import org.oppia.android.app.model.ScreenName.HOME_ACTIVITY
import org.oppia.android.app.topic.TopicActivity
import org.oppia.android.app.translation.AppLanguageResourceHandler
Expand All @@ -30,6 +34,9 @@ class HomeActivity :
@Inject
lateinit var resourceHandler: AppLanguageResourceHandler

@Inject
lateinit var activityRouter: ActivityRouter

private var internalProfileId: Int = -1

companion object {
Expand Down Expand Up @@ -85,12 +92,18 @@ class HomeActivity :
)
}

override fun routeToRecentlyPlayed() {
startActivity(
RecentlyPlayedActivity.createRecentlyPlayedActivityIntent(
this,
internalProfileId
)
override fun routeToRecentlyPlayed(recentlyPlayedActivityTitle: RecentlyPlayedActivityTitle) {
val recentlyPlayedActivityParams =
RecentlyPlayedActivityParams
.newBuilder()
.setProfileId(ProfileId.newBuilder().setInternalId(internalProfileId).build())
.setActivityTitle(recentlyPlayedActivityTitle).build()

activityRouter.routeToScreen(
DestinationScreen
.newBuilder()
.setRecentlyPlayedActivityParams(recentlyPlayedActivityParams)
.build()
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.oppia.android.app.home

import org.oppia.android.app.model.RecentlyPlayedActivityTitle

/** Listener for when an activity should route to [RecentlyPlayedActivity]. */
interface RouteToRecentlyPlayedListener {
fun routeToRecentlyPlayed()
fun routeToRecentlyPlayed(recentlyPlayedActivityTitle: RecentlyPlayedActivityTitle)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.oppia.android.R
import org.oppia.android.app.home.HomeItemViewModel
import org.oppia.android.app.home.RouteToRecentlyPlayedListener
import org.oppia.android.app.model.PromotedActivityList
import org.oppia.android.app.model.RecentlyPlayedActivityTitle
import org.oppia.android.app.translation.AppLanguageResourceHandler
import java.util.Objects

Expand Down Expand Up @@ -49,6 +50,26 @@ class PromotedStoryListViewModel(
}
}

private fun getRecentlyPlayedActivityTitle(): RecentlyPlayedActivityTitle {
with(promotedActivityList.promotedStoryList) {
return when {
suggestedStoryList.isNotEmpty() -> {
if (recentlyPlayedStoryList.isEmpty() && olderPlayedStoryList.isEmpty()) {
RecentlyPlayedActivityTitle.RECOMMENDED_STORIES
} else {
RecentlyPlayedActivityTitle.STORIES_FOR_YOU
}
}
recentlyPlayedStoryList.isNotEmpty() -> {
RecentlyPlayedActivityTitle.RECENTLY_PLAYED_STORIES
}
else -> {
RecentlyPlayedActivityTitle.LAST_PLAYED_STORIES
}
}
}
}

/** Returns the visibility for the "View All" button. */
fun getViewAllButtonVisibility(): Int {
if (activity.resources.getBoolean(R.bool.isTablet)) {
Expand All @@ -72,7 +93,7 @@ class PromotedStoryListViewModel(
}

fun clickOnViewAll() {
routeToRecentlyPlayedListener.routeToRecentlyPlayed()
routeToRecentlyPlayedListener.routeToRecentlyPlayed(getRecentlyPlayedActivityTitle())
}

// Overriding equals is needed so that DataProvider combine functions used in the HomeViewModel
Expand Down
Loading

0 comments on commit 162a50e

Please sign in to comment.