Added account name to unified widget

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

@ -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;
}

@ -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);
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);
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);
try {
TupleMessageWidget message = messages.get(position);
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);
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);
}
}

@ -34,13 +34,30 @@
android:textColor="@color/colorWidgetForeground" />
</LinearLayout>
<TextView
android:id="@+id/tvSubject"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="Subject"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/colorWidgetForeground" />
android:orientation="horizontal">
<TextView
android:id="@+id/tvSubject"
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>
Loading…
Cancel
Save