Made notification actions pro instead of notification previews

This commit is contained in:
M66B 2019-05-06 13:59:26 +02:00
parent 1a0dac6e70
commit bf36d6789e
6 changed files with 84 additions and 68 deletions

View File

@ -37,8 +37,8 @@ This app starts a foreground service with a low priority status bar notification
* Account/identity colors
* 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)
* Configurable notification actions
* Snooze messages ([instructions](https://github.com/M66B/open-source-email/blob/master/FAQ.md#user-content-faq67))
* Send messages after selected time
* Synchronization scheduling ([instructions](https://github.com/M66B/open-source-email/blob/master/FAQ.md#user-content-faq78))

View File

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

View File

@ -34,10 +34,10 @@ import android.net.Uri;
import android.os.Build;
import android.os.DeadSystemException;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.webkit.CookieManager;
import androidx.annotation.RequiresApi;
import androidx.preference.PreferenceManager;
import org.json.JSONArray;
import org.json.JSONException;
@ -90,6 +90,7 @@ public class ApplicationEx extends Application {
}
});
upgrade(this);
createNotificationChannels();
if (Helper.hasWebView(this))
CookieManager.getInstance().setAcceptCookie(false);
@ -118,6 +119,25 @@ public class ApplicationEx extends Application {
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) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean english = prefs.getBoolean("english", false);

View File

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

View File

@ -36,6 +36,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import androidx.constraintlayout.widget.Group;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
import static android.app.Activity.RESULT_OK;
@ -88,35 +89,35 @@ public class FragmentOptionsNotifications extends FragmentBase {
cbNotifyActionTrash.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_trash", checked).apply();
setAction(buttonView, "notify_trash", checked);
}
});
cbNotifyActionArchive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_archive", checked).apply();
setAction(buttonView, "notify_archive", checked);
}
});
cbNotifyActionReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_reply", checked).apply();
setAction(buttonView, "notify_reply", checked);
}
});
cbNotifyActionFlag.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("notify_flag", checked).apply();
setAction(buttonView, "notify_flag", checked);
}
});
cbNotifyActionSeen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
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;
}
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() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
swNotifyPreview.setChecked(prefs.getBoolean("notify_preview", true));
swNotifyPreview.setEnabled(Helper.isPro(getContext()));
cbNotifyActionTrash.setChecked(prefs.getBoolean("notify_trash", true));
cbNotifyActionArchive.setChecked(prefs.getBoolean("notify_archive", true));
cbNotifyActionReply.setChecked(prefs.getBoolean("notify_reply", false));

View File

@ -39,18 +39,6 @@
app:layout_constraintStart_toStartOf="parent"
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
android:id="@+id/tvNotifyActions"
android:layout_width="0dp"
@ -62,7 +50,7 @@
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewPro" />
app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewHint" />
<CheckBox
android:id="@+id/cbNotifyActionTrash"