Show rule relative time in list

pull/214/head
M66B 12 months ago
parent ff3a992cee
commit 5137772fa0

@ -167,9 +167,18 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
if (jcondition.has("date")) if (jcondition.has("date"))
conditions.add(new Condition(context.getString(R.string.title_rule_time_abs), conditions.add(new Condition(context.getString(R.string.title_rule_time_abs),
null, null)); null, null));
if (jcondition.has("schedule")) if (jcondition.has("schedule")) {
String range = null;
JSONObject jschedule = jcondition.optJSONObject("schedule");
if (jschedule != null && jschedule.has("start") && jschedule.has("end")) {
int start = jschedule.getInt("start");
int end = jschedule.getInt("end");
range = Helper.formatHour(context, start % (24 * 60)) + " - " +
Helper.formatHour(context, end % (24 * 60));
}
conditions.add(new Condition(context.getString(R.string.title_rule_time_rel), conditions.add(new Condition(context.getString(R.string.title_rule_time_rel),
null, null)); range, null));
}
SpannableStringBuilder ssb = new SpannableStringBuilderEx(); SpannableStringBuilder ssb = new SpannableStringBuilderEx();
for (Condition condition : conditions) { for (Condition condition : conditions) {

@ -1109,14 +1109,14 @@ public class FragmentRule extends FragmentBase {
private void onScheduleStart(Bundle args) { private void onScheduleStart(Bundle args) {
int minutes = args.getInt("minutes", 0); int minutes = args.getInt("minutes", 0);
tvScheduleHourStart.setTag(minutes); tvScheduleHourStart.setTag(minutes);
tvScheduleHourStart.setText(formatHour(getContext(), minutes)); tvScheduleHourStart.setText(Helper.formatHour(getContext(), minutes));
cbScheduleEnd.setChecked(true); cbScheduleEnd.setChecked(true);
} }
private void onScheduleEnd(Bundle args) { private void onScheduleEnd(Bundle args) {
int minutes = args.getInt("minutes", 0); int minutes = args.getInt("minutes", 0);
tvScheduleHourEnd.setTag(minutes); tvScheduleHourEnd.setTag(minutes);
tvScheduleHourEnd.setText(formatHour(getContext(), minutes)); tvScheduleHourEnd.setText(Helper.formatHour(getContext(), minutes));
cbScheduleEnd.setChecked(true); cbScheduleEnd.setChecked(true);
} }
@ -1280,10 +1280,10 @@ public class FragmentRule extends FragmentBase {
spScheduleDayEnd.setSelection(end / (24 * 60)); spScheduleDayEnd.setSelection(end / (24 * 60));
tvScheduleHourStart.setTag(start % (24 * 60)); tvScheduleHourStart.setTag(start % (24 * 60));
tvScheduleHourStart.setText(formatHour(getContext(), start % (24 * 60))); tvScheduleHourStart.setText(Helper.formatHour(getContext(), start % (24 * 60)));
tvScheduleHourEnd.setTag(end % (24 * 60)); tvScheduleHourEnd.setTag(end % (24 * 60));
tvScheduleHourEnd.setText(formatHour(getContext(), end % (24 * 60))); tvScheduleHourEnd.setText(Helper.formatHour(getContext(), end % (24 * 60)));
if (rule == null) { if (rule == null) {
for (int pos = 0; pos < adapterIdentity.getCount(); pos++) for (int pos = 0; pos < adapterIdentity.getCount(); pos++)
@ -1829,15 +1829,6 @@ public class FragmentRule extends FragmentBase {
} }
} }
private String formatHour(Context context, int minutes) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, minutes / 60);
cal.set(Calendar.MINUTE, minutes % 60);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return Helper.getTimeInstance(context, SimpleDateFormat.SHORT).format(cal.getTime());
}
public static class TimePickerFragment extends FragmentDialogBase implements TimePickerDialog.OnTimeSetListener { public static class TimePickerFragment extends FragmentDialogBase implements TimePickerDialog.OnTimeSetListener {
@NonNull @NonNull
@Override @Override

@ -2307,6 +2307,15 @@ public class Helper {
return DateUtils.getRelativeTimeSpanString(context, millis); return DateUtils.getRelativeTimeSpanString(context, millis);
} }
static String formatHour(Context context, int minutes) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, minutes / 60);
cal.set(Calendar.MINUTE, minutes % 60);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return Helper.getTimeInstance(context, SimpleDateFormat.SHORT).format(cal.getTime());
}
static String formatDuration(long ms) { static String formatDuration(long ms) {
return formatDuration(ms, true); return formatDuration(ms, true);
} }

Loading…
Cancel
Save