mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 16:43:26 +02:00
Added unified inbox widget configuration to show unseen/flagged messages only
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FairEmail is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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<List<TupleMessageWidget>> liveWidgetUnified();
|
||||
LiveData<List<TupleMessageWidget>> liveWidgetUnified(boolean unseen, boolean flagged);
|
||||
|
||||
@Query(widget)
|
||||
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
|
||||
List<TupleMessageWidget> getWidgetUnified();
|
||||
List<TupleMessageWidget> getWidgetUnified(boolean unseen, boolean flagged);
|
||||
|
||||
@Query("SELECT COUNT(message.id) FROM message" +
|
||||
" JOIN account ON account.id = message.account" +
|
||||
|
||||
@@ -184,7 +184,7 @@ public class ServiceSynchronize extends ServiceBase {
|
||||
}
|
||||
});
|
||||
|
||||
db.message().liveWidgetUnified().observe(cowner, new Observer<List<TupleMessageWidget>>() {
|
||||
db.message().liveWidgetUnified(false, false).observe(cowner, new Observer<List<TupleMessageWidget>>() {
|
||||
private List<TupleMessageWidget> last = null;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user