Widget improvements

This commit is contained in:
M66B 2019-09-29 10:51:25 +02:00
parent db9e77de43
commit 89a0b9df42
3 changed files with 23 additions and 5 deletions

View File

@ -237,6 +237,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("subject_italic", checked).apply();
WidgetUnified.update(getContext());
}
});

View File

@ -32,6 +32,7 @@ import android.view.View;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import java.util.ArrayList;
@ -43,9 +44,12 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
private boolean threading;
private boolean subject_top;
private boolean subject_italic;
private long account;
private boolean unseen;
private boolean flagged;
private int colorWidgetForeground;
private int colorWidgetRead;
private List<TupleMessageWidget> messages = new ArrayList<>();
WidgetUnifiedRemoteViewsFactory(final Context context, Intent intent) {
@ -67,9 +71,12 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
threading = prefs.getBoolean("threading", true);
subject_top = prefs.getBoolean("subject_top", false);
subject_italic = prefs.getBoolean("subject_italic", true);
account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false);
flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false);
colorWidgetForeground = ContextCompat.getColor(context, R.color.colorWidgetForeground);
colorWidgetRead = ContextCompat.getColor(context, R.color.colorWidgetRead);
messages.clear();
@ -119,17 +126,26 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
SpannableString ssSubject = new SpannableString(TextUtils.isEmpty(message.subject) ? "" : message.subject);
SpannableString ssAccount = new SpannableString(TextUtils.isEmpty(message.accountName) ? "" : message.accountName);
if (!message.ui_seen) {
ssFrom.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, ssFrom.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
ssTime.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, ssTime.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
ssSubject.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, ssSubject.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
ssAccount.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, ssAccount.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
if (message.ui_seen) {
if (subject_italic)
ssSubject.setSpan(new StyleSpan(Typeface.ITALIC), 0, ssSubject.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
} else {
ssFrom.setSpan(new StyleSpan(Typeface.BOLD), 0, ssFrom.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
ssTime.setSpan(new StyleSpan(Typeface.BOLD), 0, ssTime.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
ssSubject.setSpan(new StyleSpan(subject_italic ? Typeface.BOLD_ITALIC : Typeface.BOLD), 0, ssSubject.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
ssAccount.setSpan(new StyleSpan(Typeface.BOLD), 0, ssAccount.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
views.setTextViewText(idFrom, ssFrom);
views.setTextViewText(idTime, ssTime);
views.setTextViewText(idSubject, ssSubject);
views.setTextViewText(idAccount, ssAccount);
views.setTextColor(idFrom, message.ui_seen ? colorWidgetRead : colorWidgetForeground);
views.setTextColor(idTime, message.ui_seen ? colorWidgetRead : colorWidgetForeground);
views.setTextColor(idSubject, message.ui_seen ? colorWidgetRead : colorWidgetForeground);
views.setTextColor(idAccount, message.ui_seen ? colorWidgetRead : colorWidgetForeground);
views.setViewVisibility(idAccount, account < 0 ? View.VISIBLE : View.GONE);
} catch (Throwable ex) {

View File

@ -22,6 +22,7 @@
<color name="colorWidgetForeground">#fff</color>
<color name="colorWidgetBackground">#7f000000</color>
<color name="colorWidgetRead">#ddd</color>
<color name="lightColorItemSelected">#ccc</color>
<color name="lightColorSeparator">#ccc</color>