Skip to content

Commit

Permalink
Fix Part of #4938: Introduce New App Language Selection Screen for on…
Browse files Browse the repository at this point in the history
…boarding (#5373)

<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
Fixes Part of #4938: Introuduces new app language selection screen.

This PR introduces the layout files and the presenter for displaying the
language functionality, along with associated test cases.

I have modified the custom view `SurveyOnboardingBackgroundView` to make
it generic and reusable in the new layouts.

These changes include both darkmode support and alternate screen size
and orientation layouts, as per figma mocks.

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

## For UI-specific PRs only
||||
|--- |---|---|
||Lightmode Portrait|Darkmode & Landscape|
|Mobile
**xxhdpi**|![Screenshot_1711564671](https://github.com/oppia/oppia-android/assets/59600948/7399cad6-709c-4aa0-a2e8-5c2aeceb36d7)|![Screenshot_1712156819](https://github.com/oppia/oppia-android/assets/59600948/b6cace78-28ed-452a-b5d2-c8ce1e0e2567)|
|Mobile
**mdpi**|![Screenshot_1712156777](https://github.com/oppia/oppia-android/assets/59600948/3ce79b76-f8d0-44e2-ac2f-329c2cc9f598)|![Screenshot_1712156762](https://github.com/oppia/oppia-android/assets/59600948/0c0cba3f-8d5c-4aa6-9fab-7b902de08a0e)|
|Tablet
**xxhdpi**|![Screenshot_1711554842](https://github.com/oppia/oppia-android/assets/59600948/58ac2b67-ecec-439e-91f4-dc1dde2f2918)|![Screenshot_1712151724](https://github.com/oppia/oppia-android/assets/59600948/c8eafa6a-8550-449b-a79d-76ec961c24bc)|
|Tablet
**hdpi**|![Screenshot_1711563235](https://github.com/oppia/oppia-android/assets/59600948/4e4ae865-1e8c-4f8f-879e-8a46fe795ab4)|![Screenshot_1712151535](https://github.com/oppia/oppia-android/assets/59600948/52d07d1a-5146-41ce-b4da-597e22c4a529)|
  • Loading branch information
adhiamboperes authored Jun 18, 2024
1 parent bde4eaf commit 8e5cb49
Show file tree
Hide file tree
Showing 37 changed files with 1,651 additions and 261 deletions.
3 changes: 2 additions & 1 deletion app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ VIEWS_WITH_RESOURCE_IMPORTS = [
"src/main/java/org/oppia/android/app/customview/ChapterNotStartedContainerConstraintLayout.kt",
"src/main/java/org/oppia/android/app/customview/ContinueButtonView.kt",
"src/main/java/org/oppia/android/app/customview/LessonThumbnailImageView.kt",
"src/main/java/org/oppia/android/app/customview/OppiaCurveBackgroundView.kt",
"src/main/java/org/oppia/android/app/customview/PromotedStoryCardView.kt",
"src/main/java/org/oppia/android/app/customview/SegmentedCircularProgressView.kt",
"src/main/java/org/oppia/android/app/customview/SurveyOnboardingBackgroundView.kt",
"src/main/java/org/oppia/android/app/customview/VerticalDashedLineView.kt",
"src/main/java/org/oppia/android/app/survey/SurveyMultipleChoiceOptionView.kt",
"src/main/java/org/oppia/android/app/survey/SurveyNpsItemOptionView.kt",
Expand Down Expand Up @@ -485,6 +485,7 @@ BINDING_ADAPTERS_WITH_RESOURCE_IMPORTS = [
BINDING_ADAPTERS = [
"src/main/java/org/oppia/android/app/databinding/AppCompatCheckBoxBindingAdapters.java",
"src/main/java/org/oppia/android/app/databinding/CircularProgressIndicatorAdapters.java",
"src/main/java/org/oppia/android/app/databinding/ColorBindingAdapters.java",
"src/main/java/org/oppia/android/app/databinding/ConstraintLayoutAdapters.java",
"src/main/java/org/oppia/android/app/databinding/EditTextBindingAdapters.java",
"src/main/java/org/oppia/android/app/databinding/GuidelineBindingAdapters.java",
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@
android:label="@string/survey_activity_title"
android:theme="@style/OppiaThemeWithoutActionBar"
android:windowSoftInputMode="adjustNothing" />
<activity
android:name=".app.testing.ColorBindingAdaptersTestActivity"
android:theme="@style/OppiaThemeWithoutActionBar" />

<provider
android:name="androidx.work.impl.WorkManagerInitializer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import org.oppia.android.app.testing.AdministratorControlsFragmentTestActivity
import org.oppia.android.app.testing.AppCompatCheckBoxBindingAdaptersTestActivity
import org.oppia.android.app.testing.AudioFragmentTestActivity
import org.oppia.android.app.testing.CircularProgressIndicatorAdaptersTestActivity
import org.oppia.android.app.testing.ColorBindingAdaptersTestActivity
import org.oppia.android.app.testing.ConceptCardFragmentTestActivity
import org.oppia.android.app.testing.DragDropTestActivity
import org.oppia.android.app.testing.DrawableBindingAdaptersTestActivity
Expand Down Expand Up @@ -216,4 +217,5 @@ interface ActivityComponentImpl :
fun inject(viewEventLogsTestActivity: ViewEventLogsTestActivity)
fun inject(walkthroughActivity: WalkthroughActivity)
fun inject(surveyActivity: SurveyActivity)
fun inject(colorBindingAdaptersTestActivity: ColorBindingAdaptersTestActivity)
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
package org.oppia.android.app.customview

import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import org.oppia.android.R
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.app.view.ViewComponentFactory
import org.oppia.android.app.view.ViewComponentImpl
import javax.inject.Inject

/**
* CustomView to add a background to [SurveyWelcomeDialogFragment] and [SurveyOutroDialogFragment].
* Without chaptersFinished and totalChapters values this custom-view cannot be created.
* CustomView to add a background to views that require a bezier curve background.
*
* Reference: // https://proandroiddev.com/how-i-drew-custom-shapes-in-bottom-bar-c4539d86afd7 and
* // https://ciechanow.ski/drawing-bezier-curves/
*/
class SurveyOnboardingBackgroundView : View {
@Inject
lateinit var resourceHandler: AppLanguageResourceHandler
class OppiaCurveBackgroundView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
/**
* Used to retrieve the layout direction that should be used to mirror the direction of the
* curve based on locale.
*/
@Inject lateinit var resourceHandler: AppLanguageResourceHandler

private val isRtl by lazy {
resourceHandler.getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL
}

private val orientation = Resources.getSystem().configuration.orientation

private var customBackgroundColor = Color.WHITE // Default color.

private lateinit var paint: Paint
private lateinit var path: Path
private var strokeWidth = 2f

constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)

init {
/** Sets the desired background color to the view and initializes the view. */
fun setCustomBackgroundColor(colorRes: Int) {
this.customBackgroundColor = colorRes
setupCurvePaint()
}

Expand All @@ -61,17 +65,37 @@ class SurveyOnboardingBackgroundView : View {
val width = this.width.toFloat()
val height = this.height.toFloat()

val controlPoint1X = width * 0.5f
val controlPoint1Y = 0f

val controlPoint2X = width * 0.5f
val controlPoint2Y = height * 0.2f

val controlPoint3X = width * 1f
val controlPoint3Y = height * 0.1f
val controlPoint1X: Float
val controlPoint1Y: Float

val controlPoint2X: Float
val controlPoint2Y: Float

val controlPoint3X: Float
val controlPoint3Y: Float

if (orientation == Configuration.ORIENTATION_PORTRAIT) {
controlPoint1X = width * 0.55f
controlPoint1Y = 0f
controlPoint2X = width * 0.52f
controlPoint2Y = height * 0.2f
controlPoint3X = width * 1f
controlPoint3Y = height * 0.1f
} else {
controlPoint1X = width * 0.40f
controlPoint1Y = 0f
controlPoint2X = width * 0.60f
controlPoint2Y = height * 0.40f
controlPoint3X = width * 1f
controlPoint3Y = height * 0.2f
}

path.reset()
path.moveTo(0f, height * 0.1f)
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
path.moveTo(0f, height * 0.10f)
} else {
path.moveTo(0f, height * 0.30f)
}
path.cubicTo(
controlPoint1X,
controlPoint1Y,
Expand All @@ -90,12 +114,9 @@ class SurveyOnboardingBackgroundView : View {
path = Path()
paint = Paint(Paint.ANTI_ALIAS_FLAG)
paint.apply {
style = Paint.Style.FILL_AND_STROKE
strokeWidth = this@SurveyOnboardingBackgroundView.strokeWidth
color = ContextCompat.getColor(
context,
R.color.component_color_survey_popup_background_color
)
style = Paint.Style.FILL
strokeWidth = this@OppiaCurveBackgroundView.strokeWidth
color = customBackgroundColor
}
setBackgroundColor(Color.TRANSPARENT)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.oppia.android.app.databinding;

import android.view.View;
import androidx.databinding.BindingAdapter;

/** Holds all custom binding adapters that set color values. */
public final class ColorBindingAdapters {

/** Binding adapter for setting the `customBackgroundColor` for a [View]. */
@BindingAdapter("customBackgroundColor")
public static void setCustomBackgroundColor(View view, int color) {
view.setBackgroundColor(color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ import android.view.View
import android.view.ViewGroup
import org.oppia.android.app.fragment.FragmentComponentImpl
import org.oppia.android.app.fragment.InjectableFragment
import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2
import org.oppia.android.util.platformparameter.PlatformParameterValue
import javax.inject.Inject

/** Fragment that contains an onboarding flow of the app. */
class OnboardingFragment : InjectableFragment() {
@Inject
lateinit var onboardingFragmentPresenterV1: OnboardingFragmentPresenterV1

@Inject
lateinit var onboardingFragmentPresenter: OnboardingFragmentPresenter

@Inject
@field:EnableOnboardingFlowV2
lateinit var enableOnboardingFlowV2: PlatformParameterValue<Boolean>

override fun onAttach(context: Context) {
super.onAttach(context)
(fragmentComponent as FragmentComponentImpl).inject(this)
Expand All @@ -24,6 +33,10 @@ class OnboardingFragment : InjectableFragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return onboardingFragmentPresenter.handleCreateView(inflater, container)
return if (enableOnboardingFlowV2.value) {
onboardingFragmentPresenter.handleCreateView(inflater, container)
} else {
onboardingFragmentPresenterV1.handleCreateView(inflater, container)
}
}
}
Loading

0 comments on commit 8e5cb49

Please sign in to comment.