-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use expandable groups in all list views (#487)
* Migrate from ListView to ExpandableListView * Group alert log by year * Group test alarms in overview * Group test alarm contexts by activate state * Group alert log by year * Group test alarm contexts by activate state * Group shifts by year month
- Loading branch information
Showing
27 changed files
with
877 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
app/src/main/java/com/github/frimtec/android/pikettassist/ui/alerts/AlertArrayAdapter.java
This file was deleted.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
...in/java/com/github/frimtec/android/pikettassist/ui/alerts/AlertExpandableListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.github.frimtec.android.pikettassist.ui.alerts; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseExpandableListAdapter; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.github.frimtec.android.pikettassist.R; | ||
import com.github.frimtec.android.pikettassist.domain.Alert; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
class AlertExpandableListAdapter extends BaseExpandableListAdapter { | ||
|
||
private final Context context; | ||
private final List<YearGroup> years; | ||
|
||
AlertExpandableListAdapter(Context context, List<Alert> alerts) { | ||
this.context = context; | ||
Map<Integer, List<Alert>> groupedAlerts = alerts.stream() | ||
.collect(Collectors.groupingBy( | ||
alert -> LocalDateTime.ofInstant(alert.startTime(), ZoneId.systemDefault()).getYear()) | ||
); | ||
this.years = groupedAlerts.keySet() | ||
.stream() | ||
.sorted(Comparator.reverseOrder()) | ||
.map(year -> new YearGroup(year, groupedAlerts.get(year))) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public int getGroupCount() { | ||
return this.years.size(); | ||
} | ||
|
||
@Override | ||
public int getChildrenCount(int groupPosition) { | ||
return this.years.get(groupPosition).alerts().size(); | ||
} | ||
|
||
@Override | ||
public Object getGroup(int groupPosition) { | ||
return this.years.get(groupPosition); | ||
} | ||
|
||
@Override | ||
public Object getChild(int groupPosition, int childPosition) { | ||
return this.years.get(groupPosition).alerts().get(childPosition); | ||
} | ||
|
||
@Override | ||
public long getGroupId(int groupPosition) { | ||
return groupPosition; | ||
} | ||
|
||
@Override | ||
public long getChildId(int groupPosition, int childPosition) { | ||
return groupPosition * 1_000_000L + childPosition; | ||
} | ||
|
||
@Override | ||
public boolean hasStableIds() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { | ||
YearGroup yearGroup = this.years.get(groupPosition); | ||
if (convertView == null) { | ||
convertView = LayoutInflater.from(this.context).inflate(R.layout.general_list_group_item, parent, false); | ||
} | ||
TextView title = convertView.findViewById(R.id.general_list_group_item_title); | ||
title.setText(String.format(Locale.getDefault(), "%d (%d)", yearGroup.year(), yearGroup.alerts().size())); | ||
return convertView; | ||
} | ||
|
||
@Override | ||
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { | ||
Alert alert = this.years.get(groupPosition).alerts().get(childPosition); | ||
Objects.requireNonNull(alert); | ||
if (convertView == null) { | ||
convertView = LayoutInflater.from(this.context).inflate(R.layout.alert_log_item, parent, false); | ||
} | ||
ImageView playIcon = convertView.findViewById(R.id.alert_log_item_image_play); | ||
playIcon.setVisibility(alert.isClosed() ? View.INVISIBLE : View.VISIBLE); | ||
TextView timeWindow = convertView.findViewById(R.id.alert_log_item_time_window); | ||
TextView durations = convertView.findViewById(R.id.alert_log_item_durations); | ||
timeWindow.setText(AlertViewHelper.getTimeWindow(alert)); | ||
durations.setText(AlertViewHelper.getDurations(this.context, alert)); | ||
return convertView; | ||
} | ||
|
||
@Override | ||
public boolean isChildSelectable(int groupPosition, int childPosition) { | ||
return true; | ||
} | ||
} |
Oops, something went wrong.