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
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
Expand Up @@ -9,6 +9,7 @@ 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.home.recentlyplayed.RecentlyPlayedTitleEnum
import org.oppia.android.app.model.ExitProfileDialogArguments
import org.oppia.android.app.model.HighlightItem
import org.oppia.android.app.topic.TopicActivity
Expand Down Expand Up @@ -80,7 +81,8 @@ class HomeActivity :
startActivity(
RecentlyPlayedActivity.createRecentlyPlayedActivityIntent(
this,
internalProfileId
internalProfileId,
RecentlyPlayedTitleEnum.STORIES_FOR_YOU
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,29 @@ class RecentlyPlayedActivity : InjectableAppCompatActivity(), RouteToExploration
RECENTLY_PLAYED_ACTIVITY_INTERNAL_PROFILE_ID_KEY,
-1
)
recentlyPlayedActivityPresenter.handleOnCreate(internalProfileId)
val recentlyPlayedTitleEnum =
intent.getSerializableExtra(RECENTLY_PLAYED_ACTIVITY_TITLE_ENUM_KEY)
as RecentlyPlayedTitleEnum
recentlyPlayedActivityPresenter.handleOnCreate(internalProfileId, recentlyPlayedTitleEnum)
}

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"

internal const val RECENTLY_PLAYED_ACTIVITY_TITLE_ENUM_KEY =
"RecentlyPlayedActivity.title_enum_key"

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

Choose a reason for hiding this comment

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

This seems reasonable to me, but I think we want to do a push toward using protos more aggressively for sending arguments & intent extras. Maybe just go ahead and define an intent extra proto for this activity & use that, instead? It means a less-clean enum but you could still create an extension function for getTitleFromStringRes to keep dependent code clean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried to use protos. I am not sure if its correct so do let me know WDYT.

  1. DestinationScreen will helps to identify which activity to open and also with what intent extra values.
  2. For example for this implementation, RecentlyPlayedActivityIntentExtras is a value inside DestinationScreen which contains information about the destination activity as well as its intent extras.
  3. In activity package I have created ActivityRouter which will be injected to all activities / fragments from where we want to start the next activity. In this we will call routeToScreen with correct DestinationScreen and then this will decide which activity should be started.
  4. One added code clarity point: With this approach we can change RecentlyPlayedActivityIntentExtras proto anytime it will be very easy to make changes to code. For example in current develop as I had to send an enum I had to introduced a new key and change the createRecentlyPlayedActivityIntent function by introducing a new argument which in turn resulted in changes in all the instances where that function was getting called. But with this new approach these changes will be comparatively less.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I was just thinking that you could pass a RecentlyPlayedActivityIntentExtras proto here & proceed similarly. The router approach seems much nicer. Do you want to do that change as part of this PR or separately?

return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
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.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(internalProfileId: Int, recentlyPlayedTitleEnum: RecentlyPlayedTitleEnum) {
activity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
activity.supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp)
activity.title = recentlyPlayedTitleEnum.getTitleFromStringRes(activity)
val binding =
DataBindingUtil.setContentView<RecentlyPlayedActivityBinding>(
activity,
R.layout.recently_played_activity
)

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

binding.recentlyPlayedToolbar.title = recentlyPlayedTitleEnum.getTitleFromStringRes(activity)
if (getRecentlyPlayedFragment() == null) {
activity.supportFragmentManager.beginTransaction().add(
R.id.recently_played_fragment_placeholder,
Expand Down
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
@@ -0,0 +1,16 @@
package org.oppia.android.app.home.recentlyplayed

import android.content.Context
import androidx.annotation.StringRes
import org.oppia.android.R

/** Represents different titles for RecentlyPlayedActivity used by screen readers. */
enum class RecentlyPlayedTitleEnum(@StringRes private var title: Int) {
RECENTLY_PLAYED_STORIES(R.string.recently_played_stories),
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't this using recently_played_activity_title?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. Used recently_played_activity_title

STORIES_FOR_YOU(R.string.stories_for_you);

/** Returns the string corresponding to this error's string resources, or null if there is none. */
fun getTitleFromStringRes(context: Context): String? {
return title.let(context::getString)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fun getTitleFromStringRes(context: Context): String? {
return title.let(context::getString)
}
fun getTitleFromStringRes(context: Context): String? = context.getString(title)

The scope function way seems less readable to me, but YMMV. I also changed this to an optional single-assignment syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated as per suggestion.

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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.home.recentlyplayed.RecentlyPlayedTitleEnum
import org.oppia.android.app.ongoingtopiclist.OngoingTopicListActivity
import javax.inject.Inject

Expand All @@ -33,7 +34,8 @@ class ProfileProgressActivity :
startActivity(
RecentlyPlayedActivity.createRecentlyPlayedActivityIntent(
this,
internalProfileId
internalProfileId,
RecentlyPlayedTitleEnum.RECENTLY_PLAYED_STORIES
)
)
}
Expand Down
58 changes: 0 additions & 58 deletions app/src/main/res/layout-land/recently_played_fragment.xml

This file was deleted.

This file was deleted.

This file was deleted.

60 changes: 54 additions & 6 deletions app/src/main/res/layout/recently_played_activity.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recently_played_fragment_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".app.home.recentlyplayed.RecentlyPlayedActivity" />
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/recently_played_app_bar_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<androidx.appcompat.widget.Toolbar
android:id="@+id/recently_played_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fontFamily="sans-serif"
android:minHeight="?attr/actionBarSize"
app:navigationContentDescription="@string/navigate_up"
app:navigationIcon="?attr/homeAsUpIndicator"
app:title="@string/recently_played_activity_title"
app:titleTextAppearance="@style/ToolbarTextAppearance"
app:titleTextColor="@color/white" />
</com.google.android.material.appbar.AppBarLayout>

<FrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/recently_played_app_bar_layout">

<FrameLayout
android:id="@+id/recently_played_fragment_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<View
android:layout_width="match_parent"
android:layout_height="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/recently_played_app_bar_layout" />
Copy link
Member

Choose a reason for hiding this comment

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

Is it value to have constraints when within a layout being constrained? Do we eve need these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These constraints are incorrect. Removed now.

</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Loading