Browse Source

Update seen until on notification delete

main
M66B 6 years ago
parent
commit
d263720b56
2 changed files with 45 additions and 25 deletions
  1. +10
    -9
      app/src/main/java/eu/faircode/email/ActivityView.java
  2. +35
    -16
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java

+ 10
- 9
app/src/main/java/eu/faircode/email/ActivityView.java View File

@ -172,7 +172,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
private void syncState() { private void syncState() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean eula = prefs.getBoolean("eula" , false);
boolean eula = prefs.getBoolean("eula", false);
int count = getSupportFragmentManager().getBackStackEntryCount(); int count = getSupportFragmentManager().getBackStackEntryCount();
drawerToggle.setDrawerIndicatorEnabled(count == 1 && eula); drawerToggle.setDrawerIndicatorEnabled(count == 1 && eula);
} }
@ -191,7 +191,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
if (newIntent) { if (newIntent) {
newIntent = false; newIntent = false;
getSupportFragmentManager().popBackStack("unified" , 0);
getSupportFragmentManager().popBackStack("unified", 0);
} }
} }
@ -269,9 +269,9 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
intent.setAction(null); intent.setAction(null);
setIntent(intent); setIntent(intent);
final long now = new Date().getTime();
if ("unseen".equals(action)) {
final long now = new Date().getTime();
if ("unseen".equals(action))
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -283,17 +283,18 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
Log.i(Helper.TAG, "Updated seen until"); Log.i(Helper.TAG, "Updated seen until");
} }
}); });
}
} }
private void init() { private void init() {
invalidateOptionsMenu(); invalidateOptionsMenu();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.getBoolean("eula" , false)) {
if (prefs.getBoolean("eula", false)) {
getSupportFragmentManager().popBackStack(); // eula getSupportFragmentManager().popBackStack(); // eula
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("folder" , -1);
args.putLong("folder", -1);
FragmentMessages fragment = new FragmentMessages(); FragmentMessages fragment = new FragmentMessages();
fragment.setArguments(args); fragment.setArguments(args);
@ -325,10 +326,10 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
} }
private void onMenuFolders(long account) { private void onMenuFolders(long account) {
getSupportFragmentManager().popBackStack("unified" , 0);
getSupportFragmentManager().popBackStack("unified", 0);
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("account" , account);
args.putLong("account", account);
FragmentFolders fragment = new FragmentFolders(); FragmentFolders fragment = new FragmentFolders();
fragment.setArguments(args); fragment.setArguments(args);
@ -412,7 +413,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (ACTION_VIEW_MESSAGES.equals(intent.getAction())) { if (ACTION_VIEW_MESSAGES.equals(intent.getAction())) {
getSupportFragmentManager().popBackStack("unified" , 0);
getSupportFragmentManager().popBackStack("unified", 0);
FragmentMessages fragment = new FragmentMessages(); FragmentMessages fragment = new FragmentMessages();
fragment.setArguments(intent.getExtras()); fragment.setArguments(intent.getExtras());


+ 35
- 16
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -114,9 +114,9 @@ public class ServiceSynchronize extends LifecycleService {
public ServiceSynchronize() { public ServiceSynchronize() {
// https://docs.oracle.com/javaee/6/api/javax/mail/internet/package-summary.html // https://docs.oracle.com/javaee/6/api/javax/mail/internet/package-summary.html
System.setProperty("mail.mime.ignoreunknownencoding" , "true");
System.setProperty("mail.mime.decodefilename" , "true");
System.setProperty("mail.mime.encodefilename" , "true");
System.setProperty("mail.mime.ignoreunknownencoding", "true");
System.setProperty("mail.mime.decodefilename", "true");
System.setProperty("mail.mime.encodefilename", "true");
} }
@Override @Override
@ -178,6 +178,21 @@ public class ServiceSynchronize extends LifecycleService {
Log.i(Helper.TAG, "Service start"); Log.i(Helper.TAG, "Service start");
super.onStartCommand(intent, flags, startId); super.onStartCommand(intent, flags, startId);
if ("unseen".equals(intent.getAction())) {
final long now = new Date().getTime();
executor.submit(new Runnable() {
@Override
public void run() {
DaoAccount dao = DB.getInstance(ServiceSynchronize.this).account();
for (EntityAccount account : dao.getAccounts(true)) {
account.seen_until = now;
dao.updateAccount(account);
}
Log.i(Helper.TAG, "Updated seen until");
}
});
}
return START_STICKY; return START_STICKY;
} }
@ -217,6 +232,10 @@ public class ServiceSynchronize extends LifecycleService {
PendingIntent pi = PendingIntent.getActivity( PendingIntent pi = PendingIntent.getActivity(
this, ActivityView.REQUEST_UNSEEN, intent, PendingIntent.FLAG_UPDATE_CURRENT); this, ActivityView.REQUEST_UNSEEN, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent delete = new Intent(this, ServiceSynchronize.class);
delete.setAction("unseen");
PendingIntent pid = PendingIntent.getService(this, 1, delete, PendingIntent.FLAG_UPDATE_CURRENT);
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// Build notification // Build notification
@ -231,11 +250,11 @@ public class ServiceSynchronize extends LifecycleService {
.setContentTitle(getString(R.string.title_notification_unseen, unseen)) .setContentTitle(getString(R.string.title_notification_unseen, unseen))
.setContentIntent(pi) .setContentIntent(pi)
.setSound(uri) .setSound(uri)
.setOngoing(true)
.setShowWhen(false) .setShowWhen(false)
.setPriority(Notification.PRIORITY_DEFAULT) .setPriority(Notification.PRIORITY_DEFAULT)
.setCategory(Notification.CATEGORY_STATUS) .setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_PUBLIC);
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setDeleteIntent(pid);
return builder; return builder;
} }
@ -284,8 +303,8 @@ public class ServiceSynchronize extends LifecycleService {
IMAPStore istore = null; IMAPStore istore = null;
try { try {
Properties props = MessageHelper.getSessionProperties(); Properties props = MessageHelper.getSessionProperties();
props.put("mail.imaps.peek" , "true");
props.setProperty("mail.mime.address.strict" , "false");
props.put("mail.imaps.peek", "true");
props.setProperty("mail.mime.address.strict", "false");
//props.put("mail.imaps.minidletime", "5000"); //props.put("mail.imaps.minidletime", "5000");
Session isession = Session.getInstance(props, null); Session isession = Session.getInstance(props, null);
// isession.setDebug(true); // isession.setDebug(true);
@ -390,7 +409,7 @@ public class ServiceSynchronize extends LifecycleService {
if (!EntityFolder.TYPE_OUTBOX.equals(folder.type)) if (!EntityFolder.TYPE_OUTBOX.equals(folder.type))
lbm.sendBroadcast(new Intent(ACTION_PROCESS_FOLDER) lbm.sendBroadcast(new Intent(ACTION_PROCESS_FOLDER)
.setType("account/" + account.id) .setType("account/" + account.id)
.putExtra("folder" , folder.id));
.putExtra("folder", folder.id));
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(Helper.TAG, account.name + " " + ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, account.name + " " + ex + "\n" + Log.getStackTraceString(ex));
@ -442,7 +461,7 @@ public class ServiceSynchronize extends LifecycleService {
BroadcastReceiver processReceiver = new BroadcastReceiver() { BroadcastReceiver processReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
final long fid = intent.getLongExtra("folder" , -1);
final long fid = intent.getLongExtra("folder", -1);
IMAPFolder ifolder; IMAPFolder ifolder;
synchronized (mapFolder) { synchronized (mapFolder) {
@ -796,7 +815,7 @@ public class ServiceSynchronize extends LifecycleService {
Address[] to = imessage.getAllRecipients(); Address[] to = imessage.getAllRecipients();
itransport.sendMessage(imessage, to); itransport.sendMessage(imessage, to);
Log.i(Helper.TAG, "Sent via " + ident.host + "/" + ident.user + Log.i(Helper.TAG, "Sent via " + ident.host + "/" + ident.user +
" to " + TextUtils.join(", " , to));
" to " + TextUtils.join(", ", to));
msg.sent = new Date().getTime(); msg.sent = new Date().getTime();
msg.seen = true; msg.seen = true;
@ -917,7 +936,7 @@ public class ServiceSynchronize extends LifecycleService {
} }
} }
if (candidate) { if (candidate) {
Log.i(Helper.TAG, ifolder.getFullName() + " candidate attr=" + TextUtils.join("," , attrs));
Log.i(Helper.TAG, ifolder.getFullName() + " candidate attr=" + TextUtils.join(",", attrs));
EntityFolder folder = dao.getFolderByName(account.id, ifolder.getFullName()); EntityFolder folder = dao.getFolderByName(account.id, ifolder.getFullName());
if (folder == null) { if (folder == null) {
folder = new EntityFolder(); folder = new EntityFolder();
@ -1066,7 +1085,7 @@ public class ServiceSynchronize extends LifecycleService {
message.folder = folder.id; message.folder = folder.id;
message.uid = uid; message.uid = uid;
message.msgid = helper.getMessageID(); message.msgid = helper.getMessageID();
message.references = TextUtils.join(" " , helper.getReferences());
message.references = TextUtils.join(" ", helper.getReferences());
message.inreplyto = helper.getInReplyTo(); message.inreplyto = helper.getInReplyTo();
message.thread = helper.getThreadId(uid); message.thread = helper.getThreadId(uid);
message.from = helper.getFrom(); message.from = helper.getFrom();
@ -1119,7 +1138,7 @@ public class ServiceSynchronize extends LifecycleService {
ifolder.doCommand(new IMAPFolder.ProtocolCommand() { ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
public Object doCommand(IMAPProtocol p) throws ProtocolException { public Object doCommand(IMAPProtocol p) throws ProtocolException {
Log.i(Helper.TAG, ifolder.getName() + " start NOOP"); Log.i(Helper.TAG, ifolder.getName() + " start NOOP");
p.simpleCommand("NOOP" , null);
p.simpleCommand("NOOP", null);
Log.i(Helper.TAG, ifolder.getName() + " end NOOP"); Log.i(Helper.TAG, ifolder.getName() + " end NOOP");
return null; return null;
} }
@ -1232,20 +1251,20 @@ public class ServiceSynchronize extends LifecycleService {
NotificationManager nm = context.getSystemService(NotificationManager.class); NotificationManager nm = context.getSystemService(NotificationManager.class);
NotificationChannel service = new NotificationChannel( NotificationChannel service = new NotificationChannel(
"service" ,
"service",
context.getString(R.string.channel_service), context.getString(R.string.channel_service),
NotificationManager.IMPORTANCE_MIN); NotificationManager.IMPORTANCE_MIN);
service.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT); service.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
nm.createNotificationChannel(service); nm.createNotificationChannel(service);
NotificationChannel notification = new NotificationChannel( NotificationChannel notification = new NotificationChannel(
"notification" ,
"notification",
context.getString(R.string.channel_notification), context.getString(R.string.channel_notification),
NotificationManager.IMPORTANCE_DEFAULT); NotificationManager.IMPORTANCE_DEFAULT);
nm.createNotificationChannel(notification); nm.createNotificationChannel(notification);
NotificationChannel error = new NotificationChannel( NotificationChannel error = new NotificationChannel(
"error" ,
"error",
context.getString(R.string.channel_error), context.getString(R.string.channel_error),
NotificationManager.IMPORTANCE_HIGH); NotificationManager.IMPORTANCE_HIGH);
nm.createNotificationChannel(error); nm.createNotificationChannel(error);


Loading…
Cancel
Save