Skip to content

Commit

Permalink
Merge branch 'develop' into remove-kitkat-support
Browse files Browse the repository at this point in the history
  • Loading branch information
BenHenning authored Jan 16, 2025
2 parents f078ba4 + fc92932 commit ed29a5a
Show file tree
Hide file tree
Showing 31 changed files with 1,646 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.oppia.android.domain.translation.TranslationController
/** Completed story view model for the recycler view in [CompletedStoryListFragment]. */
class CompletedStoryItemViewModel(
private val activity: AppCompatActivity,
private val internalProfileId: Int,
private val profileId: ProfileId,
val completedStory: CompletedStory,
val entityType: String,
private val intentFactoryShim: IntentFactoryShim,
Expand All @@ -33,7 +33,7 @@ class CompletedStoryItemViewModel(
/** Called when user clicks on CompletedStoryItem. */
fun onCompletedStoryItemClicked() {
routeToTopicPlayStory(
ProfileId.newBuilder().setInternalId(internalProfileId).build(),
profileId,
completedStory.classroomId,
completedStory.topicId,
completedStory.storyId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class CompletedStoryListActivity : InjectableAutoLocalizedAppCompatActivity() {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)

val internalProfileId: Int = intent?.extractCurrentUserProfileId()?.internalId ?: -1
completedStoryListActivityPresenter.handleOnCreate(internalProfileId)
val profileId = intent?.extractCurrentUserProfileId() ?: ProfileId.getDefaultInstance()
completedStoryListActivityPresenter.handleOnCreate(profileId)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.completedstorylist
import androidx.appcompat.app.AppCompatActivity
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityScope
import org.oppia.android.app.model.ProfileId
import javax.inject.Inject

/** The presenter for [CompletedStoryListActivity]. */
Expand All @@ -12,15 +13,15 @@ class CompletedStoryListActivityPresenter @Inject constructor(
) {

/** Initializes views for [CompletedStoryListActivity] and binds [CompletedStoryListFragment]. */
fun handleOnCreate(internalProfileId: Int) {
fun handleOnCreate(profileId: ProfileId) {
activity.setContentView(R.layout.completed_story_list_activity)
if (getCompletedStoryListFragment() == null) {
activity
.supportFragmentManager
.beginTransaction()
.add(
R.id.completed_story_list_fragment_placeholder,
CompletedStoryListFragment.newInstance(internalProfileId),
CompletedStoryListFragment.newInstance(profileId),
CompletedStoryListFragment.COMPLETED_STORY_LIST_FRAGMENT_TAG
).commitNow()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class CompletedStoryListFragment : InjectableFragment() {
const val COMPLETED_STORY_LIST_FRAGMENT_TAG = "COMPLETED_STORY_LIST_FRAGMENT_TAG"

/** Returns a new [CompletedStoryListFragment] to display corresponding to the specified profile ID. */
fun newInstance(internalProfileId: Int): CompletedStoryListFragment {
val profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
fun newInstance(profileId: ProfileId): CompletedStoryListFragment {
return CompletedStoryListFragment().apply {
arguments = Bundle().apply {
decorateWithUserProfileId(profileId)
Expand All @@ -47,11 +46,10 @@ class CompletedStoryListFragment : InjectableFragment() {
"Expected arguments to be passed to CompletedStoryListFragment"
}
val profileId = arguments.extractCurrentUserProfileId()
val internalProfileId = profileId.internalId
return completedStoryListFragmentPresenter.handleCreateView(
inflater,
container,
internalProfileId
profileId
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import org.oppia.android.R
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.recyclerview.BindableAdapter
import org.oppia.android.databinding.CompletedStoryItemBinding
import org.oppia.android.databinding.CompletedStoryListFragmentBinding
Expand All @@ -26,9 +27,9 @@ class CompletedStoryListFragmentPresenter @Inject constructor(
fun handleCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
internalProfileId: Int
profileId: ProfileId
): View? {
viewModel.setProfileId(internalProfileId)
viewModel.setProfileId(profileId)

binding = CompletedStoryListFragmentBinding
.inflate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ class CompletedStoryListViewModel @Inject constructor(
private val translationController: TranslationController,
@StoryHtmlParserEntityType private val entityType: String
) : ObservableViewModel() {
/** [internalProfileId] needs to be set before any of the live data members can be accessed. */
private var internalProfileId: Int = -1
/** [profileId] needs to be set before any of the live data members can be accessed. */
private var profileId: ProfileId = ProfileId.getDefaultInstance()

private val completedStoryListResultLiveData: LiveData<AsyncResult<CompletedStoryList>> by lazy {
topicController.getCompletedStoryList(
ProfileId.newBuilder().setInternalId(internalProfileId).build()
).toLiveData()
topicController.getCompletedStoryList(profileId).toLiveData()
}

private val completedStoryLiveData: LiveData<CompletedStoryList> by lazy {
Expand All @@ -45,8 +43,8 @@ class CompletedStoryListViewModel @Inject constructor(
}

/** Sets internalProfileId to this ViewModel. */
fun setProfileId(internalProfileId: Int) {
this.internalProfileId = internalProfileId
fun setProfileId(profileId: ProfileId) {
this.profileId = profileId
}

private fun processCompletedStoryListResult(
Expand Down Expand Up @@ -74,7 +72,7 @@ class CompletedStoryListViewModel @Inject constructor(
completedStoryList.completedStoryList.map { completedStory ->
CompletedStoryItemViewModel(
activity,
internalProfileId,
profileId,
completedStory,
entityType,
intentFactoryShim,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface LanguageInterface {
/**
* Returns whether the user is actively seeking a new audio position, that is, dragging the
* knob to a new position in the audio track.
* */
*/
fun getUserIsSeeking(): Boolean

/** Returns the position of the knob on the audio track. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface IntentFactoryShim {
/**
* Creates a [TopicActivity] intent for [PromotedStoryViewModel] and passes necessary string
* data.
* */
*/
fun createTopicPlayStoryActivityIntent(
context: Context,
internalProfileId: Int,
Expand All @@ -27,7 +27,7 @@ interface IntentFactoryShim {

/**
* Creates a [TopicActivity] intent which opens info-tab.
* */
*/
fun createTopicActivityIntent(
context: Context,
internalProfileId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ interface StoryFragmentScroller {
/**
* Scrolls smoothly (with animation) to the specified vertical pixel position in
* [StoryFragment].
* */
*/
fun smoothScrollToPosition(position: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.utility
import android.content.Context
import android.content.Context.WINDOW_SERVICE
import android.util.DisplayMetrics
import android.util.TypedValue
import android.view.WindowManager
import org.oppia.android.app.model.ReadingTextSize
import javax.inject.Inject
Expand All @@ -21,16 +22,18 @@ class FontScaleConfigurationUtil @Inject constructor() {
// TODO(#3616): Migrate to the proper SDK 30+ APIs.
@Suppress("DEPRECATION") // The code is correct for targeted versions of Android.
windowManager!!.defaultDisplay.getMetrics(metrics)
// TODO(#5625): Migrate away from scaledDensity.
val scaledDensity = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, 1.0f, metrics
) * configuration.fontScale
@Suppress("DEPRECATION")
metrics.scaledDensity = configuration.fontScale * metrics.density
metrics.scaledDensity = scaledDensity
context.createConfigurationContext(configuration)
context.resources.displayMetrics.setTo(metrics)
}

private fun getReadingTextSizeConfigurationUtil(readingTextSize: ReadingTextSize): Float {
return when (readingTextSize) {
ReadingTextSize.SMALL_TEXT_SIZE -> .8f
ReadingTextSize.SMALL_TEXT_SIZE -> 0.8f
ReadingTextSize.MEDIUM_TEXT_SIZE -> 1.0f
ReadingTextSize.LARGE_TEXT_SIZE -> 1.2f
ReadingTextSize.EXTRA_LARGE_TEXT_SIZE -> 1.4f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface HintHandler {
* @param trackedWrongAnswerCount the count of wrong answers saved in the checkpoint
* @param helpIndex the cached state of hints/solution from the checkpoint
* @param state the restored pending state
* */
*/
suspend fun resumeHintsForSavedState(
trackedWrongAnswerCount: Int,
helpIndex: HelpIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ExceptionsController @Inject constructor(
* At first, it checks if the size of the store isn't exceeding [exceptionLogStorageCacheSize].
* If the limit is exceeded then the least recent exception is removed from the [exceptionLogStore].
* After this, the [exceptionLog] is added to the store.
* */
*/
private fun cacheExceptionLog(exceptionLog: ExceptionLog) {
exceptionLogStore.storeDataAsync(true) { oppiaExceptionLogs ->
val storeSize = oppiaExceptionLogs.exceptionLogList.size
Expand Down
4 changes: 2 additions & 2 deletions scripts/assets/file_content_validation_checks.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ file_content_checks {
}
file_content_checks {
file_path_regex: ".+?\\.kt$"
prohibited_content_regex: "\\*\\*/"
failure_message: "Badly formatted KDoc or block comment. KDocs and block comments should only end with \"*/\"."
prohibited_content_regex: "\\*(\\s*\\*|\\*)/"
failure_message: "Badly formatted KDoc or block comment. KDocs and block comments should only end with \"*/\". Multiple asterisks or whitespace between asterisks are not allowed."
exempted_file_name: "scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt"
}
file_content_checks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ class RegexPatternValidationCheckTest {
"Badly formatted KDoc. Single-line KDocs should always end with exactly one space before the" +
" final \"*/\"."
private val badKdocOrBlockCommentShouldEndWithCorrectEnding =
"Badly formatted KDoc or block comment. KDocs and block comments should only end with \"*/\"."
"Badly formatted KDoc or block comment. KDocs and block comments should only" +
" end with \"*/\". Multiple asterisks or whitespace between asterisks are not allowed."
private val badKdocParamsAndPropertiesShouldHaveNameFollowing =
"Badly formatted KDoc param or property at-clause: the name of the parameter or property" +
" should immediately follow the at-clause without any additional linking with brackets."
Expand Down Expand Up @@ -2607,6 +2608,37 @@ class RegexPatternValidationCheckTest {
)
}

@Test
fun testFileContent_kdocWithInvalidEndingSequences_failsValidation() {
val prohibitedContent =
"""
/**
* Incorrect KDoc comment.
* */
/**
* Incorrect KDoc comment.
**/
/**
* Correct KDoc comment.
*/
""".trimIndent()
tempFolder.newFolder("testfiles", "app", "src", "main", "java", "org", "oppia", "android")
val stringFilePath = "app/src/main/java/org/oppia/android/TestPresenter.kt"
tempFolder.newFile("testfiles/$stringFilePath").writeText(prohibitedContent)

val exception = assertThrows<Exception>() { runScript() }

assertThat(exception).hasMessageThat().contains(REGEX_CHECK_FAILED_OUTPUT_INDICATOR)
assertThat(outContent.toString().trim())
.isEqualTo(
"""
$stringFilePath:3: $badKdocOrBlockCommentShouldEndWithCorrectEnding
$stringFilePath:6: $badKdocOrBlockCommentShouldEndWithCorrectEnding
$wikiReferenceNote
""".trimIndent()
)
}

@Test
fun testFileContent_singleLineKdocWithExtraSpacesBeforeEnd_fileContentIsNotCorrect() {
val prohibitedContent =
Expand Down
69 changes: 69 additions & 0 deletions testing/src/test/java/org/oppia/android/testing/math/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
Tests for math-related test utilities.
"""

load("//:oppia_android_test.bzl", "oppia_android_test")

oppia_android_test(
name = "FractionSubjectTest",
srcs = ["FractionSubjectTest.kt"],
custom_package = "org.oppia.android.testing.math",
test_class = "org.oppia.android.testing.math.FractionSubjectTest",
test_manifest = "//testing:test_manifest",
deps = [
"//model/src/main/proto:math_java_proto_lite",
"//testing/src/main/java/org/oppia/android/testing/math:fraction_subject",
"//testing/src/main/java/org/oppia/android/testing/robolectric:test_module",
"//third_party:com_google_truth_truth",
"//third_party:junit_junit",
"//third_party:robolectric_android-all",
],
)

oppia_android_test(
name = "MathEquationSubjectTest",
srcs = ["MathEquationSubjectTest.kt"],
custom_package = "org.oppia.android.testing.math",
test_class = "org.oppia.android.testing.math.MathEquationSubjectTest",
test_manifest = "//testing:test_manifest",
deps = [
"//model/src/main/proto:math_java_proto_lite",
"//testing/src/main/java/org/oppia/android/testing/math:math_equation_subject",
"//testing/src/main/java/org/oppia/android/testing/robolectric:test_module",
"//third_party:com_google_truth_truth",
"//third_party:junit_junit",
"//third_party:robolectric_android-all",
],
)

oppia_android_test(
name = "MathExpressionSubjectTest",
srcs = ["MathExpressionSubjectTest.kt"],
custom_package = "org.oppia.android.testing.math",
test_class = "org.oppia.android.testing.math.MathExpressionSubjectTest",
test_manifest = "//testing:test_manifest",
deps = [
"//model/src/main/proto:math_java_proto_lite",
"//testing/src/main/java/org/oppia/android/testing/math:math_expression_subject",
"//testing/src/main/java/org/oppia/android/testing/robolectric:test_module",
"//third_party:com_google_truth_truth",
"//third_party:junit_junit",
"//third_party:robolectric_android-all",
],
)

oppia_android_test(
name = "RealSubjectTest",
srcs = ["RealSubjectTest.kt"],
custom_package = "org.oppia.android.testing.math",
test_class = "org.oppia.android.testing.math.RealSubjectTest",
test_manifest = "//testing:test_manifest",
deps = [
"//model/src/main/proto:math_java_proto_lite",
"//testing/src/main/java/org/oppia/android/testing/math:real_subject",
"//testing/src/main/java/org/oppia/android/testing/robolectric:test_module",
"//third_party:com_google_truth_truth",
"//third_party:junit_junit",
"//third_party:robolectric_android-all",
],
)
Loading

0 comments on commit ed29a5a

Please sign in to comment.