mirror of https://github.com/M66B/FairEmail.git
Use update notification instead of dialog
This commit is contained in:
parent
d33d4dfe83
commit
8b2e83aca8
|
@ -19,6 +19,8 @@ package eu.faircode.email;
|
|||
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -49,6 +51,7 @@ import android.widget.Toast;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
@ -108,6 +111,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
static final int REQUEST_THREAD = 3;
|
||||
static final int REQUEST_OUTBOX = 4;
|
||||
static final int REQUEST_ERROR = 5;
|
||||
static final int REQUEST_UPDATE = 6;
|
||||
|
||||
static final int REQUEST_SENDER = 1;
|
||||
static final int REQUEST_RECIPIENT = 2;
|
||||
|
@ -732,17 +736,25 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
return;
|
||||
}
|
||||
|
||||
final Intent update = new Intent(Intent.ACTION_VIEW, Uri.parse(info.html_url));
|
||||
if (update.resolveActivity(getPackageManager()) != null)
|
||||
new DialogBuilderLifecycle(ActivityView.this, ActivityView.this)
|
||||
.setMessage(getString(R.string.title_updated, info.tag_name))
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Helper.view(ActivityView.this, ActivityView.this, update);
|
||||
}
|
||||
})
|
||||
.show();
|
||||
NotificationCompat.Builder builder =
|
||||
new NotificationCompat.Builder(ActivityView.this, "notification")
|
||||
.setSmallIcon(R.drawable.baseline_system_update_24)
|
||||
.setContentTitle(getString(R.string.title_updated, info.tag_name))
|
||||
.setAutoCancel(true)
|
||||
.setShowWhen(false)
|
||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
.setCategory(NotificationCompat.CATEGORY_REMINDER)
|
||||
.setVisibility(NotificationCompat.VISIBILITY_SECRET);
|
||||
|
||||
Intent update = new Intent(Intent.ACTION_VIEW, Uri.parse(info.html_url));
|
||||
if (update.resolveActivity(getPackageManager()) != null) {
|
||||
PendingIntent piUpdate = PendingIntent.getActivity(
|
||||
ActivityView.this, REQUEST_UPDATE, update, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
builder.setContentIntent(piUpdate);
|
||||
}
|
||||
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify(Helper.NOTIFICATION_UPDATE, builder.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,6 +20,7 @@ package eu.faircode.email;
|
|||
*/
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -177,6 +178,10 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("updates", checked).apply();
|
||||
if (!checked) {
|
||||
NotificationManager nm = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.cancel(Helper.NOTIFICATION_UPDATE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -95,6 +95,7 @@ public class Helper {
|
|||
static final int NOTIFICATION_SYNCHRONIZE = 1;
|
||||
static final int NOTIFICATION_SEND = 2;
|
||||
static final int NOTIFICATION_EXTERNAL = 3;
|
||||
static final int NOTIFICATION_UPDATE = 4;
|
||||
|
||||
static final float LOW_LIGHT = 0.6f;
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M17,1.01L7,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2L19,3c0,-1.1 -0.9,-1.99 -2,-1.99zM17,19L7,19L7,5h10v14zM16,13h-3L13,8h-2v5L8,13l4,4 4,-4z"/>
|
||||
</vector>
|
Loading…
Reference in New Issue