From ba0737dc70958ba9306ea3b6cfa9335ad03b79fa Mon Sep 17 00:00:00 2001 From: andresmr Date: Tue, 20 Feb 2024 14:04:21 +0100 Subject: [PATCH] [ANDROAPP-5805] Remove connected rounded corners on landscape --- .../java/org/dhis2/bindings/Bindings.java | 114 +----------------- .../java/org/dhis2/bindings/ViewExtensions.kt | 56 ++++----- .../searchTrackEntity/SearchTEActivity.java | 7 +- .../SearchParametersScreen.kt | 19 ++- 4 files changed, 47 insertions(+), 149 deletions(-) diff --git a/app/src/main/java/org/dhis2/bindings/Bindings.java b/app/src/main/java/org/dhis2/bindings/Bindings.java index dac7553a33..85d4ca5b8b 100644 --- a/app/src/main/java/org/dhis2/bindings/Bindings.java +++ b/app/src/main/java/org/dhis2/bindings/Bindings.java @@ -1,41 +1,28 @@ package org.dhis2.bindings; -import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; -import android.graphics.Color; -import android.graphics.PorterDuff; -import android.graphics.Typeface; import android.graphics.drawable.AnimatedVectorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.util.TypedValue; import android.view.View; -import android.widget.AdapterView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import androidx.appcompat.content.res.AppCompatResources; -import androidx.appcompat.widget.AppCompatSpinner; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.databinding.BindingAdapter; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.google.android.material.floatingactionbutton.FloatingActionButton; - import org.dhis2.R; import org.dhis2.commons.animations.ViewAnimationsKt; -import org.dhis2.commons.filters.CatOptionComboFilter; -import org.dhis2.commons.data.ProgramEventViewModel; -import org.dhis2.utils.CatComboAdapter; import org.dhis2.utils.DateUtils; import org.dhis2.utils.NetworkUtils; -import org.hisp.dhis.android.core.category.CategoryOptionCombo; -import org.hisp.dhis.android.core.common.State; import org.hisp.dhis.android.core.enrollment.Enrollment; import org.hisp.dhis.android.core.enrollment.EnrollmentStatus; import org.hisp.dhis.android.core.event.Event; @@ -44,9 +31,7 @@ import org.hisp.dhis.android.core.program.Program; import org.hisp.dhis.android.core.program.ProgramStage; -import java.util.ArrayList; import java.util.Date; -import java.util.List; public class Bindings { @@ -55,10 +40,8 @@ public class Bindings { public static void setDrawableEnd(TextView textView, Drawable drawable) { textView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - if (drawable instanceof AnimatedVectorDrawable) - ((AnimatedVectorDrawable) drawable).start(); - } + if (drawable instanceof AnimatedVectorDrawable) + ((AnimatedVectorDrawable) drawable).start(); } @BindingAdapter(value = {"initGrid", "spanCount"}, requireAll = false) @@ -73,19 +56,6 @@ public static void setLayoutManager(RecyclerView recyclerView, boolean horizonta } - @BindingAdapter("spanSize") - public static void setSpanSize(RecyclerView recyclerView, boolean setSpanSize) { - if (recyclerView.getLayoutManager() instanceof GridLayoutManager) { - ((GridLayoutManager) recyclerView.getLayoutManager()).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { - @Override - public int getSpanSize(int position) { - int itemViewType = recyclerView.getAdapter().getItemViewType(position); - return (itemViewType == 4 || itemViewType == 8) ? 2 : 1; - } - }); - } - } - @BindingAdapter("enrolmentIcon") public static void setEnrolmentIcon(ImageView view, EnrollmentStatus status) { Drawable lock; @@ -133,27 +103,6 @@ public static void setEnrolmentText(TextView view, EnrollmentStatus status) { view.setText(text); } - public static String enrollmentText(Context context, EnrollmentStatus status) { - String text; - if (status == null) - status = EnrollmentStatus.ACTIVE; - switch (status) { - case ACTIVE: - text = context.getString(R.string.event_open); - break; - case COMPLETED: - text = context.getString(R.string.completed); - break; - case CANCELLED: - text = context.getString(R.string.cancelled); - break; - default: - text = context.getString(R.string.read_only); - break; - } - return text; - } - @BindingAdapter(value = {"eventStatusIcon", "enrollmentStatusIcon", "eventProgramStage", "eventProgram"}, requireAll = false) public static void setEventIcon(ImageView view, Event event, Enrollment enrollment, ProgramStage eventProgramStage, Program program) { if (event != null) { @@ -212,11 +161,9 @@ public static void setImageBackground(ImageView imageView, Drawable drawable) { TypedArray a = imageView.getContext().obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimaryDark}); TypedArray b = imageView.getContext().obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimaryLight}); int colorPrimaryDark = a.getColor(0, 0); - int colorPrimaryLight = b.getColor(0, 0); int px = (int) (1 * Resources.getSystem().getDisplayMetrics().density); ((GradientDrawable) drawable.mutate()).setStroke(px, colorPrimaryDark); - //((GradientDrawable) drawable.mutate()).setColor(colorPrimaryLight); imageView.setBackground(drawable); @@ -253,36 +200,6 @@ public static void setNetworkVisibility(View view, boolean checkNetwork) { } } - @BindingAdapter(value = {"catComboAdapterData", "catComboAdapterTitle"}) - public static void setCatComboAdapter(AppCompatSpinner spinner, List catComboAdapterData, String catComboAdapterTitle) { - CatComboAdapter spinnerAdapter = new CatComboAdapter(spinner.getContext(), - R.layout.spinner_layout, - R.id.spinner_text, - catComboAdapterData != null ? catComboAdapterData : new ArrayList<>(), - catComboAdapterTitle, - R.color.white_faf); - - spinner.setAdapter(spinnerAdapter); - } - - @BindingAdapter("onCatComboSelected") - public static void setOnCatComboSelected(AppCompatSpinner spinner, CatOptionComboFilter itemFilter) { - spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView adapterView, View view, int position, long l) { - if (position != 0) { - itemFilter.selectCatOptionCombo(position - 1); - spinner.setSelection(0); - } - } - - @Override - public void onNothingSelected(AdapterView adapterView) { - - } - }); - } - @BindingAdapter(value = {"dataSetStatus"}) public static void setDataSetStatusIcon(ImageView view, Boolean isComplete) { int drawableResource = isComplete ? R.drawable.ic_event_status_complete : R.drawable.ic_event_status_open; @@ -295,38 +212,11 @@ public static void setDataSetStatusIcon(ImageView view, Boolean isComplete) { view.setTag(drawableResource); } - @BindingAdapter("textStyle") - public static void setTextStyle(TextView textView, int style) { - switch (style) { - case Typeface.BOLD: - textView.setTypeface(null, Typeface.BOLD); - break; - default: - textView.setTypeface(null, Typeface.NORMAL); - break; - - } - } - @BindingAdapter("clipCorners") public static void setClipCorners(View view, int cornerRadiusInDp) { ViewExtensionsKt.clipWithRoundedCorners(view, ExtensionsKt.getDp(cornerRadiusInDp)); } - @BindingAdapter("clipAllCorners") - public static void setAllClipCorners(View view, int cornerRadiusInDp) { - ViewExtensionsKt.clipWithAllRoundedCorners(view, ExtensionsKt.getDp(cornerRadiusInDp)); - } - - @BindingAdapter("fabVisibility") - public static void setFabVisibility(FloatingActionButton fab, boolean isVisible) { - if (isVisible) { - fab.show(); - } else { - fab.hide(); - } - } - @BindingAdapter("viewVisibility") public static void setViewVisibility(View view, boolean isVisible) { if (isVisible) { diff --git a/app/src/main/java/org/dhis2/bindings/ViewExtensions.kt b/app/src/main/java/org/dhis2/bindings/ViewExtensions.kt index 0ccb1d7069..90318177fb 100644 --- a/app/src/main/java/org/dhis2/bindings/ViewExtensions.kt +++ b/app/src/main/java/org/dhis2/bindings/ViewExtensions.kt @@ -1,8 +1,6 @@ package org.dhis2.bindings import android.graphics.Outline -import android.os.Build -import android.util.TypedValue import android.view.View import android.view.ViewOutlineProvider import android.view.inputmethod.EditorInfo @@ -11,15 +9,7 @@ import android.widget.ListPopupWindow import android.widget.Spinner import android.widget.TextView import com.google.android.material.floatingactionbutton.FloatingActionButton -import com.tbuonomo.viewpagerdotsindicator.R import org.dhis2.commons.extensions.closeKeyboard -import java.lang.Exception - -fun View.getThemePrimaryColor(): Int { - val value = TypedValue() - context.theme.resolveAttribute(R.attr.colorPrimary, value, true) - return value.data -} fun View.onFocusRemoved(onFocusRemovedCallback: () -> Unit) { setOnFocusChangeListener { view, hasFocus -> @@ -42,37 +32,33 @@ fun TextView.clearFocusOnDone() { } fun View.clipWithRoundedCorners(curvedRadio: Int = 16.dp) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - outlineProvider = object : ViewOutlineProvider() { - override fun getOutline(view: View, outline: Outline) { - outline.setRoundRect( - 0, - 0, - view.width, - view.height + curvedRadio, - curvedRadio.toFloat(), - ) - } + outlineProvider = object : ViewOutlineProvider() { + override fun getOutline(view: View, outline: Outline) { + outline.setRoundRect( + 0, + 0, + view.width, + view.height + curvedRadio, + curvedRadio.toFloat(), + ) } - clipToOutline = true } + clipToOutline = true } -fun View.clipWithAllRoundedCorners(curvedRadio: Int = 16.dp) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - outlineProvider = object : ViewOutlineProvider() { - override fun getOutline(view: View, outline: Outline) { - outline.setRoundRect( - 0, - 0, - view.width, - view.height, - curvedRadio.toFloat(), - ) - } +fun View.clipWithTopRightRoundedCorner(curvedRadio: Int = 16.dp) { + outlineProvider = object : ViewOutlineProvider() { + override fun getOutline(view: View, outline: Outline) { + outline.setRoundRect( + 0 - curvedRadio, + 0, + view.width, + view.height + curvedRadio, + curvedRadio.toFloat(), + ) } - clipToOutline = true } + clipToOutline = true } fun Spinner.overrideHeight(desiredHeight: Int) { diff --git a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEActivity.java b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEActivity.java index 512181fdb3..2cf88b2dd3 100644 --- a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEActivity.java +++ b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEActivity.java @@ -173,7 +173,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { } binding.setPresenter(presenter); binding.setTotalFilters(FilterManager.getInstance().getTotalFilters()); - ViewExtensionsKt.clipWithRoundedCorners(binding.mainComponent, ExtensionsKt.getDp(16)); + + if (OrientationUtilsKt.isPortrait()) { + ViewExtensionsKt.clipWithRoundedCorners(binding.mainComponent, ExtensionsKt.getDp(16)); + } else { + ViewExtensionsKt.clipWithTopRightRoundedCorner(binding.mainComponent, ExtensionsKt.getDp(16)); + } binding.filterRecyclerLayout.setAdapter(filtersAdapter); diff --git a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/searchparameters/SearchParametersScreen.kt b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/searchparameters/SearchParametersScreen.kt index a81e6bf1af..93455d50de 100644 --- a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/searchparameters/SearchParametersScreen.kt +++ b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/searchparameters/SearchParametersScreen.kt @@ -1,5 +1,6 @@ package org.dhis2.usescases.searchTrackEntity.searchparameters +import android.content.res.Configuration import androidx.activity.compose.rememberLauncherForActivityResult import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column @@ -7,6 +8,8 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.shape.CornerSize +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material.Icon import androidx.compose.material.Scaffold @@ -22,6 +25,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.testTag @@ -47,6 +51,7 @@ import org.hisp.dhis.android.core.common.ValueType import org.hisp.dhis.mobile.ui.designsystem.component.Button import org.hisp.dhis.mobile.ui.designsystem.component.ButtonStyle import org.hisp.dhis.mobile.ui.designsystem.component.parameter.ParameterSelectorItem +import org.hisp.dhis.mobile.ui.designsystem.theme.Radius import org.hisp.dhis.mobile.ui.designsystem.theme.Shape import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor @@ -68,6 +73,7 @@ fun SearchParametersScreen( val snackBarHostState = scaffoldState.snackbarHostState val coroutineScope = rememberCoroutineScope() val focusManager = LocalFocusManager.current + val configuration = LocalConfiguration.current val qrScanLauncher = rememberLauncherForActivityResult( contract = ScanContract(), @@ -138,6 +144,17 @@ fun SearchParametersScreen( } } + val backgroundShape = when (configuration.orientation) { + Configuration.ORIENTATION_LANDSCAPE -> RoundedCornerShape( + topStart = CornerSize(Radius.L), + topEnd = CornerSize(Radius.NoRounding), + bottomEnd = CornerSize(Radius.NoRounding), + bottomStart = CornerSize(Radius.NoRounding), + ) + + else -> Shape.LargeTop + } + Scaffold( backgroundColor = Color.Transparent, scaffoldState = scaffoldState, @@ -156,7 +173,7 @@ fun SearchParametersScreen( Column( modifier = Modifier .fillMaxSize() - .background(color = Color.White, shape = Shape.LargeTop) + .background(color = Color.White, shape = backgroundShape) .padding(it), ) { Column(