Android Q compatibility

This commit is contained in:
M66B 2019-03-14 14:57:24 +00:00
parent 8263742f6c
commit 38fcadab9b
4 changed files with 31 additions and 51 deletions

View File

@ -117,7 +117,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
private static NumberFormat nf = NumberFormat.getNumberInstance(); private static NumberFormat nf = NumberFormat.getNumberInstance();
static final int REQUEST_UNIFIED = 1; static final int REQUEST_UNIFIED = 1;
static final int REQUEST_THREAD = 2; static final int REQUEST_WHY = 2;
static final int REQUEST_THREAD = 3;
static final int REQUEST_RAW = 1; static final int REQUEST_RAW = 1;
static final int REQUEST_ATTACHMENT = 2; static final int REQUEST_ATTACHMENT = 2;
@ -430,7 +431,22 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
if ("unified".equals(action)) if ("unified".equals(action))
init(); init();
else if ("error".equals(action)) else if ("why".equals(action)) {
init();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityView.this);
boolean why = prefs.getBoolean("why", false);
if (!why) {
prefs.edit().putBoolean("why", true).apply();
Intent iwhy = new Intent(Intent.ACTION_VIEW);
iwhy.setData(Uri.parse(Helper.FAQ_URI + "#user-content-faq2"));
iwhy.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (iwhy.resolveActivity(getPackageManager()) != null)
startActivity(iwhy);
}
} else if ("error".equals(action))
onDebugInfo(); onDebugInfo();
else if (action.startsWith("thread")) { else if (action.startsWith("thread")) {

View File

@ -1519,9 +1519,9 @@ class Core {
messageContact.put(message, ContactInfo.get(context, message.from, false)); messageContact.put(message, ContactInfo.get(context, message.from, false));
// Build pending intents // Build pending intents
Intent summary = new Intent(context, ServiceUI.class); Intent summary = new Intent(context, ActivityView.class);
summary.setAction("summary"); summary.setAction("unified");
PendingIntent piSummary = PendingIntent.getService(context, ServiceUI.PI_SUMMARY, summary, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piSummary = PendingIntent.getActivity(context, ActivityView.REQUEST_UNIFIED, summary, PendingIntent.FLAG_UPDATE_CURRENT);
Intent clear = new Intent(context, ServiceUI.class); Intent clear = new Intent(context, ServiceUI.class);
clear.setAction("clear"); clear.setAction("clear");

View File

@ -211,9 +211,9 @@ public class ServiceSynchronize extends LifecycleService {
lastStats = stats; lastStats = stats;
// Build pending intent // Build pending intent
Intent intent = new Intent(this, ServiceUI.class); Intent why = new Intent(this, ActivityView.class);
intent.setAction("why"); why.setAction("why");
PendingIntent pi = PendingIntent.getService(this, ServiceUI.PI_WHY, intent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piWhy = PendingIntent.getActivity(this, ActivityView.REQUEST_WHY, why, PendingIntent.FLAG_UPDATE_CURRENT);
// Build notification // Build notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "service"); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "service");
@ -222,7 +222,7 @@ public class ServiceSynchronize extends LifecycleService {
.setSmallIcon(R.drawable.baseline_compare_arrows_white_24) .setSmallIcon(R.drawable.baseline_compare_arrows_white_24)
.setContentTitle(getResources().getQuantityString( .setContentTitle(getResources().getQuantityString(
R.plurals.title_notification_synchronizing, lastStats.accounts, lastStats.accounts)) R.plurals.title_notification_synchronizing, lastStats.accounts, lastStats.accounts))
.setContentIntent(pi) .setContentIntent(piWhy)
.setAutoCancel(false) .setAutoCancel(false)
.setShowWhen(false) .setShowWhen(false)
.setPriority(NotificationCompat.PRIORITY_MIN) .setPriority(NotificationCompat.PRIORITY_MIN)

View File

@ -2,22 +2,16 @@ package eu.faircode.email;
import android.app.IntentService; import android.app.IntentService;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.preference.PreferenceManager;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
public class ServiceUI extends IntentService { public class ServiceUI extends IntentService {
static final int PI_WHY = 1; static final int PI_CLEAR = 1;
static final int PI_SUMMARY = 2; static final int PI_SEEN = 2;
static final int PI_CLEAR = 3; static final int PI_ARCHIVE = 3;
static final int PI_SEEN = 4; static final int PI_TRASH = 4;
static final int PI_ARCHIVE = 5; static final int PI_IGNORED = 5;
static final int PI_TRASH = 6; static final int PI_SNOOZED = 6;
static final int PI_IGNORED = 7;
static final int PI_SNOOZED = 8;
public ServiceUI() { public ServiceUI() {
this(ServiceUI.class.getName()); this(ServiceUI.class.getName());
@ -57,12 +51,6 @@ public class ServiceUI extends IntentService {
long id = (parts.length > 1 ? Long.parseLong(parts[1]) : -1); long id = (parts.length > 1 ? Long.parseLong(parts[1]) : -1);
switch (parts[0]) { switch (parts[0]) {
case "why":
onWhy();
break;
case "summary":
onSummary();
break;
case "clear": case "clear":
onClear(); onClear();
break; break;
@ -90,30 +78,6 @@ public class ServiceUI extends IntentService {
} }
} }
private void onWhy() {
Intent why = new Intent(Intent.ACTION_VIEW);
why.setData(Uri.parse(Helper.FAQ_URI + "#user-content-faq2"));
why.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PackageManager pm = getPackageManager();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.getBoolean("why", false) || why.resolveActivity(pm) == null) {
Intent view = new Intent(this, ActivityView.class);
view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(view);
} else {
prefs.edit().putBoolean("why", true).apply();
startActivity(why);
}
}
private void onSummary() {
Intent view = new Intent(this, ActivityView.class);
view.setAction("unified");
view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(view);
}
private void onClear() { private void onClear() {
DB.getInstance(this).message().ignoreAll(); DB.getInstance(this).message().ignoreAll();
} }