Skip to content

Commit

Permalink
Merge branch 'develop' into comparable-operation-subject-test
Browse files Browse the repository at this point in the history
  • Loading branch information
theayushyadav11 authored Jan 30, 2025
2 parents f76bb9b + 4f58be9 commit 90bf370
Show file tree
Hide file tree
Showing 31 changed files with 759 additions and 54 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/static_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ jobs:
run: |
bazel run //scripts:xml_syntax_check -- $(pwd)
- name: TextView Style Validation Check
# The expression if: ${{ !cancelled() }} runs a job or step regardless of its success or failure while responding to cancellations,
# serving as a cancellation-compliant alternative to if: ${{ always() }} in concurrent workflows.
if: ${{ !cancelled() }}
run: |
bazel run //scripts:check_textview_styles -- $(pwd)
- name: Testfile Presence Check
# The expression if: ${{ !cancelled() }} runs a job or step regardless of its success or failure while responding to cancellations,
# serving as a cancellation-compliant alternative to if: ${{ always() }} in concurrent workflows.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.oppia.android.app.hintsandsolution

import androidx.databinding.ObservableBoolean
import org.oppia.android.util.logging.ConsoleLogger
import org.oppia.android.util.parser.html.CUSTOM_CONCEPT_CARD_TAG
import org.oppia.android.util.parser.html.ConceptCardTagHandler
import org.oppia.android.util.parser.html.CustomHtmlContentHandler

/**
Expand All @@ -9,21 +12,30 @@ import org.oppia.android.util.parser.html.CustomHtmlContentHandler
* @property title the title of this hint, relative to others (this is generated by the app)
* @property hintSummary the core hint text (which may contain HTML) to show the user
* @property isHintRevealed whether the hint is currently expanded and viewable
* @property conceptCardLinkClickListener listener for handling concept card clicks
* @property consoleLogger logger for handling any parsing errors
*/
class HintViewModel(
val title: String,
val hintSummary: String,
val isHintRevealed: ObservableBoolean
val isHintRevealed: ObservableBoolean,
private val conceptCardLinkClickListener: ConceptCardTagHandler.ConceptCardLinkClickListener,
private val consoleLogger: ConsoleLogger
) : HintsAndSolutionItemViewModel() {
/**
* A screenreader-friendly version of [hintSummary] that should be used for readout, in place of
* the original summary.
*/
val hintContentDescription: String by lazy {
CustomHtmlContentHandler.fromHtml(
CustomHtmlContentHandler.getContentDescription(
hintSummary,
imageRetriever = null,
customTagHandlers = mapOf()
).toString()
customTagHandlers = mapOf(
CUSTOM_CONCEPT_CARD_TAG to ConceptCardTagHandler(
conceptCardLinkClickListener,
consoleLogger
)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.oppia.android.domain.hintsandsolution.isHintRevealed
import org.oppia.android.domain.hintsandsolution.isSolutionAvailable
import org.oppia.android.domain.hintsandsolution.isSolutionRevealed
import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.util.logging.ConsoleLogger
import org.oppia.android.util.parser.html.ConceptCardTagHandler
import javax.inject.Inject

/**
Expand All @@ -27,7 +29,9 @@ class HintsAndSolutionViewModel private constructor(
private val writtenTranslationContext: WrittenTranslationContext,
private val resourceHandler: AppLanguageResourceHandler,
private val translationController: TranslationController,
private val solutionViewModelFactory: SolutionViewModel.Factory
private val solutionViewModelFactory: SolutionViewModel.Factory,
private val conceptCardTagHandlerFactory: ConceptCardTagHandler.Factory,
private val consoleLogger: ConsoleLogger
) : ObservableViewModel() {
private val hintList by lazy { helpIndex.dropLastUnavailable(state.interaction.hintList) }
private val solution by lazy {
Expand Down Expand Up @@ -57,7 +61,9 @@ class HintsAndSolutionViewModel private constructor(
private fun createViewModels(): List<HintsAndSolutionItemViewModel> {
return hintList.mapIndexed { index, hint ->
createHintViewModel(
index, hint, isHintRevealed = ObservableBoolean(helpIndex.isHintRevealed(index, hintList))
index,
hint,
isHintRevealed = ObservableBoolean(helpIndex.isHintRevealed(index, hintList))
)
} + listOfNotNull(solution?.let(this::createSolutionViewModel)) + ReturnToLessonViewModel
}
Expand All @@ -73,16 +79,21 @@ class HintsAndSolutionViewModel private constructor(
resourceHandler.toHumanReadableString(hintIndex + 1)
),
hintSummary = translationController.extractString(
hint.hintContent, writtenTranslationContext
hint.hintContent,
writtenTranslationContext
),
isHintRevealed = isHintRevealed
isHintRevealed = isHintRevealed,
conceptCardLinkClickListener =
conceptCardTagHandlerFactory.createConceptCardLinkClickListener(),
consoleLogger = consoleLogger
)
}

private fun createSolutionViewModel(solution: Solution): SolutionViewModel {
return solutionViewModelFactory.create(
solutionSummary = translationController.extractString(
solution.explanation, writtenTranslationContext
solution.explanation,
writtenTranslationContext
),
isSolutionRevealed = isSolutionRevealed,
isSolutionExclusive = solution.answerIsExclusive,
Expand All @@ -96,7 +107,9 @@ class HintsAndSolutionViewModel private constructor(
class Factory @Inject constructor(
private val resourceHandler: AppLanguageResourceHandler,
private val translationController: TranslationController,
private val solutionViewModelFactory: SolutionViewModel.Factory
private val solutionViewModelFactory: SolutionViewModel.Factory,
private val conceptCardTagHandlerFactory: ConceptCardTagHandler.Factory,
private val consoleLogger: ConsoleLogger
) {
/**
* Returns a new [HintsAndSolutionViewModel] that populates a list of item view models (to be
Expand All @@ -114,7 +127,9 @@ class HintsAndSolutionViewModel private constructor(
writtenTranslationContext,
resourceHandler,
translationController,
solutionViewModelFactory
solutionViewModelFactory,
conceptCardTagHandlerFactory,
consoleLogger
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout-land/profile_chooser_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
android:contentDescription="@string/language_icon_content_description" />

<TextView
android:id="@+id/profile_chooser_language_text_view"
style="@style/Subtitle1ViewCenter"
android:minHeight="48dp"
android:paddingTop="20dp"
Expand Down Expand Up @@ -100,6 +101,7 @@
app:layout_constraintEnd_toEndOf="parent">

<TextView
android:id="@+id/administrator_controls_text_view"
style="@style/Subtitle1ViewCenter"
android:layout_marginBottom="24dp"
android:minHeight="48dp"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/layout-land/walkthrough_final_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
app:contentPadding="@dimen/walkthrough_final_fragment_card_content_padding">

<TextView
android:id="@+id/walkthrough_final_no_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
Expand All @@ -61,6 +62,7 @@
android:textSize="20sp" />

<TextView
android:id="@+id/walkthrough_final_no_center_text_view"
style="@style/TextViewCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -85,6 +87,7 @@
app:contentPadding="@dimen/walkthrough_final_fragment_card_content_padding">

<TextView
android:id="@+id/walkthrough_final_yes_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
Expand All @@ -94,6 +97,7 @@
android:textSize="20sp" />

<TextView
android:id="@+id/walkthrough_final_yes_center_text_view"
style="@style/TextViewCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
</FrameLayout>

<TextView
android:id="@+id/story_progress_percentage_text_view"
style="@style/TextViewCenterHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout-sw600dp/profile_chooser_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
android:contentDescription="@string/language_icon_content_description" />

<TextView
android:id="@+id/profile_chooser_language_text_view"
style="@style/Subtitle1ViewCenter"
android:minHeight="48dp"
android:paddingTop="20dp"
Expand Down Expand Up @@ -108,6 +109,7 @@
app:layout_constraintEnd_toEndOf="parent">

<TextView
android:id="@+id/administrator_controls_text_view"
style="@style/Heading1ViewCenter"
android:layout_marginBottom="@dimen/profile_chooser_administrator_controls_margin_bottom"
android:minHeight="48dp"
Expand Down
11 changes: 4 additions & 7 deletions app/src/main/res/layout/drawer_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
android:contentDescription="@string/developer_options_icon_content_description" />

<TextView
android:id="@+id/developer_options_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
Expand Down Expand Up @@ -103,14 +104,10 @@
android:contentDescription="@string/administrator_controls_icon_content_description" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="12dp"
android:fontFamily="sans-serif-medium"
android:id="@+id/administrator_controls_text_view"
style="@style/AdministratorControlsText"
android:text="@string/administrator_controls"
android:textColor="@{footerViewModel.isAdministratorControlsSelected ? @color/component_color_drawer_fragment_admin_controls_selected_text_color : @color/component_color_shared_primary_dark_text_color}"
android:textSize="14sp" />
android:textColor="@{footerViewModel.isAdministratorControlsSelected ? @color/component_color_drawer_fragment_admin_controls_selected_text_color : @color/component_color_shared_primary_dark_text_color}" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/numeric_input_interaction_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
app:textChangedListener="@{viewModel.answerTextWatcher}" />

<TextView
android:id="@+id/numeric_input_interaction_text_view"
style="@style/InputInteractionErrorTextView"
android:text="@{viewModel.errorMessage}"
android:textColor="@color/component_color_shared_input_error_color"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/profile_chooser_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
android:contentDescription="@string/language_icon_content_description" />

<TextView
android:id="@+id/profile_chooser_language_text_view"
style="@style/Subtitle1ViewCenter"
android:minHeight="48dp"
android:paddingTop="20dp"
Expand Down Expand Up @@ -100,6 +101,7 @@
app:layout_constraintEnd_toEndOf="parent">

<TextView
android:id="@+id/administrator_controls_text_view"
style="@style/Subtitle1ViewCenter"
android:layout_marginBottom="24dp"
android:minHeight="48dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/topic_lessons_story_summary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
</FrameLayout>

<TextView
android:id="@+id/story_progress_percentage_text_view"
style="@style/TextViewCenterHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/layout/walkthrough_final_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
app:contentPadding="@dimen/walkthrough_final_fragment_card_content_padding">

<TextView
android:id="@+id/walkthrough_final_no_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
Expand All @@ -66,6 +67,7 @@
android:textSize="20sp" />

<TextView
android:id="@+id/walkthrough_final_no_center_text_view"
style="@style/TextViewCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -90,6 +92,7 @@
app:contentPadding="@dimen/walkthrough_final_fragment_card_content_padding">

<TextView
android:id="@+id/walkthrough_final_yes_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
Expand All @@ -99,6 +102,7 @@
android:textSize="20sp" />

<TextView
android:id="@+id/walkthrough_final_yes_center_text_view"
style="@style/TextViewCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,15 @@
<item name="android:textSize">@dimen/onboarding_shared_text_size_large</item>
</style>

<style name="AdministratorControlsText">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_marginStart">12dp</item>
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textSize">14sp</item>
</style>

<style name="LanguageDropdownStyle" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2288,15 +2288,12 @@ class ExplorationActivityTest {
openHintsAndSolutionsDialog()
pressRevealHintButton(hintPosition = 0)

// TODO(#4848): Fix content description generation & update this test to verify using the
// correct text.
// Ensure the hint description is correct and doesn't contain any HTML.
onView(withId(R.id.hints_and_solution_summary))
.check(
matches(
withContentDescription(
"Remember that two halves, when added together," +
" make one whole.\n\nClick on this .\n\n"
"Remember that two halves, when added together, make one whole." +
"\nClick on this test_skill_id_1 concept card."
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ class QuestionPlayerActivityTest {
matches(
withContentDescription(
"To write a fraction, you need to know its denominator, which is the total " +
"number of pieces in the whole. All of these pieces should be the same size.\n\n"
"number of pieces in the whole. All of these pieces should be the same size."
)
)
)
Expand Down
7 changes: 7 additions & 0 deletions scripts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,10 @@ java_binary(
main_class = "org.oppia.android.scripts.telemetry.DecodeUserStudyEventStringKt",
runtime_deps = ["//scripts/src/java/org/oppia/android/scripts/telemetry:decode_user_study_event_string_lib"],
)

kt_jvm_binary(
name = "check_textview_styles",
testonly = True,
main_class = "org.oppia.android.scripts.xml.TextViewStyleCheckKt",
runtime_deps = ["//scripts/src/java/org/oppia/android/scripts/xml:check_textview_styles"],
)
16 changes: 0 additions & 16 deletions scripts/assets/test_file_exemptions.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -4102,18 +4102,6 @@ test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/ComparableOperationSubject.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/FractionSubject.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/MathEquationSubject.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/MathExpressionSubject.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/MathParsingErrorSubject.kt"
test_file_not_required: true
Expand All @@ -4122,10 +4110,6 @@ test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/PolynomialSubject.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/RealSubject.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt"
test_file_not_required: true
Expand Down
2 changes: 1 addition & 1 deletion scripts/assets/todo_open_exemptions.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ todo_open_exemption {
}
todo_open_exemption {
exempted_file_path: "scripts/static_checks.sh"
line_number: 114
line_number: 121
}
todo_open_exemption {
exempted_file_path: "wiki/Coding-style-guide.md"
Expand Down
Loading

0 comments on commit 90bf370

Please sign in to comment.