Made notification actions pro instead of notification previews

pull/156/head
M66B 5 years ago
parent 1a0dac6e70
commit bf36d6789e

@ -37,8 +37,8 @@ This app starts a foreground service with a low priority status bar notification
* Account/identity colors * Account/identity colors
* Notifications per account (requires Android 8 Oreo or later) * Notifications per account (requires Android 8 Oreo or later)
* Notifications with message details (requires Android 7 Nougat or later)
* Notification sound per sender (requires Android 8 Oreo or later) * Notification sound per sender (requires Android 8 Oreo or later)
* Configurable notification actions
* Snooze messages ([instructions](https://github.com/M66B/open-source-email/blob/master/FAQ.md#user-content-faq67)) * Snooze messages ([instructions](https://github.com/M66B/open-source-email/blob/master/FAQ.md#user-content-faq67))
* Send messages after selected time * Send messages after selected time
* Synchronization scheduling ([instructions](https://github.com/M66B/open-source-email/blob/master/FAQ.md#user-content-faq78)) * Synchronization scheduling ([instructions](https://github.com/M66B/open-source-email/blob/master/FAQ.md#user-content-faq78))

@ -857,6 +857,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
} }
} }
editor.apply(); editor.apply();
ApplicationEx.upgrade(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
if (jimport.has("channels")) { if (jimport.has("channels")) {

@ -34,10 +34,10 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.DeadSystemException; import android.os.DeadSystemException;
import android.os.RemoteException; import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.preference.PreferenceManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -90,6 +90,7 @@ public class ApplicationEx extends Application {
} }
}); });
upgrade(this);
createNotificationChannels(); createNotificationChannels();
if (Helper.hasWebView(this)) if (Helper.hasWebView(this))
CookieManager.getInstance().setAcceptCookie(false); CookieManager.getInstance().setAcceptCookie(false);
@ -118,6 +119,25 @@ public class ApplicationEx extends Application {
Log.i(message + " " + mb + " MB" + " " + perc + " %"); Log.i(message + " " + mb + " MB" + " " + perc + " %");
} }
static void upgrade(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int version = prefs.getInt("version", 468);
if (version < BuildConfig.VERSION_CODE) {
Log.i("Upgrading from " + version + " to " + BuildConfig.VERSION_CODE);
SharedPreferences.Editor editor = prefs.edit();
editor.remove("notify_trash");
editor.remove("notify_archive");
editor.remove("notify_reply");
editor.remove("notify_flag");
editor.remove("notify_seen");
editor.putInt("version", BuildConfig.VERSION_CODE);
editor.apply();
}
}
static Context getLocalizedContext(Context context) { static Context getLocalizedContext(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean english = prefs.getBoolean("english", false); boolean english = prefs.getBoolean("english", false);

@ -1763,22 +1763,20 @@ class Core {
} else } else
builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN); builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
if (pro) { DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT); StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(); for (EntityMessage message : messages) {
for (EntityMessage message : messages) { sb.append("<strong>").append(messageContact.get(message).getDisplayName(true)).append("</strong>");
sb.append("<strong>").append(messageContact.get(message).getDisplayName(true)).append("</strong>"); if (!TextUtils.isEmpty(message.subject))
if (!TextUtils.isEmpty(message.subject)) sb.append(": ").append(message.subject);
sb.append(": ").append(message.subject); sb.append(" ").append(df.format(message.received));
sb.append(" ").append(df.format(message.received)); sb.append("<br>");
sb.append("<br>");
}
builder.setStyle(new NotificationCompat.BigTextStyle()
.bigText(HtmlHelper.fromHtml(sb.toString()))
.setSummaryText(title));
} }
builder.setStyle(new NotificationCompat.BigTextStyle()
.bigText(HtmlHelper.fromHtml(sb.toString()))
.setSummaryText(title));
notifications.add(builder.build()); notifications.add(builder.build());
boolean preview = prefs.getBoolean("notify_preview", true); boolean preview = prefs.getBoolean("notify_preview", true);
@ -1886,42 +1884,40 @@ class Core {
mbuilder.addAction(actionSeen.build()); mbuilder.addAction(actionSeen.build());
} }
if (pro) { if (!TextUtils.isEmpty(message.subject))
if (!TextUtils.isEmpty(message.subject)) mbuilder.setContentText(message.subject);
mbuilder.setContentText(message.subject);
if (message.content && preview) if (message.content && preview)
try { try {
String body = Helper.readText(message.getFile(context)); String body = Helper.readText(message.getFile(context));
StringBuilder sb = new StringBuilder(); StringBuilder sbm = new StringBuilder();
if (!TextUtils.isEmpty(message.subject)) if (!TextUtils.isEmpty(message.subject))
sb.append(message.subject).append("<br>"); sbm.append(message.subject).append("<br>");
String text = Jsoup.parse(body).text(); String text = Jsoup.parse(body).text();
if (!TextUtils.isEmpty(text)) { if (!TextUtils.isEmpty(text)) {
sb.append("<em>"); sbm.append("<em>");
if (text.length() > HtmlHelper.PREVIEW_SIZE) { if (text.length() > HtmlHelper.PREVIEW_SIZE) {
sb.append(text.substring(0, HtmlHelper.PREVIEW_SIZE)); sbm.append(text.substring(0, HtmlHelper.PREVIEW_SIZE));
sb.append("…"); sbm.append("…");
} else } else
sb.append(text); sbm.append(text);
sb.append("</em>"); sbm.append("</em>");
}
mbuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(HtmlHelper.fromHtml(sb.toString())));
} catch (IOException ex) {
Log.e(ex);
mbuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(ex.toString()));
} }
mbuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(HtmlHelper.fromHtml(sbm.toString())));
} catch (IOException ex) {
Log.e(ex);
mbuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(ex.toString()));
}
if (info.hasPhoto()) if (info.hasPhoto())
mbuilder.setLargeIcon(info.getPhotoBitmap()); mbuilder.setLargeIcon(info.getPhotoBitmap());
if (info.hasLookupUri()) if (info.hasLookupUri())
mbuilder.addPerson(info.getLookupUri().toString()); mbuilder.addPerson(info.getLookupUri().toString());
if (message.accountColor != null) { if (pro && message.accountColor != null) {
mbuilder.setColor(message.accountColor); mbuilder.setColor(message.accountColor);
mbuilder.setColorized(true); mbuilder.setColorized(true);
}
} }
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)

@ -36,6 +36,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat; import androidx.appcompat.widget.SwitchCompat;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
@ -88,35 +89,35 @@ public class FragmentOptionsNotifications extends FragmentBase {
cbNotifyActionTrash.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbNotifyActionTrash.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) { public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_trash", checked).apply(); setAction(buttonView, "notify_trash", checked);
} }
}); });
cbNotifyActionArchive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbNotifyActionArchive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) { public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_archive", checked).apply(); setAction(buttonView, "notify_archive", checked);
} }
}); });
cbNotifyActionReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbNotifyActionReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) { public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_reply", checked).apply(); setAction(buttonView, "notify_reply", checked);
} }
}); });
cbNotifyActionFlag.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbNotifyActionFlag.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) { public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_flag", checked).apply(); setAction(buttonView, "notify_flag", checked);
} }
}); });
cbNotifyActionSeen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbNotifyActionSeen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) { public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_seen", checked).apply(); setAction(buttonView, "notify_seen", checked);
} }
}); });
@ -144,11 +145,21 @@ public class FragmentOptionsNotifications extends FragmentBase {
return view; return view;
} }
private void setAction(CompoundButton cb, String key, boolean checked) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (Helper.isPro(getContext()))
prefs.edit().putBoolean(key, checked).apply();
else {
cb.setChecked(!checked);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_PRO));
}
}
private void setOptions() { private void setOptions() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
swNotifyPreview.setChecked(prefs.getBoolean("notify_preview", true)); swNotifyPreview.setChecked(prefs.getBoolean("notify_preview", true));
swNotifyPreview.setEnabled(Helper.isPro(getContext()));
cbNotifyActionTrash.setChecked(prefs.getBoolean("notify_trash", true)); cbNotifyActionTrash.setChecked(prefs.getBoolean("notify_trash", true));
cbNotifyActionArchive.setChecked(prefs.getBoolean("notify_archive", true)); cbNotifyActionArchive.setChecked(prefs.getBoolean("notify_archive", true));
cbNotifyActionReply.setChecked(prefs.getBoolean("notify_reply", false)); cbNotifyActionReply.setChecked(prefs.getBoolean("notify_reply", false));

@ -39,18 +39,6 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNotifyPreview" /> app:layout_constraintTop_toBottomOf="@id/swNotifyPreview" />
<TextView
android:id="@+id/tvNotifyPreviewPro"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:text="@string/title_pro_feature"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewHint" />
<TextView <TextView
android:id="@+id/tvNotifyActions" android:id="@+id/tvNotifyActions"
android:layout_width="0dp" android:layout_width="0dp"
@ -62,7 +50,7 @@
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewPro" /> app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewHint" />
<CheckBox <CheckBox
android:id="@+id/cbNotifyActionTrash" android:id="@+id/cbNotifyActionTrash"

Loading…
Cancel
Save