Added account name to unified widget

pull/159/head
M66B 6 years ago
parent f5ca9277c3
commit 1e30425bc3

@ -273,7 +273,7 @@ public interface DaoMessage {
" ORDER BY message.received") " ORDER BY message.received")
LiveData<List<TupleMessageEx>> liveUnseenNotify(); LiveData<List<TupleMessageEx>> liveUnseenNotify();
String widget = "SELECT message.*" + String widget = "SELECT message.*, account.name AS accountName" +
" FROM message" + " FROM message" +
" JOIN account ON account.id = message.account" + " JOIN account ON account.id = message.account" +
" JOIN folder ON folder.id = message.folder" + " JOIN folder ON folder.id = message.folder" +
@ -284,10 +284,10 @@ public interface DaoMessage {
" ORDER BY message.received DESC"; " ORDER BY message.received DESC";
@Query(widget) @Query(widget)
LiveData<List<EntityMessage>> liveWidgetUnified(); LiveData<List<TupleMessageWidget>> liveWidgetUnified();
@Query(widget) @Query(widget)
List<EntityMessage> getWidgetUnified(); List<TupleMessageWidget> getWidgetUnified();
@Query("SELECT COUNT(message.id) FROM message" + @Query("SELECT COUNT(message.id) FROM message" +
" JOIN account ON account.id = message.account" + " 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>>() { db.message().liveWidgetUnified().observe(cowner, new Observer<List<TupleMessageWidget>>() {
private List<EntityMessage> last = null; private List<TupleMessageWidget> last = null;
@Override @Override
public void onChanged(List<EntityMessage> messages) { public void onChanged(List<TupleMessageWidget> messages) {
if (messages == null) if (messages == null)
messages = new ArrayList<>(); messages = new ArrayList<>();
boolean changed = false; boolean changed = false;
if (last != null && last.size() == messages.size()) { if (last != null && last.size() == messages.size()) {
for (int i = 0; i < last.size(); i++) { for (int i = 0; i < last.size(); i++) {
EntityMessage m1 = last.get(i); TupleMessageWidget m1 = last.get(i);
EntityMessage m2 = messages.get(i); TupleMessageWidget m2 = messages.get(i);
if (!m1.id.equals(m2.id) || if (!m1.id.equals(m2.id) ||
!MessageHelper.equal(m1.from, m2.from) || !MessageHelper.equal(m1.from, m2.from) ||
!m1.received.equals(m2.received) || !m1.received.equals(m2.received) ||
!Objects.equals(m1.subject, m2.subject) || !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; changed = true;
break; break;
} }

@ -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) Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/ */
import android.appwidget.AppWidgetManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface; import android.graphics.Typeface;
@ -36,11 +37,13 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
private Context context; private Context context;
private int appWidgetId; private int appWidgetId;
private List<EntityMessage> messages = new ArrayList<>(); private List<TupleMessageWidget> messages = new ArrayList<>();
WidgetUnifiedRemoteViewsFactory(final Context context, final int appWidgetId) { WidgetUnifiedRemoteViewsFactory(final Context context, Intent intent) {
this.appWidgetId = appWidgetId;
this.context = context; this.context = context;
this.appWidgetId = intent.getIntExtra(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
} }
@Override @Override
@ -67,30 +70,37 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
@Override @Override
public RemoteViews getViewAt(int position) { public RemoteViews getViewAt(int position) {
EntityMessage message = messages.get(position);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.item_widget_unified); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.item_widget_unified);
Intent thread = new Intent(context, ActivityView.class); try {
thread.putExtra("account", message.account); TupleMessageWidget message = messages.get(position);
thread.putExtra("thread", message.thread);
thread.putExtra("id", message.id); Intent thread = new Intent(context, ActivityView.class);
views.setOnClickFillInIntent(R.id.llMessage, thread); thread.putExtra("account", message.account);
thread.putExtra("thread", message.thread);
SpannableString from = new SpannableString(MessageHelper.formatAddressesShort(message.from)); thread.putExtra("id", message.id);
SpannableString time = new SpannableString(Helper.getRelativeTimeSpanString(context, message.received)); views.setOnClickFillInIntent(R.id.llMessage, thread);
SpannableString subject = new SpannableString(TextUtils.isEmpty(message.subject) ? "" : message.subject);
SpannableString from = new SpannableString(MessageHelper.formatAddressesShort(message.from));
if (!message.ui_seen) { SpannableString time = new SpannableString(Helper.getRelativeTimeSpanString(context, message.received));
from.setSpan(new StyleSpan(Typeface.BOLD), 0, from.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); SpannableString subject = new SpannableString(TextUtils.isEmpty(message.subject) ? "" : message.subject);
time.setSpan(new StyleSpan(Typeface.BOLD), 0, time.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); SpannableString account = new SpannableString(TextUtils.isEmpty(message.accountName) ? "" : message.accountName);
subject.setSpan(new StyleSpan(Typeface.BOLD), 0, subject.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
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; return views;
} }

@ -19,16 +19,12 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B) Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/ */
import android.appwidget.AppWidgetManager;
import android.content.Intent; import android.content.Intent;
import android.widget.RemoteViewsService; import android.widget.RemoteViewsService;
public class WidgetUnifiedService extends RemoteViewsService { public class WidgetUnifiedService extends RemoteViewsService {
@Override @Override
public RemoteViewsFactory onGetViewFactory(Intent intent) { public RemoteViewsFactory onGetViewFactory(Intent intent) {
return new WidgetUnifiedRemoteViewsFactory( return new WidgetUnifiedRemoteViewsFactory(this.getApplicationContext(), intent);
this.getApplicationContext(),
intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID));
} }
} }

@ -34,13 +34,30 @@
android:textColor="@color/colorWidgetForeground" /> android:textColor="@color/colorWidgetForeground" />
</LinearLayout> </LinearLayout>
<TextView <LinearLayout
android:id="@+id/tvSubject"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end" android:orientation="horizontal">
android:maxLines="1"
android:text="Subject" <TextView
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:id="@+id/tvSubject"
android:textColor="@color/colorWidgetForeground" /> android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text="Subject"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/colorWidgetForeground" />
<TextView
android:id="@+id/tvAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:maxLines="1"
android:text="Account"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/colorWidgetForeground" />
</LinearLayout>
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save