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

Fix #4450: Add next and previous card options on revision screen #4554

Merged
merged 38 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
05e0966
add functionality for next/prev navigation for revision cards
JishnuGoyal Aug 18, 2022
d5b626b
Merge branch 'develop' into 1.6_revision_screen
JishnuGoyal Sep 5, 2022
1472d69
Merge branch 'develop' into 1.6_revision_screen
JishnuGoyal Sep 9, 2022
5e430f5
update according to changes from develop
JishnuGoyal Sep 9, 2022
23f44b5
fix bad merge with develop
JishnuGoyal Sep 9, 2022
01c56f2
make toolbar orange
JishnuGoyal Sep 9, 2022
6a3cabc
refactor code + add tests
JishnuGoyal Sep 10, 2022
7c51cac
lint/shorten test name
JishnuGoyal Sep 10, 2022
b3d75a4
lint/shorten test name
JishnuGoyal Sep 10, 2022
3d4c9f2
add all refactor jobs
JishnuGoyal Sep 11, 2022
e597b46
requested changes
JishnuGoyal Sep 11, 2022
749576b
add 'scroll to' to tests
JishnuGoyal Sep 13, 2022
5d94adf
add min height and width
JishnuGoyal Sep 14, 2022
8974fa9
remove accidentally added code that led to test failure
JishnuGoyal Sep 24, 2022
645ff38
pre-load subtopic list size
JishnuGoyal Sep 26, 2022
cbac706
lint
JishnuGoyal Sep 26, 2022
2d97c08
piping was not correct
JishnuGoyal Sep 26, 2022
455df90
lint
JishnuGoyal Sep 26, 2022
cc388f7
Merge branch 'develop' into 1.6_revision_screen
JishnuGoyal Sep 27, 2022
aac1b90
lint
JishnuGoyal Sep 27, 2022
a002ae4
disable accessibility checks
JishnuGoyal Sep 27, 2022
ce76896
finish up small left bits
JishnuGoyal Sep 27, 2022
975e4e7
lint
JishnuGoyal Sep 27, 2022
9343f33
commit before checkout
JishnuGoyal Sep 27, 2022
663dde3
partial: Add changes requested in review.
JishnuGoyal Sep 29, 2022
c34c581
lint
JishnuGoyal Sep 29, 2022
b7d93ab
partial: suggested changes
JishnuGoyal Sep 30, 2022
0fb8e9c
kt to binding
JishnuGoyal Sep 30, 2022
cd6a727
kt to xml binding
JishnuGoyal Sep 30, 2022
bb1a7d7
change colors of status bar and toolbar color without using logic
JishnuGoyal Sep 30, 2022
bd1bbf0
lint
JishnuGoyal Sep 30, 2022
994ddb5
fix todo spacing
JishnuGoyal Oct 1, 2022
3c0e64d
wrap up with review comments and fix CI
JishnuGoyal Oct 1, 2022
418ec78
Merge branch 'develop' into 1.6_revision_screen
JishnuGoyal Oct 1, 2022
b122dce
lint
JishnuGoyal Oct 1, 2022
9f8d9ff
text alignment should be right when only next card is visible
JishnuGoyal Oct 1, 2022
8eeecb7
add kdocs
JishnuGoyal Oct 2, 2022
66e10b6
finish up kdocs
JishnuGoyal Oct 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ package org.oppia.android.app.topic.revisioncard

import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.annotation.RequiresApi
import androidx.core.content.res.ResourcesCompat
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAppCompatActivity
import org.oppia.android.app.topic.RouteToRevisionCardListener
import org.oppia.android.app.topic.conceptcard.ConceptCardListener
import javax.inject.Inject

/** Activity for revision card. */
class RevisionCardActivity :
InjectableAppCompatActivity(), ReturnToTopicClickListener, ConceptCardListener {
InjectableAppCompatActivity(),
ReturnToTopicClickListener,
ConceptCardListener,
RouteToRevisionCardListener {

@Inject
lateinit var revisionCardActivityPresenter: RevisionCardActivityPresenter

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
Expand All @@ -29,6 +37,15 @@ class RevisionCardActivity :
val subtopicId = intent.getIntExtra(SUBTOPIC_ID_EXTRA_KEY, -1)
revisionCardActivityPresenter.handleOnCreate(internalProfileId, topicId, subtopicId)
}
supportActionBar?.setBackgroundDrawable(
ResourcesCompat.getDrawable(
resources,
R.color.color_def_oppia_brown_dark,
theme
)
)
window.statusBarColor =
ResourcesCompat.getColor(resources, R.color.color_def_oppia_brown_dark2, theme)
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Expand Down Expand Up @@ -60,6 +77,18 @@ class RevisionCardActivity :
}
}

override fun routeToRevisionCard(internalProfileId: Int, topicId: String, subtopicId: Int) {
startActivity(
createRevisionCardActivityIntent(
this,
internalProfileId,
topicId,
subtopicId
)
)
this.finish()
}

override fun onReturnToTopicClicked() {
onBackPressed()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package org.oppia.android.app.topic.revisioncard
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import org.oppia.android.app.fragment.FragmentScope
import org.oppia.android.app.model.EphemeralSubtopic
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.topic.RouteToRevisionCardListener
import org.oppia.android.app.topic.conceptcard.ConceptCardFragment
import org.oppia.android.app.topic.conceptcard.ConceptCardFragment.Companion.CONCEPT_CARD_DIALOG_FRAGMENT_TAG
import org.oppia.android.app.translation.AppLanguageResourceHandler
Expand All @@ -21,6 +24,7 @@ import javax.inject.Inject
/** Presenter for [RevisionCardFragment], sets up bindings from ViewModel. */
@FragmentScope
class RevisionCardFragmentPresenter @Inject constructor(
activity: AppCompatActivity,
private val fragment: Fragment,
private val oppiaLogger: OppiaLogger,
private val htmlParserFactory: HtmlParser.Factory,
Expand All @@ -31,6 +35,7 @@ class RevisionCardFragmentPresenter @Inject constructor(
private val appLanguageResourceHandler: AppLanguageResourceHandler
) : HtmlParser.CustomOppiaTagActionListener {
private lateinit var profileId: ProfileId
private val routeToReviewListener = activity as RouteToRevisionCardListener

fun handleCreateView(
inflater: LayoutInflater,
Expand Down Expand Up @@ -58,6 +63,8 @@ class RevisionCardFragmentPresenter @Inject constructor(
it.lifecycleOwner = fragment
}

setupRevisionNavigationCards(binding, topicId, subtopicId)

viewModel.revisionCardLiveData.observe(
fragment,
{ ephemeralRevisionCard ->
Expand All @@ -79,6 +86,45 @@ class RevisionCardFragmentPresenter @Inject constructor(
return binding.root
}

private fun setupRevisionNavigationCards(
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
binding: RevisionCardFragmentBinding,
topicId: String,
subtopicId: Int
) {
binding.nextSubtopicImageView.setEntityType(entityType)
binding.prevSubtopicImageView.setEntityType(entityType)

binding.previousNavigationCard.setOnClickListener {
routeToReviewListener.routeToRevisionCard(profileId.internalId, topicId, subtopicId - 1)
}

binding.nextNavigationCard.setOnClickListener {
routeToReviewListener.routeToRevisionCard(profileId.internalId, topicId, subtopicId + 1)
}

getReviewCardViewModel().nextSubtopicLiveData.observe(fragment) { nextSubtopic ->
if (nextSubtopic == EphemeralSubtopic.getDefaultInstance()) {
binding.nextNavigationCard.visibility = View.INVISIBLE
}
binding.nextSubtopicImageView.setLessonThumbnail(nextSubtopic.subtopic.subtopicThumbnail)
binding.nextSubtopicTitle.text = translationController.extractString(
nextSubtopic.subtopic.title,
nextSubtopic.writtenTranslationContext
)
}

getReviewCardViewModel().previousSubtopicLiveData.observe(fragment) { previousSubtopic ->
if (previousSubtopic.equals(EphemeralSubtopic.getDefaultInstance())) {
binding.previousNavigationCard.visibility = View.INVISIBLE
}
binding.prevSubtopicImageView.setLessonThumbnail(previousSubtopic.subtopic.subtopicThumbnail)
binding.prevSubtopicTitle.text = translationController.extractString(
previousSubtopic.subtopic.title,
previousSubtopic.writtenTranslationContext
)
}
}

/** Dismisses the concept card fragment if it's currently active in this fragment. */
fun dismissConceptCard() {
fragment.childFragmentManager.findFragmentByTag(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
import org.oppia.android.app.fragment.FragmentScope
import org.oppia.android.app.model.EphemeralRevisionCard
import org.oppia.android.app.model.EphemeralSubtopic
import org.oppia.android.app.model.EphemeralTopic
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.viewmodel.ObservableViewModel
import org.oppia.android.domain.oppialogger.OppiaLogger
Expand All @@ -21,7 +23,7 @@ class RevisionCardViewModel @Inject constructor(
private val topicController: TopicController,
private val oppiaLogger: OppiaLogger
) : ObservableViewModel() {
private lateinit var topicId: String
lateinit var topicId: String
private var subtopicId: Int = 0
private lateinit var profileId: ProfileId

Expand All @@ -32,6 +34,53 @@ class RevisionCardViewModel @Inject constructor(
processRevisionCardLiveData()
}

private val topicLiveData: LiveData<AsyncResult<EphemeralTopic>> by lazy {
getTopicResultLiveData()
}

private fun getTopicResultLiveData(): LiveData<AsyncResult<EphemeralTopic>> {
return topicController.getTopic(profileId, topicId).toLiveData()
}

val nextSubtopicLiveData: LiveData<EphemeralSubtopic> by lazy {
Transformations.map(topicLiveData, ::processNextSubtopicData)
}

val previousSubtopicLiveData: LiveData<EphemeralSubtopic> by lazy {
Transformations.map(topicLiveData, ::processPreviousSubtopicData)
}

private fun processPreviousSubtopicData(
topicLiveData: AsyncResult<EphemeralTopic>
): EphemeralSubtopic? {
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
return if (subtopicId == 0) EphemeralSubtopic.getDefaultInstance()
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
else {
when (topicLiveData) {
is AsyncResult.Success -> {
val topic = topicLiveData.value
topic.subtopicsList.find {
it.subtopic.subtopicId == subtopicId - 1
} ?: EphemeralSubtopic.getDefaultInstance()
}
else -> EphemeralSubtopic.getDefaultInstance()
}
}
}

private fun processNextSubtopicData(
topicLiveData: AsyncResult<EphemeralTopic>
): EphemeralSubtopic? {
return when (topicLiveData) {
is AsyncResult.Success -> {
val topic = topicLiveData.value
topic.subtopicsList.find {
it.subtopic.subtopicId == subtopicId + 1
} ?: EphemeralSubtopic.getDefaultInstance()
}
else -> EphemeralSubtopic.getDefaultInstance()
}
}

fun clickReturnToTopic(@Suppress("UNUSED_PARAMETER") v: View) {
returnToTopicClickListener.onReturnToTopicClicked()
}
Expand Down
137 changes: 122 additions & 15 deletions app/src/main/res/layout-sw600dp/revision_card_fragment.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

Expand Down Expand Up @@ -34,21 +35,127 @@
style="@style/Body"
android:layout_marginTop="@dimen/revision_card_fragment_layout_text_margin_top" />

<Button
android:id="@+id/revision_card_return_button"
style="@style/StateButtonActive"
android:layout_width="wrap_content"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="@dimen/revision_card_fragment_layout_button_margin_top"
android:background="@drawable/state_button_primary_background"
android:onClick="@{viewModel::clickReturnToTopic}"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/return_to_topic"
android:textAllCaps="true"
android:textColor="@color/color_def_white"
android:textSize="14sp" />
android:layout_marginTop="50dp">

<TextView
android:id="@+id/continue_studying_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginEnd="28dp"
android:text="@string/continue_studying"
android:textColor="@color/color_def_black"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/previous_navigation_card"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="28dp"
android:layout_marginBottom="@dimen/topic_revision_summary_view_container_margin_bottom"
android:clipToPadding="true"
app:cardBackgroundColor="@color/color_def_white"
app:cardCornerRadius="4dp"
app:cardElevation="4dp"
app:cardMaxElevation="4dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/continue_studying_text_view">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<org.oppia.android.app.customview.LessonThumbnailImageView
android:id="@+id/prev_subtopic_image_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:importantForAccessibility="no"
app:entityId="@{viewModel.topicId}"
app:layout_constraintDimensionRatio="H,4:3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/prev_subtopic_title"
style="@style/TextViewStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_def_oppia_brown_dark"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:lines="3"
android:paddingStart="@dimen/topic_revision_summary_view_subtopic_title_text_view_padding_start"
android:paddingTop="8dp"
android:paddingEnd="@dimen/topic_revision_summary_view_subtopic_title_text_view_padding_end"
android:paddingBottom="16dp"
android:textColor="@color/color_def_white"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="@id/prev_subtopic_image_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

<com.google.android.material.card.MaterialCardView
android:id="@+id/next_navigation_card"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="28dp"
android:layout_marginBottom="@dimen/topic_revision_summary_view_container_margin_bottom"
android:clipToPadding="true"
app:cardBackgroundColor="@color/color_def_white"
app:cardCornerRadius="4dp"
app:cardElevation="4dp"
app:cardMaxElevation="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/continue_studying_text_view">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<org.oppia.android.app.customview.LessonThumbnailImageView
android:id="@+id/next_subtopic_image_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:importantForAccessibility="no"
app:entityId="@{viewModel.topicId}"
app:layout_constraintDimensionRatio="H,4:3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/next_subtopic_title"
style="@style/TextViewStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_def_oppia_brown_dark"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:lines="3"
android:paddingStart="@dimen/topic_revision_summary_view_subtopic_title_text_view_padding_start"
android:paddingTop="8dp"
android:paddingEnd="@dimen/topic_revision_summary_view_subtopic_title_text_view_padding_end"
android:paddingBottom="16dp"
android:textColor="@color/color_def_white"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="@id/next_subtopic_image_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Expand Down
Loading