From 797e233809c4492103f6cd68825d4768956f13cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Wed, 14 Mar 2018 20:22:31 +0100 Subject: [PATCH] Fix inactive elements (#69) --- .../main/attendance/AttendanceHeaderItem.java | 36 +++++++++++++++---- .../main/timetable/TimetableHeaderItem.java | 30 ++++++++++++++-- 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendanceHeaderItem.java b/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendanceHeaderItem.java index b103a007a..306065eea 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendanceHeaderItem.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/attendance/AttendanceHeaderItem.java @@ -1,5 +1,8 @@ package io.github.wulkanowy.ui.main.attendance; +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; import android.view.View; import android.widget.FrameLayout; import android.widget.ImageView; @@ -87,10 +90,16 @@ public class AttendanceHeaderItem @BindColor(R.color.free_day) int backgroundFreeDay; + @BindColor(android.R.color.black) + int black; + + private Context context; + HeaderViewHolder(View view, FlexibleAdapter adapter) { super(view, adapter); view.setOnClickListener(this); ButterKnife.bind(this, view); + context = view.getContext(); } void onBind(Day item, List subItems) { @@ -103,14 +112,30 @@ public class AttendanceHeaderItem description.setVisibility(numberOfHours > 0 ? View.VISIBLE : View.INVISIBLE); alert.setVisibility(isSubItemsHasChanges(subItems) ? View.VISIBLE : View.INVISIBLE); freeName.setVisibility(subItems.isEmpty() ? View.VISIBLE : View.INVISIBLE); + setInactiveHeader(item.getAttendanceLessons().isEmpty()); + } - if (item.getAttendanceLessons().isEmpty()) { - ((FrameLayout) getContentView()).setForeground(null); + + private void setInactiveHeader(boolean inactive) { + ((FrameLayout) getContentView()).setForeground(inactive ? null : getSelectableDrawable()); + dayName.setTextColor(inactive ? secondaryColor : black); + + if (inactive) { getContentView().setBackgroundColor(backgroundFreeDay); - dayName.setTextColor(secondaryColor); + } else { + getContentView().setBackgroundDrawable(context.getResources() + .getDrawable(R.drawable.ic_border)); } } + private Drawable getSelectableDrawable() { + int[] attrs = new int[]{R.attr.selectableItemBackground}; + TypedArray typedArray = context.obtainStyledAttributes(attrs); + Drawable drawable = typedArray.getDrawable(0); + typedArray.recycle(); + return drawable; + } + private int countNotPresentHours(List subItems) { int i = 0; for (AttendanceSubItem subItem : subItems) { @@ -118,17 +143,16 @@ public class AttendanceHeaderItem i++; } } - return i; } private boolean isSubItemsHasChanges(List subItems) { for (AttendanceSubItem subItem : subItems) { - if (subItem.getLesson().getIsAbsenceUnexcused() || subItem.getLesson().getIsUnexcusedLateness()) { + if (subItem.getLesson().getIsAbsenceUnexcused() || subItem.getLesson() + .getIsUnexcusedLateness()) { return true; } } - return false; } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableHeaderItem.java b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableHeaderItem.java index 39a8f0122..d704e8a3a 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableHeaderItem.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/timetable/TimetableHeaderItem.java @@ -1,5 +1,8 @@ package io.github.wulkanowy.ui.main.timetable; +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; import android.view.View; import android.widget.FrameLayout; import android.widget.ImageView; @@ -84,10 +87,16 @@ public class TimetableHeaderItem @BindColor(R.color.free_day) int backgroundFreeDay; + @BindColor(android.R.color.black) + int black; + + private Context context; + HeaderViewHolder(View view, FlexibleAdapter adapter) { super(view, adapter); view.setOnClickListener(this); ButterKnife.bind(this, view); + context = view.getContext(); } void onBind(Day item, List subItems) { @@ -96,14 +105,29 @@ public class TimetableHeaderItem alert.setVisibility(isSubItemNewMovedInOrChanged(subItems) ? View.VISIBLE : View.INVISIBLE); freeName.setVisibility(item.getIsFreeDay() ? View.VISIBLE : View.INVISIBLE); freeName.setText(item.getFreeDayName()); + setInactiveHeader(item.getIsFreeDay()); + } - if (item.getIsFreeDay()) { - ((FrameLayout) getContentView()).setForeground(null); + private void setInactiveHeader(boolean inactive) { + ((FrameLayout) getContentView()).setForeground(inactive ? null : getSelectableDrawable()); + dayName.setTextColor(inactive ? secondaryColor : black); + + if (inactive) { getContentView().setBackgroundColor(backgroundFreeDay); - dayName.setTextColor(secondaryColor); + } else { + getContentView().setBackgroundDrawable(context.getResources() + .getDrawable(R.drawable.ic_border)); } } + private Drawable getSelectableDrawable() { + int[] attrs = new int[]{R.attr.selectableItemBackground}; + TypedArray typedArray = context.obtainStyledAttributes(attrs); + Drawable drawable = typedArray.getDrawable(0); + typedArray.recycle(); + return drawable; + } + private boolean isSubItemNewMovedInOrChanged(List subItems) { boolean isAlertActive = false;