Added option for wearable preview

This commit is contained in:
M66B
2019-10-21 10:34:16 +02:00
parent 21d89029ee
commit 726fce894d
4 changed files with 59 additions and 26 deletions

View File

@@ -2611,6 +2611,7 @@ class Core {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean notify_summary = prefs.getBoolean("notify_summary", false);
boolean wearable_preview = prefs.getBoolean("wearable_preview", false);
boolean biometrics = prefs.getBoolean("biometrics", false);
boolean biometric_notify = prefs.getBoolean("biometrics_notify", false);
boolean pro = ActivityBilling.isPro(context);
@@ -2725,8 +2726,9 @@ class Core {
for (NotificationCompat.Builder builder : notifications) {
long id = builder.getExtras().getLong("id", 0);
if ((id == 0 && add.size() + remove.size() > 0) || add.contains(id)) {
if (update.contains(id))
if (wearable_preview ? id < 0 : update.contains(id))
builder.setLocalOnly(true);
String tag = "unseen." + group + "." + Math.abs(id);
Notification notification = builder.build();
Log.i("Notifying tag=" + tag + " id=" + id +
@@ -3071,33 +3073,27 @@ class Core {
mbuilder.extend(new NotificationCompat.WearableExtender()
.addActions(wactions));
if (message.content && notify_preview)
try {
StringBuilder sbm = new StringBuilder();
if (!TextUtils.isEmpty(message.subject))
sbm.append(message.subject).append("<br>");
if (message.content && notify_preview) {
// Wearables
mbuilder.setContentText(
(message.subject == null ? "" : message.subject) + " - " +
(message.preview == null ? "" : message.preview));
String body = Helper.readText(message.getFile(context));
String preview = HtmlHelper.getPreview(body);
if (!TextUtils.isEmpty(preview))
sbm.append("<em>").append(preview).append("</em>");
// Device
StringBuilder sbm = new StringBuilder();
if (!TextUtils.isEmpty(message.subject))
sbm.append(message.subject).append("<br>");
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle()
.bigText(HtmlHelper.fromHtml(sbm.toString()));
if (!TextUtils.isEmpty(message.preview))
sbm.append("<em>").append(message.preview).append("</em>");
if (!TextUtils.isEmpty(message.subject)) {
bigText.setSummaryText(message.subject);
mbuilder.setContentText(message.subject); // Wearable
}
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle()
.bigText(HtmlHelper.fromHtml(sbm.toString()));
if (!TextUtils.isEmpty(message.subject))
bigText.setSummaryText(message.subject);
mbuilder.setStyle(bigText);
} catch (IOException ex) {
Log.e(ex);
mbuilder.setStyle(new NotificationCompat.BigTextStyle()
.bigText(ex.toString())
.setSummaryText(Helper.formatThrowable(ex)));
}
else {
mbuilder.setStyle(bigText);
} else {
if (!TextUtils.isEmpty(message.subject))
mbuilder.setContentText(message.subject);
}

View File

@@ -56,6 +56,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private SwitchCompat swNotifySummary;
private SwitchCompat swNotifyRemove;
private SwitchCompat swNotifyPreview;
private SwitchCompat swWearablePreview;
private CheckBox cbNotifyActionTrash;
private CheckBox cbNotifyActionJunk;
private CheckBox cbNotifyActionArchive;
@@ -79,7 +80,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private final static String[] RESET_OPTIONS = new String[]{
"badge", "unseen_ignored",
"notify_summary", "notify_remove", "notify_preview",
"notify_summary", "notify_remove", "notify_preview", "wearable_preview",
"notify_trash", "notify_junk", "notify_archive", "notify_reply", "notify_reply_direct",
"notify_flag", "notify_seen", "notify_snooze",
"biometrics_notify",
@@ -101,6 +102,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
swNotifySummary = view.findViewById(R.id.swNotifySummary);
swNotifyRemove = view.findViewById(R.id.swNotifyRemove);
swNotifyPreview = view.findViewById(R.id.swNotifyPreview);
swWearablePreview = view.findViewById(R.id.swWearablePreview);
cbNotifyActionTrash = view.findViewById(R.id.cbNotifyActionTrash);
cbNotifyActionJunk = view.findViewById(R.id.cbNotifyActionJunk);
cbNotifyActionArchive = view.findViewById(R.id.cbNotifyActionArchive);
@@ -164,6 +166,14 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("notify_preview", checked).apply();
swWearablePreview.setEnabled(checked);
}
});
swWearablePreview.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("wearable_preview", checked).apply();
}
});
@@ -343,6 +353,8 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
swUnseenIgnored.setChecked(prefs.getBoolean("unseen_ignored", false));
swNotifySummary.setChecked(prefs.getBoolean("notify_summary", false));
swNotifyPreview.setChecked(prefs.getBoolean("notify_preview", true));
swWearablePreview.setChecked(prefs.getBoolean("wearable_preview", false));
swWearablePreview.setEnabled(swNotifyPreview.isChecked());
cbNotifyActionTrash.setChecked(prefs.getBoolean("notify_trash", true) || !pro);
cbNotifyActionJunk.setChecked(prefs.getBoolean("notify_junk", false) && pro);