1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-11-23 17:26:04 -06:00

Fix inactive elements (#69)

This commit is contained in:
Rafał Borcz 2018-03-14 20:22:31 +01:00 committed by Mikołaj Pich
parent 64b964ca18
commit 797e233809
2 changed files with 57 additions and 9 deletions

View File

@ -1,5 +1,8 @@
package io.github.wulkanowy.ui.main.attendance; 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.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
@ -87,10 +90,16 @@ public class AttendanceHeaderItem
@BindColor(R.color.free_day) @BindColor(R.color.free_day)
int backgroundFreeDay; int backgroundFreeDay;
@BindColor(android.R.color.black)
int black;
private Context context;
HeaderViewHolder(View view, FlexibleAdapter adapter) { HeaderViewHolder(View view, FlexibleAdapter adapter) {
super(view, adapter); super(view, adapter);
view.setOnClickListener(this); view.setOnClickListener(this);
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
context = view.getContext();
} }
void onBind(Day item, List<AttendanceSubItem> subItems) { void onBind(Day item, List<AttendanceSubItem> subItems) {
@ -103,14 +112,30 @@ public class AttendanceHeaderItem
description.setVisibility(numberOfHours > 0 ? View.VISIBLE : View.INVISIBLE); description.setVisibility(numberOfHours > 0 ? View.VISIBLE : View.INVISIBLE);
alert.setVisibility(isSubItemsHasChanges(subItems) ? View.VISIBLE : View.INVISIBLE); alert.setVisibility(isSubItemsHasChanges(subItems) ? View.VISIBLE : View.INVISIBLE);
freeName.setVisibility(subItems.isEmpty() ? 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); 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<AttendanceSubItem> subItems) { private int countNotPresentHours(List<AttendanceSubItem> subItems) {
int i = 0; int i = 0;
for (AttendanceSubItem subItem : subItems) { for (AttendanceSubItem subItem : subItems) {
@ -118,17 +143,16 @@ public class AttendanceHeaderItem
i++; i++;
} }
} }
return i; return i;
} }
private boolean isSubItemsHasChanges(List<AttendanceSubItem> subItems) { private boolean isSubItemsHasChanges(List<AttendanceSubItem> subItems) {
for (AttendanceSubItem subItem : subItems) { for (AttendanceSubItem subItem : subItems) {
if (subItem.getLesson().getIsAbsenceUnexcused() || subItem.getLesson().getIsUnexcusedLateness()) { if (subItem.getLesson().getIsAbsenceUnexcused() || subItem.getLesson()
.getIsUnexcusedLateness()) {
return true; return true;
} }
} }
return false; return false;
} }
} }

View File

@ -1,5 +1,8 @@
package io.github.wulkanowy.ui.main.timetable; 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.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
@ -84,10 +87,16 @@ public class TimetableHeaderItem
@BindColor(R.color.free_day) @BindColor(R.color.free_day)
int backgroundFreeDay; int backgroundFreeDay;
@BindColor(android.R.color.black)
int black;
private Context context;
HeaderViewHolder(View view, FlexibleAdapter adapter) { HeaderViewHolder(View view, FlexibleAdapter adapter) {
super(view, adapter); super(view, adapter);
view.setOnClickListener(this); view.setOnClickListener(this);
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
context = view.getContext();
} }
void onBind(Day item, List<TimetableSubItem> subItems) { void onBind(Day item, List<TimetableSubItem> subItems) {
@ -96,14 +105,29 @@ public class TimetableHeaderItem
alert.setVisibility(isSubItemNewMovedInOrChanged(subItems) ? View.VISIBLE : View.INVISIBLE); alert.setVisibility(isSubItemNewMovedInOrChanged(subItems) ? View.VISIBLE : View.INVISIBLE);
freeName.setVisibility(item.getIsFreeDay() ? View.VISIBLE : View.INVISIBLE); freeName.setVisibility(item.getIsFreeDay() ? View.VISIBLE : View.INVISIBLE);
freeName.setText(item.getFreeDayName()); freeName.setText(item.getFreeDayName());
setInactiveHeader(item.getIsFreeDay());
}
if (item.getIsFreeDay()) { private void setInactiveHeader(boolean inactive) {
((FrameLayout) getContentView()).setForeground(null); ((FrameLayout) getContentView()).setForeground(inactive ? null : getSelectableDrawable());
dayName.setTextColor(inactive ? secondaryColor : black);
if (inactive) {
getContentView().setBackgroundColor(backgroundFreeDay); 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<TimetableSubItem> subItems) { private boolean isSubItemNewMovedInOrChanged(List<TimetableSubItem> subItems) {
boolean isAlertActive = false; boolean isAlertActive = false;