Added widget title fields

pull/214/head
M66B 7 months ago
parent 615f1e7a6a
commit 5071a43552

@ -27,6 +27,7 @@ import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -35,6 +36,7 @@ import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.Spinner; import android.widget.Spinner;
@ -70,6 +72,7 @@ public class ActivityWidget extends ActivityBase {
private RadioButton rbNew; private RadioButton rbNew;
private CheckBox cbTop; private CheckBox cbTop;
private Spinner spFontSize; private Spinner spFontSize;
private EditText etName;
private Button btnSave; private Button btnSave;
private ContentLoadingProgressBar pbWait; private ContentLoadingProgressBar pbWait;
private Group grpReady; private Group grpReady;
@ -100,6 +103,7 @@ public class ActivityWidget extends ActivityBase {
int layout = prefs.getInt("widget." + appWidgetId + ".layout", 1 /* new */); int layout = prefs.getInt("widget." + appWidgetId + ".layout", 1 /* new */);
boolean top = prefs.getBoolean("widget." + appWidgetId + ".top", false); boolean top = prefs.getBoolean("widget." + appWidgetId + ".top", false);
int size = prefs.getInt("widget." + appWidgetId + ".text_size", -1); int size = prefs.getInt("widget." + appWidgetId + ".text_size", -1);
String name = prefs.getString("widget." + appWidgetId + ".name", null);
daynight = daynight && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S); daynight = daynight && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S);
@ -119,6 +123,7 @@ public class ActivityWidget extends ActivityBase {
rbNew = findViewById(R.id.rbNew); rbNew = findViewById(R.id.rbNew);
cbTop = findViewById(R.id.cbTop); cbTop = findViewById(R.id.cbTop);
spFontSize = findViewById(R.id.spFontSize); spFontSize = findViewById(R.id.spFontSize);
etName = findViewById(R.id.etName);
btnSave = findViewById(R.id.btnSave); btnSave = findViewById(R.id.btnSave);
pbWait = findViewById(R.id.pbWait); pbWait = findViewById(R.id.pbWait);
grpReady = findViewById(R.id.grpReady); grpReady = findViewById(R.id.grpReady);
@ -268,13 +273,17 @@ public class ActivityWidget extends ActivityBase {
int pos = spFontSize.getSelectedItemPosition(); int pos = spFontSize.getSelectedItemPosition();
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
if (folder == null || folder.id < 0) { String name = etName.getText().toString();
if (account != null && account.id > 0) if (TextUtils.isEmpty(name))
editor.putString("widget." + appWidgetId + ".name", account.name); if (folder == null || folder.id < 0) {
else if (account != null && account.id > 0)
editor.remove("widget." + appWidgetId + ".name"); editor.putString("widget." + appWidgetId + ".name", account.name);
} else else
editor.putString("widget." + appWidgetId + ".name", folder.getDisplayName(ActivityWidget.this)); editor.remove("widget." + appWidgetId + ".name");
} else
editor.putString("widget." + appWidgetId + ".name", folder.getDisplayName(ActivityWidget.this));
else
editor.putString("widget." + appWidgetId + ".name", name);
editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id); editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id);
editor.putLong("widget." + appWidgetId + ".folder", folder == null ? -1L : folder.id); editor.putLong("widget." + appWidgetId + ".folder", folder == null ? -1L : folder.id);
editor.putBoolean("widget." + appWidgetId + ".daynight", cbDayNight.isChecked()); editor.putBoolean("widget." + appWidgetId + ".daynight", cbDayNight.isChecked());
@ -400,6 +409,7 @@ public class ActivityWidget extends ActivityBase {
rbNew.setChecked(layout == 1); rbNew.setChecked(layout == 1);
cbTop.setChecked(top); cbTop.setChecked(top);
spFontSize.setSelection(size + 1); spFontSize.setSelection(size + 1);
etName.setText(name);
updatePreview(); updatePreview();
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);

@ -27,6 +27,7 @@ import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -34,6 +35,7 @@ import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
@ -73,6 +75,7 @@ public class ActivityWidgetUnified extends ActivityBase {
private CheckBox cbAvatars; private CheckBox cbAvatars;
private CheckBox cbAccountName; private CheckBox cbAccountName;
private CheckBox cbCaption; private CheckBox cbCaption;
private EditText etName;
private CheckBox cbRefresh; private CheckBox cbRefresh;
private CheckBox cbCompose; private CheckBox cbCompose;
private Button btnSave; private Button btnSave;
@ -116,6 +119,7 @@ public class ActivityWidgetUnified extends ActivityBase {
boolean avatars = prefs.getBoolean("widget." + appWidgetId + ".avatars", false); boolean avatars = prefs.getBoolean("widget." + appWidgetId + ".avatars", false);
boolean account_name = prefs.getBoolean("widget." + appWidgetId + ".account_name", true); boolean account_name = prefs.getBoolean("widget." + appWidgetId + ".account_name", true);
boolean caption = prefs.getBoolean("widget." + appWidgetId + ".caption", true); boolean caption = prefs.getBoolean("widget." + appWidgetId + ".caption", true);
String name = prefs.getString("widget." + appWidgetId + ".name", null);
boolean refresh = prefs.getBoolean("widget." + appWidgetId + ".refresh", false); boolean refresh = prefs.getBoolean("widget." + appWidgetId + ".refresh", false);
boolean compose = prefs.getBoolean("widget." + appWidgetId + ".compose", false); boolean compose = prefs.getBoolean("widget." + appWidgetId + ".compose", false);
@ -142,6 +146,7 @@ public class ActivityWidgetUnified extends ActivityBase {
cbAvatars = findViewById(R.id.cbAvatars); cbAvatars = findViewById(R.id.cbAvatars);
cbAccountName = findViewById(R.id.cbAccountName); cbAccountName = findViewById(R.id.cbAccountName);
cbCaption = findViewById(R.id.cbCaption); cbCaption = findViewById(R.id.cbCaption);
etName = findViewById(R.id.etName);
cbRefresh = findViewById(R.id.cbRefresh); cbRefresh = findViewById(R.id.cbRefresh);
cbCompose = findViewById(R.id.cbCompose); cbCompose = findViewById(R.id.cbCompose);
btnSave = findViewById(R.id.btnSave); btnSave = findViewById(R.id.btnSave);
@ -249,6 +254,13 @@ public class ActivityWidgetUnified extends ActivityBase {
} }
}); });
cbCaption.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
etName.setEnabled(isChecked);
}
});
btnSave.setOnClickListener(new View.OnClickListener() { btnSave.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -258,12 +270,16 @@ public class ActivityWidgetUnified extends ActivityBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidgetUnified.this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidgetUnified.this);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
if (account != null && account.id > 0) if (account != null && account.id > 0) {
if (folder != null && folder.id > 0) String name = etName.getText().toString();
editor.putString("widget." + appWidgetId + ".name", folder.getDisplayName(ActivityWidgetUnified.this)); if (TextUtils.isEmpty(name))
if (folder != null && folder.id > 0)
editor.putString("widget." + appWidgetId + ".name", folder.getDisplayName(ActivityWidgetUnified.this));
else
editor.putString("widget." + appWidgetId + ".name", account.name);
else else
editor.putString("widget." + appWidgetId + ".name", account.name); editor.putString("widget." + appWidgetId + ".name", name);
else } else
editor.remove("widget." + appWidgetId + ".name"); editor.remove("widget." + appWidgetId + ".name");
int font = spFontSize.getSelectedItemPosition(); int font = spFontSize.getSelectedItemPosition();
@ -421,6 +437,8 @@ public class ActivityWidgetUnified extends ActivityBase {
spSubjectLines.setSelection(subject_lines - 1); spSubjectLines.setSelection(subject_lines - 1);
tvSubjectLinesHint.setText(getString(R.string.title_advanced_preview_lines_hint, NF.format(HtmlHelper.PREVIEW_SIZE))); tvSubjectLinesHint.setText(getString(R.string.title_advanced_preview_lines_hint, NF.format(HtmlHelper.PREVIEW_SIZE)));
cbCaption.setChecked(caption); cbCaption.setChecked(caption);
etName.setText(name);
etName.setEnabled(caption);
cbRefresh.setChecked(refresh); cbRefresh.setChecked(refresh);
cbCompose.setChecked(compose); cbCompose.setChecked(compose);

@ -173,6 +173,28 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvFontSize" /> app:layout_constraintTop_toBottomOf="@id/tvFontSize" />
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_widget_caption"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spFontSize" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/title_optional"
android:inputType="textCapSentences|textAutoCorrect"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvName" />
<Button <Button
android:id="@+id/btnSave" android:id="@+id/btnSave"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -182,7 +204,7 @@
android:drawablePadding="6dp" android:drawablePadding="6dp"
android:text="@string/title_save" android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spFontSize" /> app:layout_constraintTop_toBottomOf="@id/etName" />
<eu.faircode.email.ContentLoadingProgressBar <eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbWait" android:id="@+id/pbWait"

@ -234,6 +234,20 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbAccountName" /> app:layout_constraintTop_toBottomOf="@id/cbAccountName" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="12dp"
android:hint="@string/title_optional"
android:inputType="textCapSentences|textAutoCorrect"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbCaption" />
<CheckBox <CheckBox
android:id="@+id/cbRefresh" android:id="@+id/cbRefresh"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -242,7 +256,7 @@
android:checked="true" android:checked="true"
android:text="@string/title_widget_refresh" android:text="@string/title_widget_refresh"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbCaption" /> app:layout_constraintTop_toBottomOf="@id/etName" />
<CheckBox <CheckBox
android:id="@+id/cbCompose" android:id="@+id/cbCompose"

Loading…
Cancel
Save