mirror of https://github.com/M66B/FairEmail.git
Added widget option to show unread count at the top
This commit is contained in:
parent
91ae7d552e
commit
24cb83c93f
|
@ -59,6 +59,7 @@ public class ActivityWidget extends ActivityBase {
|
|||
private View inNew;
|
||||
private RadioButton rbOld;
|
||||
private RadioButton rbNew;
|
||||
private CheckBox cbTop;
|
||||
private Button btnSave;
|
||||
private ContentLoadingProgressBar pbWait;
|
||||
private Group grpReady;
|
||||
|
@ -84,6 +85,7 @@ public class ActivityWidget extends ActivityBase {
|
|||
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
|
||||
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
|
||||
int layout = prefs.getInt("widget." + appWidgetId + ".layout", 1 /* new */);
|
||||
boolean top = prefs.getBoolean("widget." + appWidgetId + ".top", false);
|
||||
|
||||
daynight = daynight && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S);
|
||||
|
||||
|
@ -99,6 +101,7 @@ public class ActivityWidget extends ActivityBase {
|
|||
inNew = findViewById(R.id.inNew);
|
||||
rbOld = findViewById(R.id.rbOld);
|
||||
rbNew = findViewById(R.id.rbNew);
|
||||
cbTop = findViewById(R.id.cbTop);
|
||||
btnSave = findViewById(R.id.btnSave);
|
||||
pbWait = findViewById(R.id.pbWait);
|
||||
grpReady = findViewById(R.id.grpReady);
|
||||
|
@ -119,7 +122,7 @@ public class ActivityWidget extends ActivityBase {
|
|||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
||||
btnColor.setColor(Color.TRANSPARENT);
|
||||
setBackground();
|
||||
updatePreview();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -151,7 +154,7 @@ public class ActivityWidget extends ActivityBase {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
||||
cbSemiTransparent.setChecked(false);
|
||||
btnColor.setColor(selectedColor);
|
||||
setBackground();
|
||||
updatePreview();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.title_transparent, new DialogInterface.OnClickListener() {
|
||||
|
@ -159,7 +162,7 @@ public class ActivityWidget extends ActivityBase {
|
|||
public void onClick(DialogInterface dialog, int which) {
|
||||
cbSemiTransparent.setChecked(false);
|
||||
btnColor.setColor(Color.TRANSPARENT);
|
||||
setBackground();
|
||||
updatePreview();
|
||||
}
|
||||
})
|
||||
.build()
|
||||
|
@ -183,6 +186,13 @@ public class ActivityWidget extends ActivityBase {
|
|||
}
|
||||
});
|
||||
|
||||
cbTop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
updatePreview();
|
||||
}
|
||||
});
|
||||
|
||||
btnSave.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -198,6 +208,7 @@ public class ActivityWidget extends ActivityBase {
|
|||
editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked());
|
||||
editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor());
|
||||
editor.putInt("widget." + appWidgetId + ".layout", rbNew.isChecked() ? 1 : 0);
|
||||
editor.putBoolean("widget." + appWidgetId + ".top", cbTop.isChecked());
|
||||
editor.putInt("widget." + appWidgetId + ".version", BuildConfig.VERSION_CODE);
|
||||
editor.apply();
|
||||
|
||||
|
@ -213,8 +224,9 @@ public class ActivityWidget extends ActivityBase {
|
|||
spAccount.setAdapter(adapterAccount);
|
||||
|
||||
// Initialize
|
||||
((TextView) inOld.findViewById(R.id.tvCount)).setText("12");
|
||||
((TextView) inNew.findViewById(R.id.tvCount)).setText("12");
|
||||
((TextView) inOld.findViewById(R.id.tvCount)).setText("3");
|
||||
((TextView) inNew.findViewById(R.id.tvCount)).setText("3");
|
||||
((TextView) inNew.findViewById(R.id.tvCountTop)).setText("3");
|
||||
|
||||
cbDayNight.setChecked(daynight);
|
||||
cbDayNight.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.S ? View.GONE : View.VISIBLE);
|
||||
|
@ -224,7 +236,8 @@ public class ActivityWidget extends ActivityBase {
|
|||
btnColor.setEnabled(!daynight);
|
||||
rbOld.setChecked(layout != 1);
|
||||
rbNew.setChecked(layout == 1);
|
||||
setBackground();
|
||||
cbTop.setChecked(top);
|
||||
updatePreview();
|
||||
|
||||
grpReady.setVisibility(View.GONE);
|
||||
pbWait.setVisibility(View.VISIBLE);
|
||||
|
@ -271,7 +284,7 @@ public class ActivityWidget extends ActivityBase {
|
|||
}.execute(this, args, "widget:accounts");
|
||||
}
|
||||
|
||||
private void setBackground() {
|
||||
private void updatePreview() {
|
||||
boolean semi = cbSemiTransparent.isChecked();
|
||||
int background = btnColor.getColor();
|
||||
if (background == Color.TRANSPARENT) {
|
||||
|
@ -297,7 +310,12 @@ public class ActivityWidget extends ActivityBase {
|
|||
|
||||
((ImageView) inNew.findViewById(R.id.ivMessage)).setColorFilter(color);
|
||||
((TextView) inNew.findViewById(R.id.tvCount)).setTextColor(color);
|
||||
((TextView) inNew.findViewById(R.id.tvCountTop)).setTextColor(color);
|
||||
((TextView) inNew.findViewById(R.id.tvAccount)).setTextColor(color);
|
||||
}
|
||||
|
||||
boolean top = cbTop.isChecked();
|
||||
((TextView) inNew.findViewById(R.id.tvCount)).setVisibility(top ? View.GONE : View.VISIBLE);
|
||||
((TextView) inNew.findViewById(R.id.tvCountTop)).setVisibility(top ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ public class Widget extends AppWidgetProvider {
|
|||
boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true);
|
||||
int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
|
||||
int layout = prefs.getInt("widget." + appWidgetId + ".layout", 0);
|
||||
boolean top = prefs.getBoolean("widget." + appWidgetId + ".top", false);
|
||||
int version = prefs.getInt("widget." + appWidgetId + ".version", 0);
|
||||
|
||||
if (version <= 1550)
|
||||
|
@ -143,24 +144,32 @@ public class Widget extends AppWidgetProvider {
|
|||
views.setColorAttr(R.id.ivMessage, "setColorFilter", android.R.attr.textColorPrimary);
|
||||
if (layout == 0)
|
||||
views.setColorStateListAttr(R.id.tvCount, "setTextColor", android.R.attr.textColorPrimary);
|
||||
else
|
||||
else {
|
||||
views.setTextColor(R.id.tvCount, colorWidgetForeground);
|
||||
views.setTextColor(R.id.tvCountTop, colorWidgetForeground);
|
||||
}
|
||||
views.setColorStateListAttr(R.id.tvAccount, "setTextColor", android.R.attr.textColorPrimary);
|
||||
} else if (background == Color.TRANSPARENT) {
|
||||
views.setInt(R.id.ivMessage, "setColorFilter", colorWidgetForeground);
|
||||
views.setTextColor(R.id.tvCount, colorWidgetForeground);
|
||||
views.setTextColor(R.id.tvCountTop, colorWidgetForeground);
|
||||
views.setTextColor(R.id.tvAccount, colorWidgetForeground);
|
||||
} else {
|
||||
float lum = (float) ColorUtils.calculateLuminance(background);
|
||||
int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground);
|
||||
views.setInt(R.id.ivMessage, "setColorFilter", fg);
|
||||
views.setTextColor(R.id.tvCount, layout == 0 ? fg : colorWidgetForeground);
|
||||
views.setTextColor(R.id.tvCountTop, layout == 0 ? fg : colorWidgetForeground);
|
||||
views.setTextColor(R.id.tvAccount, fg);
|
||||
}
|
||||
|
||||
// Set count
|
||||
views.setTextViewText(R.id.tvCount, Helper.formatNumber(unseen, 99, nf));
|
||||
views.setViewVisibility(R.id.tvCount, layout == 1 && unseen == 0 ? View.GONE : View.VISIBLE);
|
||||
String count = Helper.formatNumber(unseen, 99, nf);
|
||||
views.setTextViewText(R.id.tvCount, count);
|
||||
views.setViewVisibility(R.id.tvCount, top || (layout == 1 && unseen == 0) ? View.GONE : View.VISIBLE);
|
||||
|
||||
views.setTextViewText(R.id.tvCountTop, count);
|
||||
views.setViewVisibility(R.id.tvCountTop, !top || (layout == 1 && unseen == 0) ? View.GONE : View.VISIBLE);
|
||||
|
||||
// Set account name
|
||||
if (TextUtils.isEmpty(name))
|
||||
|
|
|
@ -112,6 +112,16 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/inNew" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbTop"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_widget_count_top"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/clLayout" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSave"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -121,7 +131,7 @@
|
|||
android:drawablePadding="6dp"
|
||||
android:text="@string/title_save"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/clLayout" />
|
||||
app:layout_constraintTop_toBottomOf="@id/cbTop" />
|
||||
|
||||
<eu.faircode.email.ContentLoadingProgressBar
|
||||
android:id="@+id/pbWait"
|
||||
|
|
|
@ -41,6 +41,24 @@
|
|||
android:textSize="12sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvCountTop"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@id/ivMessage"
|
||||
android:layout_alignEnd="@id/ivMessage"
|
||||
android:background="@drawable/widget_background_unread"
|
||||
android:includeFontPadding="false"
|
||||
android:lines="1"
|
||||
android:paddingStart="3dp"
|
||||
android:paddingEnd="3dp"
|
||||
android:text="\?"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="@color/colorWidgetForeground"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAccount"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -2101,6 +2101,7 @@
|
|||
<string name="title_widget_padding">Padding size</string>
|
||||
<string name="title_widget_separator_lines">Show separator lines</string>
|
||||
<string name="title_widget_semi_transparent">Semi transparent background</string>
|
||||
<string name="title_widget_count_top">Show unread count at the top</string>
|
||||
<string name="title_widget_avatars">Show contact avatars</string>
|
||||
<string name="title_widget_refresh">Show refresh messages button</string>
|
||||
<string name="title_widget_compose">Show compose new message button</string>
|
||||
|
|
Loading…
Reference in New Issue