mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Show actual auto-delete timer duration in UI
(only days and hours for now)
This commit is contained in:
@@ -18,6 +18,7 @@ import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static org.briarproject.bramble.util.StringUtils.trim;
|
||||
import static org.briarproject.briar.android.util.UiUtils.formatDate;
|
||||
import static org.briarproject.briar.android.util.UiUtils.formatDuration;
|
||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||
|
||||
@UiThread
|
||||
@@ -82,19 +83,23 @@ abstract class ConversationItemViewHolder extends ViewHolder {
|
||||
Context ctx = itemView.getContext();
|
||||
topNotice.setVisibility(VISIBLE);
|
||||
boolean enabled = item.getAutoDeleteTimer() != NO_AUTO_DELETE_TIMER;
|
||||
String duration = enabled ?
|
||||
formatDuration(ctx, item.getAutoDeleteTimer()) : "";
|
||||
String tapToLearnMore = ctx.getString(R.string.tap_to_learn_more);
|
||||
String text;
|
||||
if (item.isIncoming()) {
|
||||
String name = item.getContactName().getValue();
|
||||
int strRes = enabled ?
|
||||
R.string.auto_delete_msg_contact_enabled :
|
||||
R.string.auto_delete_msg_contact_disabled;
|
||||
text = ctx.getString(strRes, name, tapToLearnMore);
|
||||
text = enabled ?
|
||||
ctx.getString(R.string.auto_delete_msg_contact_enabled,
|
||||
name, duration, tapToLearnMore) :
|
||||
ctx.getString(R.string.auto_delete_msg_contact_disabled,
|
||||
name, tapToLearnMore);
|
||||
} else {
|
||||
int strRes = enabled ?
|
||||
R.string.auto_delete_msg_you_enabled :
|
||||
R.string.auto_delete_msg_you_disabled;
|
||||
text = ctx.getString(strRes, tapToLearnMore);
|
||||
text = enabled ?
|
||||
ctx.getString(R.string.auto_delete_msg_you_enabled,
|
||||
duration, tapToLearnMore) :
|
||||
ctx.getString(R.string.auto_delete_msg_you_disabled,
|
||||
tapToLearnMore);
|
||||
}
|
||||
topNotice.setText(text);
|
||||
topNotice.setOnClickListener(
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.PowerManager;
|
||||
@@ -75,6 +76,7 @@ import static android.text.format.DateUtils.FORMAT_ABBREV_TIME;
|
||||
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
|
||||
import static android.text.format.DateUtils.FORMAT_SHOW_TIME;
|
||||
import static android.text.format.DateUtils.FORMAT_SHOW_YEAR;
|
||||
import static android.text.format.DateUtils.HOUR_IN_MILLIS;
|
||||
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
|
||||
import static android.text.format.DateUtils.WEEK_IN_MILLIS;
|
||||
import static android.text.format.DateUtils.YEAR_IN_MILLIS;
|
||||
@@ -166,6 +168,28 @@ public class UiUtils {
|
||||
return DateUtils.formatDateTime(ctx, time, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given duration in a human-friendly format. For example,
|
||||
* "7 days" or "1 hour". Returns only the largest meaningful unit of time,
|
||||
* from days up to hours.
|
||||
*/
|
||||
public static String formatDuration(Context ctx, long millis) {
|
||||
Resources r = ctx.getResources();
|
||||
if (millis >= DAY_IN_MILLIS) {
|
||||
int days = (int) (millis / DAY_IN_MILLIS);
|
||||
int rest = (int) (millis % DAY_IN_MILLIS);
|
||||
String dayStr =
|
||||
r.getQuantityString(R.plurals.duration_days, days, days);
|
||||
if (rest < HOUR_IN_MILLIS / 2) return dayStr;
|
||||
else return dayStr + " " + formatDuration(ctx, rest);
|
||||
} else {
|
||||
int hours = (int) ((millis + HOUR_IN_MILLIS / 2) / HOUR_IN_MILLIS);
|
||||
// anything less than one hour is shown as one hour
|
||||
if (hours < 1) hours = 1;
|
||||
return r.getQuantityString(R.plurals.duration_hours, hours, hours);
|
||||
}
|
||||
}
|
||||
|
||||
public static long getDaysUntilExpiry() {
|
||||
long now = System.currentTimeMillis();
|
||||
return (EXPIRY_DATE - now) / DAYS.toMillis(1);
|
||||
|
||||
Reference in New Issue
Block a user