diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9dc56aadc3..d10e41c674 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -86,6 +86,14 @@
+
+
+
+
+
+
.
+
+ Copyright 2018-2019 by Marcel Bokhorst (M66B)
+*/
+
+import android.appwidget.AppWidgetManager;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.CheckBox;
+
+import androidx.preference.PreferenceManager;
+
+public class ActivityWidgetUnified extends ActivityBase {
+ private int appWidgetId;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Bundle extras = getIntent().getExtras();
+ if (extras == null) {
+ finish();
+ return;
+ }
+
+ appWidgetId = extras.getInt(
+ AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
+
+ getSupportActionBar().setSubtitle(R.string.title_folder_unified);
+ setContentView(R.layout.activity_widget_unified);
+
+ final CheckBox cbUnseen = findViewById(R.id.cbUnseen);
+ final CheckBox cbFlagged = findViewById(R.id.cbFlagged);
+ Button btnSave = findViewById(R.id.btnSave);
+
+ final Intent resultValue = new Intent();
+ resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
+
+ btnSave.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidgetUnified.this);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putBoolean("widget." + appWidgetId + ".unseen", cbUnseen.isChecked());
+ editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked());
+ editor.apply();
+
+ WidgetUnified.init(ActivityWidgetUnified.this, appWidgetId);
+ //WidgetUnified.update(ActivityWidgetUnified.this);
+
+ setResult(RESULT_OK, resultValue);
+ finish();
+ }
+ });
+
+ setResult(RESULT_CANCELED, resultValue);
+ }
+}
diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java
index ce8200f80c..85bd867881 100644
--- a/app/src/main/java/eu/faircode/email/DaoMessage.java
+++ b/app/src/main/java/eu/faircode/email/DaoMessage.java
@@ -274,16 +274,18 @@ public interface DaoMessage {
" AND folder.unified" +
" AND message.ui_hide = 0" +
" AND message.ui_snoozed IS NULL" +
+ " AND (NOT :unseen OR NOT message.ui_seen)" +
+ " AND (NOT :flagged OR message.ui_flagged)" +
" GROUP BY account.id, CASE WHEN message.thread IS NULL THEN message.id ELSE message.thread END" +
" ORDER BY message.received DESC";
@Query(widget)
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
- LiveData> liveWidgetUnified();
+ LiveData> liveWidgetUnified(boolean unseen, boolean flagged);
@Query(widget)
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
- List getWidgetUnified();
+ List getWidgetUnified(boolean unseen, boolean flagged);
@Query("SELECT COUNT(message.id) FROM message" +
" JOIN account ON account.id = message.account" +
diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java
index 5cea5cade7..f4a16bfd14 100644
--- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java
+++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java
@@ -184,7 +184,7 @@ public class ServiceSynchronize extends ServiceBase {
}
});
- db.message().liveWidgetUnified().observe(cowner, new Observer>() {
+ db.message().liveWidgetUnified(false, false).observe(cowner, new Observer>() {
private List last = null;
@Override
diff --git a/app/src/main/java/eu/faircode/email/WidgetUnified.java b/app/src/main/java/eu/faircode/email/WidgetUnified.java
index ffed2aadff..eb1f397c4a 100644
--- a/app/src/main/java/eu/faircode/email/WidgetUnified.java
+++ b/app/src/main/java/eu/faircode/email/WidgetUnified.java
@@ -32,6 +32,25 @@ import android.widget.RemoteViews;
public class WidgetUnified extends AppWidgetProvider {
@Override
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
+ update(context, appWidgetManager, appWidgetIds);
+ }
+
+ static void init(Context context, int appWidgetId) {
+ Log.i("Widget unified init=" + appWidgetId);
+ AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
+ update(context, appWidgetManager, new int[]{appWidgetId});
+ }
+
+ static void update(Context context) {
+ Log.i("Widget unified update");
+ if (Helper.isPro(context)) {
+ AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
+ int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetUnified.class));
+ appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv);
+ }
+ }
+
+ private static void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Intent view = new Intent(context, ActivityView.class);
view.setAction("unified");
view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -64,13 +83,4 @@ public class WidgetUnified extends AppWidgetProvider {
appWidgetManager.updateAppWidget(id, views);
}
}
-
- static void update(Context context) {
- Log.i("Widget unified update");
- if (Helper.isPro(context)) {
- AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
- int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetUnified.class));
- appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv);
- }
- }
}
diff --git a/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java b/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java
index 296ca7b2a5..16f7969896 100644
--- a/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java
+++ b/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java
@@ -22,6 +22,7 @@ package eu.faircode.email;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.Spanned;
@@ -30,6 +31,8 @@ import android.text.style.StyleSpan;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
+import androidx.preference.PreferenceManager;
+
import java.util.ArrayList;
import java.util.List;
@@ -54,8 +57,13 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
@Override
public void onDataSetChanged() {
Log.i("Widget factory changed id=" + appWidgetId);
+
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ boolean unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false);
+ boolean flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false);
+
DB db = DB.getInstance(context);
- messages = db.message().getWidgetUnified();
+ messages = db.message().getWidgetUnified(unseen, flagged);
}
@Override
diff --git a/app/src/main/res/layout/activity_widget_unified.xml b/app/src/main/res/layout/activity_widget_unified.xml
new file mode 100644
index 0000000000..21d5a4b67c
--- /dev/null
+++ b/app/src/main/res/layout/activity_widget_unified.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6302a61455..6b4a906e85 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -794,6 +794,9 @@
starred
snoozed
+ Unread messages only
+ Starred messages only
+
- Always
- Every 15 minutes
diff --git a/app/src/main/res/xml/widget_unified.xml b/app/src/main/res/xml/widget_unified.xml
index f53a376d9a..8d6196e76f 100644
--- a/app/src/main/res/xml/widget_unified.xml
+++ b/app/src/main/res/xml/widget_unified.xml
@@ -1,5 +1,6 @@