mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-27 08:23:24 +00:00
Open relevant folder/messages from unread count widget
This commit is contained in:
parent
5e5213f5b8
commit
767c8e8fe2
3 changed files with 41 additions and 12 deletions
|
@ -882,6 +882,14 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
startService(clear);
|
||||
}
|
||||
|
||||
} else if (action.startsWith("folders")) {
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||
getSupportFragmentManager().popBackStack("unified", 0);
|
||||
|
||||
long account = Long.parseLong(action.split(":", 2)[1]);
|
||||
if (account > 0)
|
||||
onMenuFolders(account);
|
||||
|
||||
} else if (action.startsWith("folder")) {
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||
getSupportFragmentManager().popBackStack("unified", 0);
|
||||
|
@ -909,10 +917,13 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
|
||||
Helper.viewFAQ(this, "alert".equals(action) ? 23 : 22);
|
||||
|
||||
} else if ("outbox".equals(action))
|
||||
} else if ("outbox".equals(action)) {
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||
getSupportFragmentManager().popBackStack("unified", 0);
|
||||
|
||||
onMenuOutbox();
|
||||
|
||||
else if (action.startsWith("thread")) {
|
||||
} else if (action.startsWith("thread")) {
|
||||
intent.putExtra("thread", action.split(":", 2)[1]);
|
||||
onViewThread(intent);
|
||||
|
||||
|
|
|
@ -163,6 +163,12 @@ public interface DaoFolder {
|
|||
" AND folder.synchronize")
|
||||
List<EntityFolder> getSynchronizingFolders(long account);
|
||||
|
||||
@Query("SELECT * FROM folder" +
|
||||
" WHERE folder.account = :account" +
|
||||
" AND folder.`synchronize`" +
|
||||
" AND folder.notify")
|
||||
List<EntityFolder> getNotifyingFolders(long account);
|
||||
|
||||
@Query("SELECT folder.type" +
|
||||
", COUNT(message.id) AS messages" +
|
||||
", SUM(CASE WHEN NOT message.ui_seen THEN 1 ELSE 0 END) AS unseen" +
|
||||
|
|
|
@ -32,6 +32,8 @@ import android.widget.RemoteViews;
|
|||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
public class Widget extends AppWidgetProvider {
|
||||
|
@ -53,23 +55,33 @@ public class Widget extends AppWidgetProvider {
|
|||
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
|
||||
String name = prefs.getString("widget." + appWidgetId + ".name", null);
|
||||
|
||||
EntityFolder folder = db.folder().getFolderByType(account, EntityFolder.INBOX);
|
||||
List<EntityFolder> folders = db.folder().getNotifyingFolders(account);
|
||||
if (folders == null)
|
||||
folders = new ArrayList<>();
|
||||
|
||||
PendingIntent pi;
|
||||
if (folder == null) {
|
||||
if (folders.size() == 1) {
|
||||
Intent view = new Intent(context, ActivityView.class);
|
||||
view.setAction("unified");
|
||||
view.putExtra("refresh", true);
|
||||
view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
pi = PendingIntent.getActivity(context, ActivityView.REQUEST_UNIFIED, view, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
} else {
|
||||
Intent view = new Intent(context, ActivityView.class);
|
||||
view.setAction("folder:" + folder.id);
|
||||
view.setAction("folder:" + folders.get(0).id);
|
||||
view.putExtra("account", account);
|
||||
view.putExtra("type", folder.type);
|
||||
view.putExtra("type", folders.get(0).type);
|
||||
view.putExtra("refresh", true);
|
||||
view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
pi = PendingIntent.getActivity(context, appWidgetId, view, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
} else {
|
||||
if (account < 0) {
|
||||
Intent view = new Intent(context, ActivityView.class);
|
||||
view.setAction("unified");
|
||||
view.putExtra("refresh", true);
|
||||
view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
pi = PendingIntent.getActivity(context, ActivityView.REQUEST_UNIFIED, view, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
} else {
|
||||
Intent view = new Intent(context, ActivityView.class);
|
||||
view.setAction("folders:" + account);
|
||||
view.putExtra("refresh", true);
|
||||
view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
pi = PendingIntent.getActivity(context, appWidgetId, view, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
}
|
||||
|
||||
TupleMessageStats stats = db.message().getWidgetUnseen(account < 0 ? null : account);
|
||||
|
|
Loading…
Reference in a new issue