Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3095, #2824: Use protos with intent extras in RecentlyPlayedActivity #4511

Merged
merged 78 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
771778e
RecentlyPlayedActivityParams proto created with ActivityRouter
vrajdesai78 Aug 19, 2022
dcdbe50
Nit changes
vrajdesai78 Aug 19, 2022
39558cd
Optimize imports
vrajdesai78 Aug 19, 2022
4ad3c4c
Merge branch 'develop' into Proto-for-Intent-extras
vrajdesai78 Aug 19, 2022
4c5b5af
Shifted applicationComponent to developerApplicationComponent
vrajdesai78 Aug 19, 2022
a7339b3
Optimized import
vrajdesai78 Aug 19, 2022
519a555
ActivityRouterModule updated
vrajdesai78 Aug 19, 2022
54fb3c1
Updated RECENTLY_PLAYED_ACTIVITY_INTENT_EXTRAS_KEY in ProfileProgress…
vrajdesai78 Aug 19, 2022
dfe1fa0
Static checks fixed
vrajdesai78 Aug 19, 2022
f8b933f
setTitle added in ReceltyPlayedActivityPresenter
vrajdesai78 Aug 19, 2022
c4fd457
bazel added and set title to toolbar
vrajdesai78 Aug 19, 2022
fe671c8
removed unused import
vrajdesai78 Aug 19, 2022
f0c7f49
nit changes
vrajdesai78 Aug 19, 2022
bb29773
test updated and made changes in bazel
vrajdesai78 Aug 20, 2022
ca129fe
dependencies added BUILD.bazel
vrajdesai78 Aug 20, 2022
bba42b7
static and lint checks fixed
vrajdesai78 Aug 20, 2022
8b0c707
protobuf lint issue fixed
vrajdesai78 Aug 20, 2022
2e06677
Revert "protobuf lint issue fixed"
vrajdesai78 Aug 20, 2022
9cbc1a4
protofub lint test fixed
vrajdesai78 Aug 20, 2022
5e03f3c
UNSPECIFIED enum renamed
vrajdesai78 Aug 20, 2022
6202e80
order changed in bazel
vrajdesai78 Aug 20, 2022
d3bd439
src of bazel fixed
vrajdesai78 Aug 21, 2022
8c3979a
dagger deps added in bazel
vrajdesai78 Aug 21, 2022
9675442
KDoc updated for bazel
vrajdesai78 Aug 21, 2022
4d868c3
Merge branch 'develop' into Proto-for-Intent-extras
vrajdesai78 Aug 27, 2022
00c426a
nit changes
vrajdesai78 Aug 27, 2022
6bdc969
Merge branch 'Proto-for-Intent-extras' of https://github.com/vrajdesa…
vrajdesai78 Aug 27, 2022
e6c9559
Revert "nit changes"
vrajdesai78 Aug 27, 2022
e1f3f6c
Merge branch 'new-branch-for-merge' into Proto-for-Intent-extras
vrajdesai78 Aug 27, 2022
cf3e56f
Updated kdoc and optimized code
vrajdesai78 Sep 1, 2022
d4d8c41
Merge to develop
vrajdesai78 Sep 12, 2022
0ccc77f
klint issue fixed
vrajdesai78 Sep 12, 2022
387d3b8
reformated route/BUILD.bazel
vrajdesai78 Sep 12, 2022
bfcb908
regex pattern checks fixed
vrajdesai78 Sep 12, 2022
3ef88c1
optimized import
vrajdesai78 Sep 12, 2022
158f9bd
Nit changes
vrajdesai78 Sep 12, 2022
839080a
Test updated and RecentlyPlayedActivityTitle used
vrajdesai78 Sep 17, 2022
ee1a545
Optimized import
vrajdesai78 Sep 17, 2022
0ccf9a6
Added newline EOF
vrajdesai78 Sep 17, 2022
06634ef
ActivityRouter added to bazel
vrajdesai78 Sep 17, 2022
b7a0b3b
reformat bazel
vrajdesai78 Sep 17, 2022
3384611
corrected path
vrajdesai78 Sep 17, 2022
6193973
made nit changes
vrajdesai78 Sep 22, 2022
c4bee7f
Merged with develop and done nit changes
vrajdesai78 Sep 22, 2022
062c29a
Nit changes
vrajdesai78 Sep 22, 2022
d1ed34e
added new line
vrajdesai78 Sep 22, 2022
151292f
New approach implemented for dagger
vrajdesai78 Sep 27, 2022
891cc90
code optimized
vrajdesai78 Sep 27, 2022
ccab9b4
Fix broken builds for #4511.
BenHenning Sep 29, 2022
2ef5e87
Fixed intentname failing tests
vrajdesai78 Sep 30, 2022
75d9eb0
Imports optimized
vrajdesai78 Sep 30, 2022
cb475ac
Added tests for ActivityRouter and ActivityRouterModule
vrajdesai78 Oct 1, 2022
f451213
optimized code
vrajdesai78 Oct 1, 2022
5f7e2a2
Merge branch 'develop' into Proto-for-Intent-extras
vrajdesai78 Oct 1, 2022
53203f8
Added KDoc and ActivityRouter in bazel
vrajdesai78 Oct 1, 2022
5bd3cfb
Merge branch 'Proto-for-Intent-extras' of https://github.com/vrajdesa…
vrajdesai78 Oct 1, 2022
0ab0840
fixed typo
vrajdesai78 Oct 1, 2022
8cf6c60
removed practicetab
vrajdesai78 Oct 1, 2022
56a191c
ActivityRouterModule added in BottomSheetOptionsMenu
vrajdesai78 Oct 1, 2022
5f10a78
Optimized imports
vrajdesai78 Oct 1, 2022
0e0c2de
Updated failing tests
vrajdesai78 Oct 1, 2022
fa33c5c
Added activityRouterModule in Intrumentation
vrajdesai78 Oct 1, 2022
c241e14
removed activity_router_module from bazel in Instrumentation
vrajdesai78 Oct 1, 2022
ed56d9f
removed activityRouterModule from LogReportingModuleTest
vrajdesai78 Oct 1, 2022
926b761
removed activity_component_factory from bazel in route/BUILD.bazel
vrajdesai78 Oct 1, 2022
da393f1
Nit changes
vrajdesai78 Oct 1, 2022
2fe5926
Optimized import
vrajdesai78 Oct 1, 2022
4fffe58
Tests for ActivityRouter and ActivityRouterModule updated
vrajdesai78 Oct 4, 2022
2792a39
Optimized code for null safety in ProfileProgressHeaderViewModel
vrajdesai78 Oct 4, 2022
211f6ad
Optimized code
vrajdesai78 Oct 4, 2022
5a72a21
Updated KDoc
vrajdesai78 Oct 4, 2022
451500f
Updated kDoc
vrajdesai78 Oct 4, 2022
9c06752
Nit changes
vrajdesai78 Oct 5, 2022
6c8221c
Added new tests and updated ActivityRouter to fix failing CI
vrajdesai78 Oct 5, 2022
3c141fb
Update app/src/sharedTest/java/org/oppia/android/app/profileprogress/…
vrajdesai78 Oct 5, 2022
19b8fa3
Revert "Update app/src/sharedTest/java/org/oppia/android/app/profilep…
vrajdesai78 Oct 5, 2022
13cb226
Updated testname
vrajdesai78 Oct 5, 2022
b59c5f1
Updated logic in ActivityRouter
vrajdesai78 Oct 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
@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
)
}
}
}
}
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,
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
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) {
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
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