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() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean eula = prefs.getBoolean("eula" , false);
boolean eula = prefs.getBoolean("eula", false);
int count = getSupportFragmentManager().getBackStackEntryCount();
drawerToggle.setDrawerIndicatorEnabled(count == 1 && eula);
}
@ -191,7 +191,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
if (newIntent) {
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);
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() {
@Override
public void run() {
@ -283,17 +283,18 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
Log.i(Helper.TAG, "Updated seen until");
}
});
}
}
private void init() {
invalidateOptionsMenu();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.getBoolean("eula" , false)) {
if (prefs.getBoolean("eula", false)) {
getSupportFragmentManager().popBackStack(); // eula
Bundle args = new Bundle();
args.putLong("folder" , -1);
args.putLong("folder", -1);
FragmentMessages fragment = new FragmentMessages();
fragment.setArguments(args);
@ -325,10 +326,10 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
}
private void onMenuFolders(long account) {
getSupportFragmentManager().popBackStack("unified" , 0);
getSupportFragmentManager().popBackStack("unified", 0);
Bundle args = new Bundle();
args.putLong("account" , account);
args.putLong("account", account);
FragmentFolders fragment = new FragmentFolders();
fragment.setArguments(args);
@ -412,7 +413,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
@Override
public void onReceive(Context context, Intent intent) {
if (ACTION_VIEW_MESSAGES.equals(intent.getAction())) {
getSupportFragmentManager().popBackStack("unified" , 0);
getSupportFragmentManager().popBackStack("unified", 0);
FragmentMessages fragment = new FragmentMessages();
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() {
// 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
@ -178,6 +178,21 @@ public class ServiceSynchronize extends LifecycleService {
Log.i(Helper.TAG, "Service start");
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;
}
@ -217,6 +232,10 @@ public class ServiceSynchronize extends LifecycleService {
PendingIntent pi = PendingIntent.getActivity(
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);
// Build notification
@ -231,11 +250,11 @@ public class ServiceSynchronize extends LifecycleService {
.setContentTitle(getString(R.string.title_notification_unseen, unseen))
.setContentIntent(pi)
.setSound(uri)
.setOngoing(true)
.setShowWhen(false)
.setPriority(Notification.PRIORITY_DEFAULT)
.setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_PUBLIC);
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setDeleteIntent(pid);
return builder;
}
@ -284,8 +303,8 @@ public class ServiceSynchronize extends LifecycleService {
IMAPStore istore = null;
try {
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");
Session isession = Session.getInstance(props, null);
// isession.setDebug(true);
@ -390,7 +409,7 @@ public class ServiceSynchronize extends LifecycleService {
if (!EntityFolder.TYPE_OUTBOX.equals(folder.type))
lbm.sendBroadcast(new Intent(ACTION_PROCESS_FOLDER)
.setType("account/" + account.id)
.putExtra("folder" , folder.id));
.putExtra("folder", folder.id));
} catch (Throwable 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() {
@Override
public void onReceive(Context context, Intent intent) {
final long fid = intent.getLongExtra("folder" , -1);
final long fid = intent.getLongExtra("folder", -1);
IMAPFolder ifolder;
synchronized (mapFolder) {
@ -796,7 +815,7 @@ public class ServiceSynchronize extends LifecycleService {
Address[] to = imessage.getAllRecipients();
itransport.sendMessage(imessage, to);
Log.i(Helper.TAG, "Sent via " + ident.host + "/" + ident.user +
" to " + TextUtils.join(", " , to));
" to " + TextUtils.join(", ", to));
msg.sent = new Date().getTime();
msg.seen = true;
@ -917,7 +936,7 @@ public class ServiceSynchronize extends LifecycleService {
}
}
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());
if (folder == null) {
folder = new EntityFolder();
@ -1066,7 +1085,7 @@ public class ServiceSynchronize extends LifecycleService {
message.folder = folder.id;
message.uid = uid;
message.msgid = helper.getMessageID();
message.references = TextUtils.join(" " , helper.getReferences());
message.references = TextUtils.join(" ", helper.getReferences());
message.inreplyto = helper.getInReplyTo();
message.thread = helper.getThreadId(uid);
message.from = helper.getFrom();
@ -1119,7 +1138,7 @@ public class ServiceSynchronize extends LifecycleService {
ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
public Object doCommand(IMAPProtocol p) throws ProtocolException {
Log.i(Helper.TAG, ifolder.getName() + " start NOOP");
p.simpleCommand("NOOP" , null);
p.simpleCommand("NOOP", null);
Log.i(Helper.TAG, ifolder.getName() + " end NOOP");
return null;
}
@ -1232,20 +1251,20 @@ public class ServiceSynchronize extends LifecycleService {
NotificationManager nm = context.getSystemService(NotificationManager.class);
NotificationChannel service = new NotificationChannel(
"service" ,
"service",
context.getString(R.string.channel_service),
NotificationManager.IMPORTANCE_MIN);
service.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
nm.createNotificationChannel(service);
NotificationChannel notification = new NotificationChannel(
"notification" ,
"notification",
context.getString(R.string.channel_notification),
NotificationManager.IMPORTANCE_DEFAULT);
nm.createNotificationChannel(notification);
NotificationChannel error = new NotificationChannel(
"error" ,
"error",
context.getString(R.string.channel_error),
NotificationManager.IMPORTANCE_HIGH);
nm.createNotificationChannel(error);


Loading…
Cancel
Save