Added notification action to mark messages read

Fixes #126
This commit is contained in:
M66B 2018-09-19 09:43:57 +00:00
parent b65e504098
commit 2ed92f310e
2 changed files with 50 additions and 2 deletions

View File

@ -167,6 +167,12 @@ public interface DaoMessage {
" AND NOT ui_found" /* keep found messages */) " AND NOT ui_found" /* keep found messages */)
List<Long> getUids(long folder, long received); List<Long> getUids(long folder, long received);
@Query("SELECT message.* FROM message" +
" JOIN folder ON folder.id = message.folder" +
" WHERE NOT message.ui_seen" +
" AND folder.unified")
List<EntityMessage> getUnseenUnifiedMessages();
@Insert @Insert
long insertMessage(EntityMessage message); long insertMessage(EntityMessage message);

View File

@ -27,6 +27,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.Icon;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.Network; import android.net.Network;
@ -107,6 +108,7 @@ import javax.mail.search.ReceivedDateTerm;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleService; import androidx.lifecycle.LifecycleService;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
@ -229,8 +231,38 @@ public class ServiceSynchronize extends LifecycleService {
protected void onLoaded(Bundle args, Void data) { protected void onLoaded(Bundle args, Void data) {
Log.i(Helper.TAG, "Updated seen until"); Log.i(Helper.TAG, "Updated seen until");
} }
}.load(ServiceSynchronize.this, args); }.load(this, args);
} else if ("seen".equals(intent.getAction())) {
Bundle args = new Bundle();
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
DB db = DB.getInstance(context);
try {
db.beginTransaction();
for (EntityMessage message : db.message().getUnseenUnifiedMessages()) {
db.message().setMessageUiSeen(message.id, true);
EntityOperation.queue(db, message, EntityOperation.SEEN, true);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
EntityOperation.process(context);
return null;
}
@Override
protected void onLoaded(Bundle args, Void data) {
Log.i(Helper.TAG, "Set seen");
}
}.load(this, args);
} }
return START_STICKY; return START_STICKY;
@ -284,6 +316,15 @@ public class ServiceSynchronize extends LifecycleService {
delete.setAction("unseen"); delete.setAction("unseen");
PendingIntent pid = PendingIntent.getService(this, 1, delete, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pid = PendingIntent.getService(this, 1, delete, PendingIntent.FLAG_UPDATE_CURRENT);
Intent seen = new Intent(this, ServiceSynchronize.class);
seen.setAction("seen");
PendingIntent pis = PendingIntent.getService(this, 2, seen, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Action.Builder actionBuilder = new Notification.Action.Builder(
Icon.createWithResource(this, R.drawable.baseline_mail_outline_24),
getString(R.string.title_seen),
pis);
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// Build notification // Build notification
@ -302,7 +343,8 @@ public class ServiceSynchronize extends LifecycleService {
.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); .setDeleteIntent(pid)
.addAction(actionBuilder.build());
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O && if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O &&
prefs.getBoolean("light", false)) { prefs.getBoolean("light", false)) {