Fixed some more time formatting

pull/159/head
M66B 5 years ago
parent ea14fa769a
commit 075d3dc6e9

@ -52,7 +52,6 @@ import androidx.recyclerview.widget.RecyclerView;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
@ -70,7 +69,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
private List<TupleAccountEx> items = new ArrayList<>();
private NumberFormat nf = NumberFormat.getNumberInstance();
private DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
private DateFormat DTF;
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
private View view;
@ -159,7 +158,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
tvHost.setText(String.format("%s:%d", account.host, account.port));
tvLast.setText(context.getString(R.string.title_last_connected,
account.last_connected == null ? "-" : df.format(account.last_connected)));
account.last_connected == null ? "-" : DTF.format(account.last_connected)));
tvAuthorize.setVisibility(account.auth_type == ConnectionHelper.AUTH_TYPE_PASSWORD ? View.GONE : View.VISIBLE);
tvIdentity.setVisibility(account.identities > 0 || !settings ? View.GONE : View.VISIBLE);
@ -289,6 +288,8 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
this.colorUnread = Helper.resolveColor(context, R.attr.colorUnread);
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
this.DTF = Helper.getDateTimeInstance(context, DateFormat.SHORT, DateFormat.SHORT);
setHasStableIds(true);
owner.getLifecycle().addObserver(new LifecycleObserver() {

@ -45,7 +45,6 @@ import androidx.recyclerview.widget.RecyclerView;
import java.text.Collator;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -60,7 +59,7 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
private List<TupleIdentityEx> items = new ArrayList<>();
private DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
private DateFormat DTF;
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
private View view;
@ -127,7 +126,7 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
tvHost.setText(String.format("%s:%d", identity.host, identity.port));
tvAccount.setText(identity.accountName);
tvLast.setText(context.getString(R.string.title_last_connected,
identity.last_connected == null ? "-" : df.format(identity.last_connected)));
identity.last_connected == null ? "-" : DTF.format(identity.last_connected)));
tvAuthorize.setVisibility(identity.auth_type == ConnectionHelper.AUTH_TYPE_PASSWORD ? View.GONE : View.VISIBLE);
@ -219,6 +218,8 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
this.owner = parentFragment.getViewLifecycleOwner();
this.inflater = LayoutInflater.from(context);
this.DTF = Helper.getDateTimeInstance(context, DateFormat.SHORT, DateFormat.SHORT);
setHasStableIds(true);
owner.getLifecycle().addObserver(new LifecycleObserver() {

@ -36,7 +36,6 @@ import androidx.recyclerview.widget.ListUpdateCallback;
import androidx.recyclerview.widget.RecyclerView;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
@ -48,7 +47,7 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
private List<EntityLog> items = new ArrayList<>();
private DateFormat TF = SimpleDateFormat.getTimeInstance();
private DateFormat TF;
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView tvTime;
@ -74,6 +73,8 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
this.owner = parentFragment.getViewLifecycleOwner();
this.inflater = LayoutInflater.from(parentFragment.getContext());
this.TF = Helper.getTimeInstance(context);
setHasStableIds(true);
owner.getLifecycle().addObserver(new LifecycleObserver() {

@ -194,7 +194,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private NumberFormat NF = NumberFormat.getNumberInstance();
private DateFormat TF;
private DateFormat DTF = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG, SimpleDateFormat.LONG);
private DateFormat DTF;
private static final List<String> PARANOID_QUERY = Collections.unmodifiableList(Arrays.asList(
"utm_source",
@ -1192,7 +1192,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return;
}
DateFormat df = SimpleDateFormat.getDateTimeInstance();
DateFormat DTF = Helper.getDateTimeInstance(context);
VEvent event = icalendar.getEvents().get(0);
@ -1221,10 +1221,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvCalendarSummary.setText(summary == null ? null : summary.getValue());
tvCalendarSummary.setVisibility(summary == null ? View.GONE : View.VISIBLE);
tvCalendarStart.setText(start == null ? null : df.format(start.getTime()));
tvCalendarStart.setText(start == null ? null : DTF.format(start.getTime()));
tvCalendarStart.setVisibility(start == null ? View.GONE : View.VISIBLE);
tvCalendarEnd.setText(end == null ? null : df.format(end.getTime()));
tvCalendarEnd.setText(end == null ? null : DTF.format(end.getTime()));
tvCalendarEnd.setVisibility(end == null ? View.GONE : View.VISIBLE);
tvAttendees.setText(TextUtils.join(", ", attendee));
@ -1517,11 +1517,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private void onShowSnoozed(TupleMessageEx message) {
if (message.ui_snoozed != null) {
DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM, SimpleDateFormat.SHORT);
DateFormat day = new SimpleDateFormat("E");
DateFormat DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.MEDIUM, SimpleDateFormat.SHORT);
DateFormat D = new SimpleDateFormat("E");
Snackbar.make(
parentFragment.getView(),
day.format(message.ui_snoozed) + " " + df.format(message.ui_snoozed),
D.format(message.ui_snoozed) + " " + DTF.format(message.ui_snoozed),
Snackbar.LENGTH_LONG).show();
}
}
@ -2883,6 +2883,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.suitable = ConnectionHelper.getNetworkState(context).isSuitable();
this.inflater = LayoutInflater.from(context);
this.TF = Helper.getTimeInstance(context, SimpleDateFormat.SHORT);
this.DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.LONG, SimpleDateFormat.LONG);
this.dp36 = Helper.dp2pixels(context, 36);
this.colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);

@ -46,7 +46,7 @@ public class AdapterRuleMatch extends RecyclerView.Adapter<AdapterRuleMatch.View
private List<EntityMessage> items = new ArrayList<>();
private DateFormat DF = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
private DateFormat DTF;
public class ViewHolder extends RecyclerView.ViewHolder {
private View view;
@ -68,7 +68,7 @@ public class AdapterRuleMatch extends RecyclerView.Adapter<AdapterRuleMatch.View
}
private void bindTo(EntityMessage message) {
tvTime.setText(DF.format(message.received));
tvTime.setText(DTF.format(message.received));
tvSubject.setText(message.subject);
}
}
@ -78,6 +78,8 @@ public class AdapterRuleMatch extends RecyclerView.Adapter<AdapterRuleMatch.View
this.owner = owner;
this.inflater = LayoutInflater.from(context);
this.DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
setHasStableIds(true);
owner.getLifecycle().addObserver(new LifecycleObserver() {

@ -2034,13 +2034,13 @@ class Core {
.setPublicVersion(pub);
if (!biometrics) {
DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
DateFormat DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
StringBuilder sb = new StringBuilder();
for (EntityMessage message : messages) {
sb.append("<strong>").append(messageContact.get(message).getDisplayName(true)).append("</strong>");
if (!TextUtils.isEmpty(message.subject))
sb.append(": ").append(message.subject);
sb.append(" ").append(df.format(message.received));
sb.append(" ").append(DTF.format(message.received));
sb.append("<br>");
}

@ -130,7 +130,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@ -2691,8 +2690,8 @@ public class FragmentCompose extends FragmentBase {
if (draft.ui_snoozed == null)
feedback = context.getString(R.string.title_queued);
else {
DateFormat df = SimpleDateFormat.getDateTimeInstance();
feedback = context.getString(R.string.title_queued_at, df.format(draft.ui_snoozed));
DateFormat DTF = Helper.getDateTimeInstance(context);
feedback = context.getString(R.string.title_queued_at, DTF.format(draft.ui_snoozed));
}
Handler handler = new Handler(context.getMainLooper());

@ -65,8 +65,8 @@ public class FragmentDialogDuration extends DialogFragmentEx {
cal.setTimeInMillis(savedInstanceState.getLong("fair:time"));
Log.i("Set init=" + new Date(cal.getTimeInMillis()));
final DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.FULL, SimpleDateFormat.SHORT);
tvDuration.setText(df.format(cal.getTime()));
final DateFormat DTF = Helper.getDateTimeInstance(getContext(), SimpleDateFormat.FULL, SimpleDateFormat.SHORT);
tvDuration.setText(DTF.format(cal.getTime()));
timePicker.setIs24HourView(android.text.format.DateFormat.is24HourFormat(getContext()));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@ -82,7 +82,7 @@ public class FragmentDialogDuration extends DialogFragmentEx {
public void onTimeChanged(TimePicker view, int hour, int minute) {
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, minute);
tvDuration.setText(df.format(cal.getTime()));
tvDuration.setText(DTF.format(cal.getTime()));
Log.i("Set hour=" + hour + " minute=" + minute +
" time=" + new Date(cal.getTimeInMillis()));
}
@ -98,7 +98,7 @@ public class FragmentDialogDuration extends DialogFragmentEx {
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, day);
tvDuration.setText(df.format(cal.getTime()));
tvDuration.setText(DTF.format(cal.getTime()));
Log.i("Set year=" + year + " month=" + month + " day=" + day +
" time=" + new Date(cal.getTimeInMillis()));
}

@ -4228,7 +4228,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
{
Element span = document.createElement("span");
DateFormat DTF = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG, SimpleDateFormat.LONG);
DateFormat DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.LONG, SimpleDateFormat.LONG);
span.text(getString(R.string.title_received) + " " + DTF.format(message.received));
p.append(span.html() + "<br>");
}

@ -46,8 +46,6 @@ import androidx.preference.PreferenceManager;
import com.bugsnag.android.Bugsnag;
import java.text.SimpleDateFormat;
public class FragmentOptionsMisc extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private SwitchCompat swBadge;
private SwitchCompat swSubscriptions;
@ -318,10 +316,10 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
private void setLastCleanup(long time) {
java.text.DateFormat df = SimpleDateFormat.getDateTimeInstance();
java.text.DateFormat DTF = Helper.getDateTimeInstance(getContext());
tvLastCleanup.setText(
getString(R.string.title_advanced_last_cleanup,
time < 0 ? "-" : df.format(time)));
time < 0 ? "-" : DTF.format(time)));
}
private void restart() {

@ -347,8 +347,17 @@ public class Helper {
return new DecimalFormat("@@").format(bytes / Math.pow(unit, exp)) + " " + pre + "B";
}
// https://issuetracker.google.com/issues/37054851
static DateFormat getTimeInstance(Context context) {
return Helper.getTimeInstance(context, SimpleDateFormat.MEDIUM);
}
static DateFormat getDateInstance(Context context) {
return SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM);
}
static DateFormat getTimeInstance(Context context, int style) {
// https://issuetracker.google.com/issues/37054851
if (context != null &&
(style == SimpleDateFormat.SHORT || style == SimpleDateFormat.MEDIUM)) {
Locale locale = Locale.getDefault();
@ -362,6 +371,15 @@ public class Helper {
return SimpleDateFormat.getTimeInstance(style);
}
static DateFormat getDateTimeInstance(Context context) {
return Helper.getDateTimeInstance(context, SimpleDateFormat.MEDIUM, SimpleDateFormat.MEDIUM);
}
static DateFormat getDateTimeInstance(Context context, int dateStyle, int timeStyle) {
// TODO fix time format
return SimpleDateFormat.getDateTimeInstance(dateStyle, timeStyle);
}
static CharSequence getRelativeTimeSpanString(Context context, long millis) {
long now = System.currentTimeMillis();
long span = Math.abs(now - millis);

@ -53,7 +53,6 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -410,10 +409,10 @@ public class Log {
long size = 0;
long from = new Date().getTime() - 24 * 3600 * 1000L;
DateFormat DF = SimpleDateFormat.getTimeInstance();
DateFormat TF = Helper.getTimeInstance(context);
for (EntityLog entry : db.log().getLogs(from))
size += write(os, String.format("%s %s\r\n", DF.format(entry.time), entry.data));
size += write(os, String.format("%s %s\r\n", TF.format(entry.time), entry.data));
db.attachment().setDownloaded(attachment.id, size);
}
@ -436,11 +435,11 @@ public class Log {
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
long size = 0;
DateFormat DF = SimpleDateFormat.getTimeInstance();
DateFormat TF = Helper.getTimeInstance(context);
for (EntityOperation op : db.operation().getOperations())
size += write(os, String.format("%s %d %s %s %s\r\n",
DF.format(op.created),
TF.format(op.created),
op.message == null ? -1 : op.message,
op.name,
op.args,

@ -51,7 +51,6 @@ import com.sun.mail.imap.IMAPStore;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
@ -720,7 +719,7 @@ public class ServiceSynchronize extends LifecycleService {
Log.i("Reporting sync error after=" + delayed);
Throwable warning = new Throwable(
getString(R.string.title_no_sync,
SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
Helper.getDateTimeInstance(this, DateFormat.SHORT, DateFormat.SHORT)
.format(account.last_connected)), ex);
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("receive:" + account.id, 1,

Loading…
Cancel
Save