mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-07 17:43:18 +02:00
Added account name to unified widget
This commit is contained in:
@@ -273,7 +273,7 @@ public interface DaoMessage {
|
||||
" ORDER BY message.received")
|
||||
LiveData<List<TupleMessageEx>> liveUnseenNotify();
|
||||
|
||||
String widget = "SELECT message.*" +
|
||||
String widget = "SELECT message.*, account.name AS accountName" +
|
||||
" FROM message" +
|
||||
" JOIN account ON account.id = message.account" +
|
||||
" JOIN folder ON folder.id = message.folder" +
|
||||
@@ -284,10 +284,10 @@ public interface DaoMessage {
|
||||
" ORDER BY message.received DESC";
|
||||
|
||||
@Query(widget)
|
||||
LiveData<List<EntityMessage>> liveWidgetUnified();
|
||||
LiveData<List<TupleMessageWidget>> liveWidgetUnified();
|
||||
|
||||
@Query(widget)
|
||||
List<EntityMessage> getWidgetUnified();
|
||||
List<TupleMessageWidget> getWidgetUnified();
|
||||
|
||||
@Query("SELECT COUNT(message.id) FROM message" +
|
||||
" JOIN account ON account.id = message.account" +
|
||||
|
||||
@@ -186,24 +186,25 @@ public class ServiceSynchronize extends LifecycleService {
|
||||
}
|
||||
});
|
||||
|
||||
db.message().liveWidgetUnified().observe(cowner, new Observer<List<EntityMessage>>() {
|
||||
private List<EntityMessage> last = null;
|
||||
db.message().liveWidgetUnified().observe(cowner, new Observer<List<TupleMessageWidget>>() {
|
||||
private List<TupleMessageWidget> last = null;
|
||||
|
||||
@Override
|
||||
public void onChanged(List<EntityMessage> messages) {
|
||||
public void onChanged(List<TupleMessageWidget> messages) {
|
||||
if (messages == null)
|
||||
messages = new ArrayList<>();
|
||||
|
||||
boolean changed = false;
|
||||
if (last != null && last.size() == messages.size()) {
|
||||
for (int i = 0; i < last.size(); i++) {
|
||||
EntityMessage m1 = last.get(i);
|
||||
EntityMessage m2 = messages.get(i);
|
||||
TupleMessageWidget m1 = last.get(i);
|
||||
TupleMessageWidget m2 = messages.get(i);
|
||||
if (!m1.id.equals(m2.id) ||
|
||||
!MessageHelper.equal(m1.from, m2.from) ||
|
||||
!m1.received.equals(m2.received) ||
|
||||
!Objects.equals(m1.subject, m2.subject) ||
|
||||
m1.ui_seen != m2.ui_seen) {
|
||||
!(m1.ui_seen == m2.ui_seen) ||
|
||||
!Objects.equals(m1.accountName, m2.accountName)) {
|
||||
changed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
35
app/src/main/java/eu/faircode/email/TupleMessageWidget.java
Normal file
35
app/src/main/java/eu/faircode/email/TupleMessageWidget.java
Normal file
@@ -0,0 +1,35 @@
|
||||
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 java.util.Objects;
|
||||
|
||||
public class TupleMessageWidget extends EntityMessage {
|
||||
public String accountName;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof TupleMessageEx) {
|
||||
TupleMessageEx other = (TupleMessageEx) obj;
|
||||
return (super.equals(obj) && Objects.equals(this.accountName, other.accountName));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package eu.faircode.email;
|
||||
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
@@ -36,11 +37,13 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
|
||||
private Context context;
|
||||
private int appWidgetId;
|
||||
|
||||
private List<EntityMessage> messages = new ArrayList<>();
|
||||
private List<TupleMessageWidget> messages = new ArrayList<>();
|
||||
|
||||
WidgetUnifiedRemoteViewsFactory(final Context context, final int appWidgetId) {
|
||||
this.appWidgetId = appWidgetId;
|
||||
WidgetUnifiedRemoteViewsFactory(final Context context, Intent intent) {
|
||||
this.context = context;
|
||||
this.appWidgetId = intent.getIntExtra(
|
||||
AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,30 +70,37 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
|
||||
|
||||
@Override
|
||||
public RemoteViews getViewAt(int position) {
|
||||
EntityMessage message = messages.get(position);
|
||||
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.item_widget_unified);
|
||||
|
||||
Intent thread = new Intent(context, ActivityView.class);
|
||||
thread.putExtra("account", message.account);
|
||||
thread.putExtra("thread", message.thread);
|
||||
thread.putExtra("id", message.id);
|
||||
views.setOnClickFillInIntent(R.id.llMessage, thread);
|
||||
try {
|
||||
TupleMessageWidget message = messages.get(position);
|
||||
|
||||
SpannableString from = new SpannableString(MessageHelper.formatAddressesShort(message.from));
|
||||
SpannableString time = new SpannableString(Helper.getRelativeTimeSpanString(context, message.received));
|
||||
SpannableString subject = new SpannableString(TextUtils.isEmpty(message.subject) ? "" : message.subject);
|
||||
Intent thread = new Intent(context, ActivityView.class);
|
||||
thread.putExtra("account", message.account);
|
||||
thread.putExtra("thread", message.thread);
|
||||
thread.putExtra("id", message.id);
|
||||
views.setOnClickFillInIntent(R.id.llMessage, thread);
|
||||
|
||||
if (!message.ui_seen) {
|
||||
from.setSpan(new StyleSpan(Typeface.BOLD), 0, from.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
time.setSpan(new StyleSpan(Typeface.BOLD), 0, time.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
subject.setSpan(new StyleSpan(Typeface.BOLD), 0, subject.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
SpannableString from = new SpannableString(MessageHelper.formatAddressesShort(message.from));
|
||||
SpannableString time = new SpannableString(Helper.getRelativeTimeSpanString(context, message.received));
|
||||
SpannableString subject = new SpannableString(TextUtils.isEmpty(message.subject) ? "" : message.subject);
|
||||
SpannableString account = new SpannableString(TextUtils.isEmpty(message.accountName) ? "" : message.accountName);
|
||||
|
||||
if (!message.ui_seen) {
|
||||
from.setSpan(new StyleSpan(Typeface.BOLD), 0, from.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
time.setSpan(new StyleSpan(Typeface.BOLD), 0, time.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
subject.setSpan(new StyleSpan(Typeface.BOLD), 0, subject.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
account.setSpan(new StyleSpan(Typeface.BOLD), 0, account.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
}
|
||||
|
||||
views.setTextViewText(R.id.tvFrom, from);
|
||||
views.setTextViewText(R.id.tvTime, time);
|
||||
views.setTextViewText(R.id.tvSubject, subject);
|
||||
views.setTextViewText(R.id.tvAccount, account);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
views.setTextViewText(R.id.tvFrom, from);
|
||||
views.setTextViewText(R.id.tvTime, time);
|
||||
views.setTextViewText(R.id.tvSubject, subject);
|
||||
|
||||
return views;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,16 +19,12 @@ package eu.faircode.email;
|
||||
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Intent;
|
||||
import android.widget.RemoteViewsService;
|
||||
|
||||
public class WidgetUnifiedService extends RemoteViewsService {
|
||||
@Override
|
||||
public RemoteViewsFactory onGetViewFactory(Intent intent) {
|
||||
return new WidgetUnifiedRemoteViewsFactory(
|
||||
this.getApplicationContext(),
|
||||
intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
AppWidgetManager.INVALID_APPWIDGET_ID));
|
||||
return new WidgetUnifiedRemoteViewsFactory(this.getApplicationContext(), intent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user