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;
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<AttendanceSubItem> 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<AttendanceSubItem> subItems) {
int i = 0;
for (AttendanceSubItem subItem : subItems) {
@ -118,17 +143,16 @@ public class AttendanceHeaderItem
i++;
}
}
return i;
}
private boolean isSubItemsHasChanges(List<AttendanceSubItem> subItems) {
for (AttendanceSubItem subItem : subItems) {
if (subItem.getLesson().getIsAbsenceUnexcused() || subItem.getLesson().getIsUnexcusedLateness()) {
if (subItem.getLesson().getIsAbsenceUnexcused() || subItem.getLesson()
.getIsUnexcusedLateness()) {
return true;
}
}
return false;
}
}

View File

@ -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<TimetableSubItem> 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<TimetableSubItem> subItems) {
boolean isAlertActive = false;