Skip to content

Commit

Permalink
[ANDROAPP-5805] Remove connected rounded corners on landscape
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmr committed Feb 20, 2024
1 parent 885e672 commit ba0737d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 149 deletions.
114 changes: 2 additions & 112 deletions app/src/main/java/org/dhis2/bindings/Bindings.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -253,36 +200,6 @@ public static void setNetworkVisibility(View view, boolean checkNetwork) {
}
}

@BindingAdapter(value = {"catComboAdapterData", "catComboAdapterTitle"})
public static void setCatComboAdapter(AppCompatSpinner spinner, List<CategoryOptionCombo> 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;
Expand All @@ -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) {
Expand Down
56 changes: 21 additions & 35 deletions app/src/main/java/org/dhis2/bindings/ViewExtensions.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 ->
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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
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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit ba0737d

Please sign in to comment.