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 #2824: [A11y] Add label for RecentlyPlayedActivity #3065

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
android:theme="@style/OppiaThemeWithoutActionBar" />
<activity
android:name=".app.home.recentlyplayed.RecentlyPlayedActivity"
android:label="@string/recently_played_activity_title"
android:theme="@style/OppiaThemeWithoutActionBar" />
<activity
android:name=".app.mydownloads.MyDownloadsActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.oppia.android.app.activity

import androidx.appcompat.app.AppCompatActivity
import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedActivity
import org.oppia.android.app.model.DestinationScreen
import org.oppia.android.app.model.RecentlyPlayedActivityIntentExtras
import javax.inject.Inject

/** Central utility to manage routing to different activities. */
class ActivityRouter @Inject constructor(private val activity: AppCompatActivity) {

/** Checks the value of [DestinationScreen] and routes to different activities accordingly. */
fun routeToScreen(destinationScreen: DestinationScreen) {
if (destinationScreen.destinationScreenCase ==
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a when statement, instead? Maybe also use 'return' to force it to be exhaustive.

DestinationScreen.DestinationScreenCase.RECENTLY_PLAYED_ACTIVITY_INTENT_EXTRAS
) {
openRecentlyPlayedActivity(destinationScreen.recentlyPlayedActivityIntentExtras)
}
}

private fun openRecentlyPlayedActivity(
recentlyPlayedActivityIntentExtras: RecentlyPlayedActivityIntentExtras
) {
activity.startActivity(
RecentlyPlayedActivity.createRecentlyPlayedActivityIntent(
activity,
recentlyPlayedActivityIntentExtras
)
)
}
}
41 changes: 34 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 @@ -4,13 +4,17 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityRouter
import org.oppia.android.app.activity.InjectableAppCompatActivity
import org.oppia.android.app.drawer.ExitProfileDialogFragment
import org.oppia.android.app.drawer.KEY_NAVIGATION_PROFILE_ID
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.RecentlyPlayedActivityIntentExtras
import org.oppia.android.app.model.RecentlyPlayedActivityTitle
import org.oppia.android.app.topic.TopicActivity
import javax.inject.Inject

Expand All @@ -24,6 +28,9 @@ class HomeActivity :
lateinit var homeActivityPresenter: HomeActivityPresenter
private var internalProfileId: Int = -1

@Inject
lateinit var activityRouter: ActivityRouter

companion object {
fun createHomeActivity(context: Context, profileId: Int?): Intent {
val intent = Intent(context, HomeActivity::class.java)
Expand Down Expand Up @@ -76,12 +83,32 @@ class HomeActivity :
)
}

override fun routeToRecentlyPlayed() {
startActivity(
RecentlyPlayedActivity.createRecentlyPlayedActivityIntent(
this,
internalProfileId
)
override fun routeToRecentlyPlayed(title: String) {
val recentlyPlayedActivityIntentExtras =
RecentlyPlayedActivityIntentExtras
.newBuilder()
.setProfileId(
ProfileId.newBuilder().setInternalId(internalProfileId).build()
)
.setActivityTitle(
when (title) {
getString(R.string.stories_for_you) -> {
RecentlyPlayedActivityTitle.STORIES_FOR_YOU
}
getString(R.string.recently_played_activity_title) -> {
RecentlyPlayedActivityTitle.RECENTLY_PLAYED_STORIES
}
else -> {
RecentlyPlayedActivityTitle.RECENTLY_PLAYED_STORIES
}
}
).build()

activityRouter.routeToScreen(
DestinationScreen
.newBuilder()
.setRecentlyPlayedActivityIntentExtras(recentlyPlayedActivityIntentExtras)
.build()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package org.oppia.android.app.home

/** Listener for when an activity should route to [RecentlyPlayedActivity]. */
interface RouteToRecentlyPlayedListener {
fun routeToRecentlyPlayed()
fun routeToRecentlyPlayed(title: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PromotedStoryListViewModel(
}

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

// Overriding equals is needed so that DataProvider combine functions used in the HomeViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.os.Bundle
import org.oppia.android.app.activity.InjectableAppCompatActivity
import org.oppia.android.app.home.RouteToExplorationListener
import org.oppia.android.app.model.RecentlyPlayedActivityIntentExtras
import org.oppia.android.app.player.exploration.ExplorationActivity
import javax.inject.Inject

Expand All @@ -17,22 +18,27 @@ class RecentlyPlayedActivity : InjectableAppCompatActivity(), RouteToExploration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityComponent.inject(this)
val internalProfileId = intent.getIntExtra(
RECENTLY_PLAYED_ACTIVITY_INTERNAL_PROFILE_ID_KEY,
-1
val recentlyPlayedActivityIntentExtras = RecentlyPlayedActivityIntentExtras.parseFrom(
intent.getByteArrayExtra(RECENTLY_PLAYED_ACTIVITY_INTENT_EXTRAS)
)
recentlyPlayedActivityPresenter.handleOnCreate(internalProfileId)

recentlyPlayedActivityPresenter.handleOnCreate(recentlyPlayedActivityIntentExtras)
}

companion object {
// TODO(#1655): Re-restrict access to fields in tests post-Gradle.
const val RECENTLY_PLAYED_ACTIVITY_INTERNAL_PROFILE_ID_KEY =
"RecentlyPlayedActivity.internal_profile_id"
const val RECENTLY_PLAYED_ACTIVITY_INTENT_EXTRAS = "RecentlyPlayedActivity.intent_extras"

/** Returns a new [Intent] to route to [RecentlyPlayedActivity]. */
fun createRecentlyPlayedActivityIntent(context: Context, internalProfileId: Int): Intent {
fun createRecentlyPlayedActivityIntent(
context: Context,
recentlyPlayedActivityIntentExtras: RecentlyPlayedActivityIntentExtras
): Intent {
val intent = Intent(context, RecentlyPlayedActivity::class.java)
intent.putExtra(RECENTLY_PLAYED_ACTIVITY_INTERNAL_PROFILE_ID_KEY, internalProfileId)
intent.putExtra(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RECENTLY_PLAYED_ACTIVITY_INTENT_EXTRAS,
recentlyPlayedActivityIntentExtras.toByteArray()
)
return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
package org.oppia.android.app.home.recentlyplayed

import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityScope
import org.oppia.android.app.model.RecentlyPlayedActivityIntentExtras
import org.oppia.android.app.model.RecentlyPlayedActivityTitle
import org.oppia.android.databinding.RecentlyPlayedActivityBinding
import javax.inject.Inject

/** The presenter for [RecentlyPlayedActivity]. */
@ActivityScope
class RecentlyPlayedActivityPresenter @Inject constructor(private val activity: AppCompatActivity) {
fun handleOnCreate(internalProfileId: Int) {
activity.setContentView(R.layout.recently_played_activity)
fun handleOnCreate(recentlyPlayedActivityIntentExtras: RecentlyPlayedActivityIntentExtras) {
activity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
activity.supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp)
activity.title = getTitle(recentlyPlayedActivityIntentExtras)
val binding =
DataBindingUtil.setContentView<RecentlyPlayedActivityBinding>(
activity,
R.layout.recently_played_activity
)

binding.recentlyPlayedToolbar.setNavigationOnClickListener {
(activity as RecentlyPlayedActivity).finish()
}

binding.recentlyPlayedToolbar.title = getTitle(recentlyPlayedActivityIntentExtras)
if (getRecentlyPlayedFragment() == null) {
activity.supportFragmentManager.beginTransaction().add(
R.id.recently_played_fragment_placeholder,
RecentlyPlayedFragment.newInstance(internalProfileId),
RecentlyPlayedFragment.newInstance(recentlyPlayedActivityIntentExtras.profileId.internalId),
RecentlyPlayedFragment.TAG_RECENTLY_PLAYED_FRAGMENT
).commitNow()
}
Expand All @@ -24,4 +41,20 @@ class RecentlyPlayedActivityPresenter @Inject constructor(private val activity:
R.id.recently_played_fragment_placeholder
) as RecentlyPlayedFragment?
}

private fun getTitle(
recentlyPlayedActivityIntentExtras: RecentlyPlayedActivityIntentExtras
): String {
return when (recentlyPlayedActivityIntentExtras.activityTitle) {
RecentlyPlayedActivityTitle.RECENTLY_PLAYED_STORIES -> {
activity.getString(R.string.recently_played_activity_title)
}
RecentlyPlayedActivityTitle.STORIES_FOR_YOU -> {
activity.getString(R.string.stories_for_you)
}
else -> {
activity.getString(R.string.recently_played_activity_title)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
internalProfileId: Int
): View? {
binding = RecentlyPlayedFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding.recentlyPlayedToolbar.setNavigationOnClickListener {
(activity as RecentlyPlayedActivity).finish()
}

this.internalProfileId = internalProfileId

Expand All @@ -77,17 +74,14 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
fragment,
{
if (it.promotedStoryList.recentlyPlayedStoryList.isNotEmpty()) {
binding.recentlyPlayedToolbar.title = activity.getString(R.string.recently_played_stories)
addRecentlyPlayedStoryListSection(it.promotedStoryList.recentlyPlayedStoryList)
}

if (it.promotedStoryList.olderPlayedStoryList.isNotEmpty()) {
binding.recentlyPlayedToolbar.title = activity.getString(R.string.recently_played_stories)
addOlderStoryListSection(it.promotedStoryList.olderPlayedStoryList)
}

if (it.promotedStoryList.suggestedStoryList.isNotEmpty()) {
binding.recentlyPlayedToolbar.title = activity.getString(R.string.stories_for_you)
addRecommendedStoryListSection(it.promotedStoryList.suggestedStoryList)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ package org.oppia.android.app.profileprogress
import android.content.Context
import android.content.Intent
import android.os.Bundle
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityRouter
import org.oppia.android.app.activity.InjectableAppCompatActivity
import org.oppia.android.app.completedstorylist.CompletedStoryListActivity
import org.oppia.android.app.home.RouteToRecentlyPlayedListener
import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedActivity
import org.oppia.android.app.model.DestinationScreen
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.RecentlyPlayedActivityIntentExtras
import org.oppia.android.app.model.RecentlyPlayedActivityTitle
import org.oppia.android.app.ongoingtopiclist.OngoingTopicListActivity
import javax.inject.Inject

Expand All @@ -20,6 +25,10 @@ class ProfileProgressActivity :

@Inject
lateinit var profileProgressActivityPresenter: ProfileProgressActivityPresenter

@Inject
lateinit var activityRouter: ActivityRouter

private var internalProfileId = -1

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -29,12 +38,32 @@ class ProfileProgressActivity :
profileProgressActivityPresenter.handleOnCreate(internalProfileId)
}

override fun routeToRecentlyPlayed() {
startActivity(
RecentlyPlayedActivity.createRecentlyPlayedActivityIntent(
this,
internalProfileId
)
override fun routeToRecentlyPlayed(title: String) {
val recentlyPlayedActivityIntentExtras =
RecentlyPlayedActivityIntentExtras
.newBuilder()
.setProfileId(
ProfileId.newBuilder().setInternalId(internalProfileId).build()
)
.setActivityTitle(
when (title) {
getString(R.string.stories_for_you) -> {
RecentlyPlayedActivityTitle.STORIES_FOR_YOU
}
getString(R.string.recently_played_activity_title) -> {
RecentlyPlayedActivityTitle.RECENTLY_PLAYED_STORIES
}
else -> {
RecentlyPlayedActivityTitle.RECENTLY_PLAYED_STORIES
}
}
).build()

activityRouter.routeToScreen(
DestinationScreen
.newBuilder()
.setRecentlyPlayedActivityIntentExtras(recentlyPlayedActivityIntentExtras)
.build()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.ObservableField
import androidx.fragment.app.Fragment
import org.oppia.android.R
import org.oppia.android.app.home.RouteToRecentlyPlayedListener
import org.oppia.android.app.model.Profile

/** Header [ViewModel] for the recycler view in [ProfileProgressFragment]. */
class ProfileProgressHeaderViewModel(activity: AppCompatActivity, fragment: Fragment) :
class ProfileProgressHeaderViewModel(private val activity: AppCompatActivity, fragment: Fragment) :
ProfileProgressItemViewModel() {
private val routeToCompletedStoryListListener = activity as RouteToCompletedStoryListListener
private val routeToOngoingTopicListListener = activity as RouteToOngoingTopicListListener
Expand Down Expand Up @@ -42,7 +43,9 @@ class ProfileProgressHeaderViewModel(activity: AppCompatActivity, fragment: Frag
}

fun clickOnViewAll() {
routeToRecentlyPlayedActivity.routeToRecentlyPlayed()
routeToRecentlyPlayedActivity.routeToRecentlyPlayed(
activity.getString(R.string.recently_played_activity_title)
)
}

fun clickOnProfilePicture() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,4 @@ interface IntentFactoryShim {
internalProfileId: Int,
topicId: String
): Intent

/**
* Creates a [RecentlyPlayedActivity] intent for [PromotedStoryListViewModel] and passes
* necessary string data.
* */
fun createRecentlyPlayedActivityIntent(context: Context, internalProfileId: Int): Intent
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.content.Intent
import androidx.fragment.app.FragmentActivity
import org.oppia.android.app.drawer.KEY_NAVIGATION_PROFILE_ID
import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedActivity
import org.oppia.android.app.profile.ProfileChooserActivity
import org.oppia.android.app.topic.TopicActivity
import javax.inject.Inject
Expand Down Expand Up @@ -58,20 +57,4 @@ class IntentFactoryShimImpl @Inject constructor() : IntentFactoryShim {
intent.putExtra(TOPIC_ACTIVITY_TOPIC_ID_ARGUMENT_KEY, topicId)
return intent
}

/**
* Creates a [RecentlyPlayedActivity] intent for [PromotedStoryListViewModel] and passes
* necessary string data.
* */
override fun createRecentlyPlayedActivityIntent(
context: Context,
internalProfileId: Int
): Intent {
val intent = Intent(context, RecentlyPlayedActivity::class.java)
intent.putExtra(
RecentlyPlayedActivity.RECENTLY_PLAYED_ACTIVITY_INTERNAL_PROFILE_ID_KEY,
internalProfileId
)
return intent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ class HomeFragmentTestActivity :
// Override functions are needed to fulfill listener definitions.
override fun routeToTopic(internalProfileId: Int, topicId: String) {}
override fun routeToTopicPlayStory(internalProfileId: Int, topicId: String, storyId: String) {}
override fun routeToRecentlyPlayed() {}
override fun routeToRecentlyPlayed(title: String) {}
}
Loading