From 3435a0844d3a91f82d757d8e81b0bd107f329ca0 Mon Sep 17 00:00:00 2001 From: Adhiambo Peres <59600948+adhiamboperes@users.noreply.github.com> Date: Mon, 30 Oct 2023 17:50:16 +0300 Subject: [PATCH 01/13] Refactor SurveyOnboardingBackgroundView to be a generic OppiaCurveBackgroundView Since many new designs include this custom shape, we can now reuse this view by passing in the desired background color. --- ...undView.kt => OppiaCurveBackgroundView.kt} | 33 +++++++++---------- .../android/app/view/ViewComponentImpl.kt | 4 +-- .../survey_welcome_dialog_fragment.xml | 8 +++-- .../survey_welcome_dialog_fragment.xml | 7 ++-- .../layout/survey_outro_dialog_fragment.xml | 3 +- .../layout/survey_welcome_dialog_fragment.xml | 5 +-- app/src/main/res/values/attrs.xml | 4 +++ 7 files changed, 36 insertions(+), 28 deletions(-) rename app/src/main/java/org/oppia/android/app/customview/{SurveyOnboardingBackgroundView.kt => OppiaCurveBackgroundView.kt} (77%) diff --git a/app/src/main/java/org/oppia/android/app/customview/SurveyOnboardingBackgroundView.kt b/app/src/main/java/org/oppia/android/app/customview/OppiaCurveBackgroundView.kt similarity index 77% rename from app/src/main/java/org/oppia/android/app/customview/SurveyOnboardingBackgroundView.kt rename to app/src/main/java/org/oppia/android/app/customview/OppiaCurveBackgroundView.kt index 4ef674dc6ab..1b9063aa4f3 100644 --- a/app/src/main/java/org/oppia/android/app/customview/SurveyOnboardingBackgroundView.kt +++ b/app/src/main/java/org/oppia/android/app/customview/OppiaCurveBackgroundView.kt @@ -1,13 +1,13 @@ package org.oppia.android.app.customview import android.content.Context +import android.content.res.TypedArray 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 @@ -18,13 +18,16 @@ 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 { +class OppiaCurveBackgroundView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : View(context, attrs, defStyleAttr) { @Inject lateinit var resourceHandler: AppLanguageResourceHandler @@ -32,19 +35,18 @@ class SurveyOnboardingBackgroundView : View { resourceHandler.getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL } + 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 { + val typedArray: TypedArray = + context.obtainStyledAttributes(attrs, R.styleable.OppiaCurveBackgroundView) + customBackgroundColor = + typedArray.getColor(R.styleable.OppiaCurveBackgroundView_customBackgroundColor, Color.WHITE) + typedArray.recycle() setupCurvePaint() } @@ -91,11 +93,8 @@ class SurveyOnboardingBackgroundView : View { 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 - ) + strokeWidth = this@OppiaCurveBackgroundView.strokeWidth + color = customBackgroundColor } setBackgroundColor(Color.TRANSPARENT) } diff --git a/app/src/main/java/org/oppia/android/app/view/ViewComponentImpl.kt b/app/src/main/java/org/oppia/android/app/view/ViewComponentImpl.kt index 08726cc7f49..ecb07ff3e28 100644 --- a/app/src/main/java/org/oppia/android/app/view/ViewComponentImpl.kt +++ b/app/src/main/java/org/oppia/android/app/view/ViewComponentImpl.kt @@ -6,9 +6,9 @@ import dagger.Subcomponent import org.oppia.android.app.customview.ChapterNotStartedContainerConstraintLayout import org.oppia.android.app.customview.ContinueButtonView import org.oppia.android.app.customview.LessonThumbnailImageView +import org.oppia.android.app.customview.OppiaCurveBackgroundView import org.oppia.android.app.customview.PromotedStoryCardView import org.oppia.android.app.customview.SegmentedCircularProgressView -import org.oppia.android.app.customview.SurveyOnboardingBackgroundView import org.oppia.android.app.home.promotedlist.ComingSoonTopicsListView import org.oppia.android.app.home.promotedlist.PromotedStoryListView import org.oppia.android.app.player.state.DragDropSortInteractionView @@ -42,7 +42,7 @@ interface ViewComponentImpl : ViewComponent { fun inject(promotedStoryCardView: PromotedStoryCardView) fun inject(promotedStoryListView: PromotedStoryListView) fun inject(segmentedCircularProgressView: SegmentedCircularProgressView) - fun inject(surveyOnboardingBackgroundView: SurveyOnboardingBackgroundView) + fun inject(curveBackgroundView: OppiaCurveBackgroundView) fun inject(surveyMultipleChoiceOptionView: SurveyMultipleChoiceOptionView) fun inject(surveyNpsItemOptionView: SurveyNpsItemOptionView) } diff --git a/app/src/main/res/layout-land/survey_welcome_dialog_fragment.xml b/app/src/main/res/layout-land/survey_welcome_dialog_fragment.xml index 9a41b4cf558..86fd12d45b6 100644 --- a/app/src/main/res/layout-land/survey_welcome_dialog_fragment.xml +++ b/app/src/main/res/layout-land/survey_welcome_dialog_fragment.xml @@ -10,9 +10,10 @@ android:id="@+id/survey_onboarding_title_text" style="@style/SurveyPopupHeaderStyle" android:text="@string/survey_onboarding_title_text" + + app:layout_constraintBottom_toTopOf="@id/survey_onboarding_title_guide" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintBottom_toTopOf="@id/survey_onboarding_title_guide" app:layout_constraintTop_toTopOf="parent" /> -