Skip to content

Commit

Permalink
Merge branch 'oppia:develop' into develop-tejas
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejas-67 authored Nov 1, 2023
2 parents 63b191e + 094d4a3 commit e688b1e
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 70 deletions.
56 changes: 14 additions & 42 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -472,48 +472,20 @@
<string name="completed_story_list_recyclerview_tag">completed_story_list_recyclerview_tag</string>
<string name="item_selection_text">Please select all correct choices.</string>
<!-- SplashActivity -->
<string name="unsupported_app_version_dialog_title" description="The title of the dialog shown when a user's pre-release app has expired.">
Unsupported app version
</string>
<string name="unsupported_app_version_dialog_message" description="The main message of the dialog shown when a user's pre-release app has expired.">
This version of the app is no longer supported. Please update it through the Play Store.
</string>
<string name="unsupported_app_version_dialog_close_button_text" description="The close button text of the dialog shown when a user's pre-release app has expired.">
Close app
</string>
<string name="forced_app_update_dialog_title" description="The title of the dialog shown when a user's pre-release app has expired.">
App update required
</string>
<string name="forced_app_update_dialog_message" description="The main message of the dialog shown when a user's app has expired.">
A new version of %s is now available. The new version is more secure, and improves your learning experience.\n\nThis version is no longer supported. To continue using the app, please update to the latest version.
</string>
<string name="forced_app_update_dialog_update_button_text" description="The update button text of the dialog shown when a user's pre-release app has expired.">
Update
</string>
<string name="forced_app_update_dialog_close_button_text" description="The close button text of the dialog shown when a user's pre-release app has expired.">
Close app
</string>
<string name="optional_app_update_dialog_title" description="The title of the dialog shown when an optional app update is available.">
New update available
</string>
<string name="optional_app_update_dialog_message" description="The main message of the dialog shown when an optional app update is available.">
A new version of %s is now available. We recommend that you update the app for bug fixes and a better learning experience.
</string>
<string name="optional_app_update_dialog_dismiss_button_text" description="The dismiss button text of the dialog shown when an optional app update is available.">
Dismiss
</string>
<string name="optional_app_update_dialog_update_button_text" description="The update button text of the dialog shown when an optional app update is available.">
Update
</string>
<string name="os_deprecation_dialog_title" description="The title of the dialog shown when an the OS the user is using is no longer supported.">
Update your Android OS
</string>
<string name="os_deprecation_dialog_message" description="The main message of the dialog shown when an the OS the user is using is no longer supported.">
We recommend updating your Android OS to take advantage of %s\'s new features and lessons.\n\nVisit your phone\'s Settings app to update your OS.
</string>
<string name="os_deprecation_dialog_dismiss_button_text" description="The dismiss button text of the dialog shown when an the OS the user is using is no longer supported.">
Dismiss
</string>
<string name="unsupported_app_version_dialog_title" description="The title of the dialog shown when a user's pre-release app has expired.">Unsupported app version</string>
<string name="unsupported_app_version_dialog_message" description="The main message of the dialog shown when a user's pre-release app has expired.">This version of the app is no longer supported. Please update it through the Play Store.</string>
<string name="unsupported_app_version_dialog_close_button_text" description="The close button text of the dialog shown when a user's pre-release app has expired.">Close app</string>
<string name="forced_app_update_dialog_title" description="The title of the dialog shown when a user's pre-release app has expired.">App update required</string>
<string name="forced_app_update_dialog_message" description="The main message of the dialog shown when a user's app has expired.">A new version of %s is now available. The new version is more secure, and improves your learning experience.\n\nThis version is no longer supported. To continue using the app, please update to the latest version.</string>
<string name="forced_app_update_dialog_update_button_text" description="The update button text of the dialog shown when a user's pre-release app has expired.">Update</string>
<string name="forced_app_update_dialog_close_button_text" description="The close button text of the dialog shown when a user's pre-release app has expired.">Close app</string>
<string name="optional_app_update_dialog_title" description="The title of the dialog shown when an optional app update is available.">New update available</string>
<string name="optional_app_update_dialog_message" description="The main message of the dialog shown when an optional app update is available.">A new version of %s is now available. We recommend that you update the app for bug fixes and a better learning experience.</string>
<string name="optional_app_update_dialog_dismiss_button_text" description="The dismiss button text of the dialog shown when an optional app update is available.">Dismiss</string>
<string name="optional_app_update_dialog_update_button_text" description="The update button text of the dialog shown when an optional app update is available.">Update</string>
<string name="os_deprecation_dialog_title" description="The title of the dialog shown when an the OS the user is using is no longer supported.">Update your Android OS</string>
<string name="os_deprecation_dialog_message" description="The main message of the dialog shown when an the OS the user is using is no longer supported.">We recommend updating your Android OS to take advantage of %s\'s new features and lessons.\n\nVisit your phone\'s Settings app to update your OS.</string>
<string name="os_deprecation_dialog_dismiss_button_text" description="The dismiss button text of the dialog shown when an the OS the user is using is no longer supported.">Dismiss</string>
<string name="splash_screen_developer_label">Developer Build</string>
<string name="splash_screen_alpha_label">Alpha</string>
<string name="splash_screen_beta_label">Beta</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,26 @@ class HtmlParser private constructor(
supportsLinks: Boolean = false,
supportsConceptCards: Boolean = false
): Spannable {

var htmlContent = rawString

// Canvas does not support RTL, it always starts from left to right in RTL due to which compound drawables are
// not center aligned. To avoid this situation check if RTL is enabled and set the textDirection.
if (isRtl) {
htmlContentTextView.textDirection = View.TEXT_DIRECTION_RTL

val regex = Regex("""<oppia-noninteractive-image [^>]*>.*?</oppia-noninteractive-image>""")
val modifiedHtmlContent = rawString.replace(regex) {
val oppiaImageTag = it.value
"""<div style="text-align: center;">$oppiaImageTag</div>"""
}
htmlContent = modifiedHtmlContent
} else {
htmlContentTextView.textDirection = View.TEXT_DIRECTION_LTR
}

htmlContentTextView.invalidate()

var htmlContent = rawString
if ("\n\t" in htmlContent) {
htmlContent = htmlContent.replace("\n\t", "")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.widget.TextView
import androidx.core.view.ViewCompat
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
import org.oppia.android.util.R
Expand Down Expand Up @@ -234,6 +235,11 @@ class UrlImageParser private constructor(
private val autoResizeImage: Boolean
) : AutoAdjustingImageTarget<T, D>(targetConfiguration) {

private fun isRTLMode(): Boolean {
return ViewCompat.getLayoutDirection(htmlContentTextView) == ViewCompat
.LAYOUT_DIRECTION_RTL
}

override fun computeBounds(
context: Context,
drawable: D,
Expand Down Expand Up @@ -304,11 +310,13 @@ class UrlImageParser private constructor(
drawableWidth *= multipleFactor
}
}
val drawableLeft = if (imageCenterAlign) {

val drawableLeft = if (imageCenterAlign && !isRTLMode()) {
calculateInitialMargin(maxAvailableWidth, drawableWidth)
} else {
0f
}

val drawableTop = 0f
val drawableRight = drawableLeft + drawableWidth
val drawableBottom = drawableTop + drawableHeight
Expand Down
62 changes: 47 additions & 15 deletions wiki/Installing-Oppia-Android.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@ This wiki page explains how to install Oppia Android on your local machine. If y
- [Install oppia-android](#install-oppia-android)
- [Run the app from Android Studio](#run-the-app-from-android-studio)
- [Run the tests](#set-up-and-run-tests)
- [Step-by-Step guidance for setting up and running app modules robolectric test](#step-by-step-guidance-for-setting-up-and-running-app-modules-robolectric-test)
- [For tests that are in non-app modules, such as **domain** or **utility**:](#for-tests-that-are-in-non-app-modules-such-as-domain-or-utility)


## Prepare developer environment

1. Download/Install [Android Studio](https://developer.android.com/studio/?gclid=EAIaIQobChMI8fX3n5Lb6AIVmH8rCh24JQsxEAAYASAAEgL4L_D_BwE&gclsrc=aw.ds#downloads).
1. Download/Install [Android Studio Bumblebee | Patch 3](https://developer.android.com/studio/archive).

**Note**: We recommend installing **Android Studio Bumblebee** because newer versions of Android Studio[ do not support running tests where shared source sets are used](https://issuetracker.google.com/issues/232007221#comment18), a configuration we use at Oppia.
**Note**: We recommend installing **Android Studio Bumblebee | 2021.1.1 Patch 3** because newer versions of Android Studio[ do not support running tests where shared source sets are used](https://issuetracker.google.com/issues/232007221#comment18), a configuration we use at Oppia.

**Direct download Url**: [Windows](https://redirector.gvt1.com/edgedl/android/studio/install/2021.1.1.23/android-studio-2021.1.1.23-windows.exe) | [Linux](https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2021.1.1.23/android-studio-2021.1.1.23-linux.tar.gz) | [Intel Mac](https://redirector.gvt1.com/edgedl/android/studio/install/2021.1.1.23/android-studio-2021.1.1.23-mac.dmg) | [Apple Silicon Mac](https://redirector.gvt1.com/edgedl/android/studio/install/2021.1.1.23/android-studio-2021.1.1.23-mac_arm.dmg)

You can have multiple versions of Android Studio installed on your machine at the same time.

2. Configure your Android Studio
- In Android Studio, open Tools > SDK Manager.
- In the "SDK Platforms" tab (which is the default), select `API Level 28` and also `API Level 31` (for Bazel support).
- In the "SDK Platforms" tab (which is the default), select `API Level 28` and also `API Level 30` (for Bazel support).
- Also, navigate to the "SDK Tools" tab, click the "Show Package Details" checkbox at the bottom right, then click on "Android SDK Build-Tools 34-rc1" and select 29.0.2 (this is needed for Bazel support).

- Then, click "Apply" to download and install these two SDKs/Tools.

- Must have **JDK 11** selected:
- In Android Studio, open Settings > Build, Execution, Deployment > Build Tools > Gradle and edit the Gradle JDK field.

## Install oppia-android

Expand Down Expand Up @@ -81,38 +86,65 @@ Please follow these steps to set up Oppia Android on your local machine.
## Set up and run tests
Testing the app is an integral part of our development process. You will need to test all code changes to ensure that the app works correctly, therefore it is important to ensure that your test configuration works.

We run tests in either Espresso(`app` module tests) or Robolectric(non-app module tests), meaning tests will run in either the emulator or on Gradle/Bazel via the terminal.
We strongly recommend running tests on Robolectric which is faster because it does not require a physical device or emulator setup.

### Configure Robolectric Tests

#### Step-by-Step guidance for setting up and running app modules robolectric test:

1. Go to **Edit Configuration** in Android Studio (Bumblebee | 2021.1.1 Patch 3)
![](https://user-images.githubusercontent.com/9396084/79109714-83525980-7d96-11ea-99d7-f83ea81a8a50.png)

2. Click on Add(+) -> **JUnit**
![](https://github.com/oppia/oppia-android/assets/76530270/87caf3fc-37d9-472d-92fd-b8ec49fb6b49)

3. Enter following information:
- a) Name of test. Example: In my case "SplashActivityTest"
- b) Make sure select "java 11" and oppia-android.app
- c) Class path of Test class. Example: In my case "org.oppia.android.app.splash.
SplashActivityTest"
- d) Press `OK` to select the test.
![](https://github.com/oppia/oppia-android/assets/76530270/5901624a-df76-4b27-8f31-6077a68fcb89)

4. Click on "Run" button to run robolectric test. (In my case "SplashActivityTest")
![](https://github.com/oppia/oppia-android/assets/76530270/75a6b998-90c5-4f0a-8886-78f96970be90)

#### For tests that are in non-app modules, such as **domain** or **utility**::

1. In Android Studio, open the desired test file, e.g., `AnalyticsControllerTest`.
2. In the test file, to the left of the class name, click on the orange and green arrow, and select **Run 'AnalyticsControllerTest'**.
- You will notice that the emulator is greyed out, but the run window will open to show the running tests:
![](https://user-images.githubusercontent.com/59600948/272657015-158117e5-47d2-40fc-a38b-5dee6c347556.png)

### Configure Emulator Tests

**Espresso is slower for running tests, so we recommend using Robolectric.**

1. In Android Studio, open the desired test file, e.g., `HomeActivityTest`.
2. In the Android Studio toolbar, click on the `Available Devices` option. Select an emulator that has between API 28-30.

**Note**: If you don't have any available devices in this list, please follow [these instructions](#run-the-app-from-android-studio) to create one.

3. In the test file, to the left of the class name, click on the orange and green arrow, and select **Run 'HomeActivityTest'**.
![](https://user-images.githubusercontent.com/59600948/272657131-96e5354b-13a9-4709-969a-b9494a65c30f.png)
![](https://user-images.githubusercontent.com/59600948/272657131-96e5354b-13a9-4709-969a-b9494a65c30f.png)

4. An "**Edit Configuration**" dialog will show up, and you should add the following settings under the general tab:
- For module, select **oppia-android.app**
- For Test, select **Class**
- For Instrumentation class, **org.oppia.android.testing.OppiaTestRunner**, will be selected by default.
- For target, select the **Use the device/snapshot dropdown** option.
- Verify that your setup looks like below:
-![](https://user-images.githubusercontent.com/59600948/272657260-2e654891-61be-467a-8ebd-c997aa2abda6.png)

![](https://user-images.githubusercontent.com/59600948/272657260-2e654891-61be-467a-8ebd-c997aa2abda6.png)
- Finally, Click the "Apply" and "Okay" buttons.
- You may need to repeat step (3) above to run the test with the new configuration.
- Subsequent runs of any app module tests will not require editing the configuration.
- This configuration will run all the tests in that class.
5. To run only a specific test in a file:
- Search or scroll down to the desired test name, to the left of the test name, click on the run icon and select **Run '`test name`''**.

### Configure Robolectric Tests
These are tests that are in non-app modules, such as **domain** or **utility**.
1. In Android Studio, open the desired test file, e.g., `AnalyticsControllerTest`.
2. In the test file, to the left of the class name, click on the orange and green arrow, and select **Run 'AnalyticsControllerTest'**.
- You will notice that the emulator is greyed out, but the run window will open to show the running tests:
- ![](https://user-images.githubusercontent.com/59600948/272657015-158117e5-47d2-40fc-a38b-5dee6c347556.png)


### Next Steps
- Congratulations, you are ready to work on your first issue! Take a look at our [good first issues](https://github.com/oppia/oppia-android/wiki/Oppia-Android-Testing) and leave a comment with your suggested fix. A maintainer will assign you the issue and provide any necessary guidance.
- Congratulations, you are ready to work on your first issue! Take a look at our [good first issues](https://github.com/oppia/oppia-android/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22+no%3Aassignee) and leave a comment with your suggested fix. A maintainer will assign you the issue and provide any necessary guidance.

- When you are ready to submit a PR, please follow [these instructions](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR) on submitting a PR.

Expand Down
27 changes: 16 additions & 11 deletions wiki/Oppia-Android-Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,22 @@ public class MyActivityTest {
```

### Running Robolectric tests
1. Go to **Edit Configuration** in Android Studio
<img width="425" alt="Screenshot 2020-04-13 at 2 51 02 PM" src="https://user-images.githubusercontent.com/9396084/79109714-83525980-7d96-11ea-99d7-f83ea81a8a50.png">

2. Add **Android JUnit**
<img width="1070" alt="Screenshot 2020-04-13 at 2 51 31 PM" src="https://user-images.githubusercontent.com/9396084/79109717-851c1d00-7d96-11ea-92c1-2e8a9c6ef88f.png">

3. Enter following information - (a.) **Name** (Normally class name) (b.)**Use classpath of module** (c.) **Class**
<img width="1074" alt="Screenshot 2020-04-13 at 3 18 39 PM" src="https://user-images.githubusercontent.com/9396084/79111450-307aa100-7d9a-11ea-8b9d-81aac26e104d.png">


4. Press `OK` to run the test cases in robolectric.
1. Go to **Edit Configuration** in Android Studio (Bumblebee | 2021.1.1 Patch 3)
![](https://user-images.githubusercontent.com/9396084/79109714-83525980-7d96-11ea-99d7-f83ea81a8a50.png)

2. Click on Add(+) -> **JUnit**
![](https://github.com/oppia/oppia-android/assets/76530270/87caf3fc-37d9-472d-92fd-b8ec49fb6b49)

3. Enter following information:
- a) Name of test. Example: In my case "SplashActivityTest"
- b) Make sure select "java 11" and oppia-android.app [**Note:** For "app module test" select `oppia-android.app` similarly for "utility tests" select `oppia-android.utility`, for "domain test" select `oppia-android.domain`, for "model test" select `oppia-android.model`, for "testing" select `oppia-android.testing`]
- c) Class path of Test class. Example: In my case "org.oppia.android.app.splash.
SplashActivityTest"
- d) Press `OK` to select the test.
![](https://github.com/oppia/oppia-android/assets/76530270/5901624a-df76-4b27-8f31-6077a68fcb89)

4. Click on "Run" button to run robolectric test. (In my case "SplashActivityTest")
![](https://github.com/oppia/oppia-android/assets/76530270/75a6b998-90c5-4f0a-8886-78f96970be90)

## Espresso

Expand Down

0 comments on commit e688b1e

Please sign in to comment.