Addes swipe snooze action

pull/162/head
M66B 5 years ago
parent 619c54cc15
commit 7221131d78

@ -166,6 +166,15 @@ public class ApplicationEx extends Application {
} else if (version < 741)
editor.remove("send_dialog");
else if (version < 751) {
if (prefs.contains("notify_snooze_duration")) {
int minutes = prefs.getInt("notify_snooze_duration", 60);
int hours = (int) Math.ceil(minutes / 60.0);
editor.putInt("default_snooze", hours);
editor.remove("notify_snooze_duration");
}
}
if (BuildConfig.DEBUG && false) {
editor.remove("app_support");
editor.remove("notify_archive");

@ -145,6 +145,7 @@ public class FragmentAccount extends FragmentBase {
static final Long SWIPE_ACTION_ASK = -1L;
static final Long SWIPE_ACTION_SEEN = -2L;
static final Long SWIPE_ACTION_SNOOZE = -3L;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -1429,6 +1430,11 @@ public class FragmentAccount extends FragmentBase {
seen.name = getString(R.string.title_seen);
folders.add(seen);
EntityFolder snooze = new EntityFolder();
snooze.id = SWIPE_ACTION_SNOOZE;
snooze.name = getString(R.string.title_snooze_now);
folders.add(snooze);
folders.addAll(_folders);
adapterSwipe.clear();

@ -1430,10 +1430,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (FragmentAccount.SWIPE_ACTION_ASK.equals(action))
icon = R.drawable.baseline_list_24;
else if (FragmentAccount.SWIPE_ACTION_SEEN.equals(action))
if (message.ui_seen)
icon = R.drawable.baseline_visibility_off_24;
else
icon = R.drawable.baseline_visibility_24;
icon = (message.ui_seen ? R.drawable.baseline_visibility_off_24 : R.drawable.baseline_visibility_24);
else if (FragmentAccount.SWIPE_ACTION_SNOOZE.equals(action))
icon = (message.ui_snoozed == null ? R.drawable.baseline_timelapse_24 : R.drawable.baseline_timer_off_24);
else
icon = EntityFolder.getIcon(dX > 0 ? swipes.right_type : swipes.left_type);
Drawable d = getResources().getDrawable(icon, getContext().getTheme()).mutate();
@ -1490,10 +1489,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Log.i("Swiped dir=" + direction + " message=" + message.id);
if (FragmentAccount.SWIPE_ACTION_SEEN.equals(action))
onActionSeenSelection(!message.ui_seen, message.id);
else if (FragmentAccount.SWIPE_ACTION_ASK.equals(action))
if (FragmentAccount.SWIPE_ACTION_ASK.equals(action))
swipeAsk(message, viewHolder);
else if (FragmentAccount.SWIPE_ACTION_SEEN.equals(action))
onActionSeenSelection(!message.ui_seen, message.id);
else if (FragmentAccount.SWIPE_ACTION_SNOOZE.equals(action))
onActionSnooze(message);
else
swipeFolder(message, action);
}
@ -1907,6 +1908,25 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(this, args, "messages:seen");
}
private void onActionSnooze(TupleMessageEx message) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
long duration = prefs.getInt("default_snooze", 1) * 3600 * 1000L;
Bundle args = new Bundle();
args.putLong("account", message.account);
args.putString("thread", message.thread);
args.putLong("id", message.id);
if (message.ui_snoozed == null) {
args.putLong("duration", duration);
args.putLong("time", new Date().getTime() + duration);
} else {
args.putLong("duration", 0);
args.putLong("time", 0);
}
onSnooze(args);
}
private void onActionSnoozeSelection() {
Bundle args = new Bundle();
args.putString("title", getString(R.string.title_snooze));

@ -25,6 +25,8 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -34,6 +36,7 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@ -47,6 +50,7 @@ import androidx.preference.PreferenceManager;
public class FragmentOptionsMisc extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private SwitchCompat swDoubleBack;
private EditText etDefaultSnooze;
private Spinner spBiometricsTimeout;
private SwitchCompat swEnglish;
private SwitchCompat swWatchdog;
@ -66,7 +70,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private Group grpDebug;
private final static String[] RESET_OPTIONS = new String[]{
"double_back", "biometrics_timeout", "english", "watchdog", "updates", "experiments", "crash_reports", "debug"
"double_back", "default_snooze", "biometrics_timeout", "english", "watchdog", "updates", "experiments", "crash_reports", "debug"
};
private final static String[] RESET_QUESTIONS = new String[]{
@ -86,6 +90,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
// Get controls
swDoubleBack = view.findViewById(R.id.swDoubleBack);
etDefaultSnooze = view.findViewById(R.id.etDefaultSnooze);
spBiometricsTimeout = view.findViewById(R.id.spBiometricsTimeout);
swEnglish = view.findViewById(R.id.swEnglish);
swWatchdog = view.findViewById(R.id.swWatchdog);
@ -117,6 +122,25 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
etDefaultSnooze.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable editable) {
try {
int hours = Integer.parseInt(editable.toString());
prefs.edit().putInt("default_snooze", hours).apply();
} catch (NumberFormatException ignored) {
}
}
});
spBiometricsTimeout.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
@ -297,6 +321,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
swDoubleBack.setChecked(prefs.getBoolean("double_back", true));
etDefaultSnooze.setText(Integer.toString(prefs.getInt("default_snooze", 1)));
int biometrics_timeout = prefs.getInt("biometrics_timeout", 2);
int[] biometricTimeoutValues = getResources().getIntArray(R.array.biometricsTimeoutValues);

@ -28,8 +28,6 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -39,7 +37,6 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
@ -67,7 +64,6 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private CheckBox cbNotifyActionFlag;
private CheckBox cbNotifyActionSeen;
private CheckBox cbNotifyActionSnooze;
private EditText etNotifyActionSnooze;
private TextView tvNotifyActionsPro;
private SwitchCompat swBiometricsNotify;
private Button btnManage;
@ -85,7 +81,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
"badge", "unseen_ignored",
"notify_summary", "notify_remove", "notify_preview",
"notify_trash", "notify_junk", "notify_archive", "notify_reply", "notify_reply_direct",
"notify_flag", "notify_seen", "notify_snooze", "notify_snooze_duration",
"notify_flag", "notify_seen", "notify_snooze",
"biometrics_notify",
"light", "sound", "alert_once"
};
@ -113,7 +109,6 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
cbNotifyActionFlag = view.findViewById(R.id.cbNotifyActionFlag);
cbNotifyActionSeen = view.findViewById(R.id.cbNotifyActionSeen);
cbNotifyActionSnooze = view.findViewById(R.id.cbNotifyActionSnooze);
etNotifyActionSnooze = view.findViewById(R.id.etNotifyActionSnooze);
tvNotifyActionsPro = view.findViewById(R.id.tvNotifyActionsPro);
swBiometricsNotify = view.findViewById(R.id.swBiometricsNotify);
btnManage = view.findViewById(R.id.btnManage);
@ -228,25 +223,6 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
}
});
etNotifyActionSnooze.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable editable) {
try {
int minutes = Integer.parseInt(editable.toString());
prefs.edit().putInt("notify_snooze_duration", minutes).apply();
} catch (NumberFormatException ex) {
}
}
});
Helper.linkPro(tvNotifyActionsPro);
swBiometricsNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@ -376,7 +352,6 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
cbNotifyActionFlag.setChecked(prefs.getBoolean("notify_flag", false) && pro);
cbNotifyActionSeen.setChecked(prefs.getBoolean("notify_seen", true) || !pro);
cbNotifyActionSnooze.setChecked(prefs.getBoolean("notify_snooze", false) || !pro);
etNotifyActionSnooze.setText(Integer.toString(prefs.getInt("notify_snooze_duration", 60)));
swNotifyRemove.setChecked(prefs.getBoolean("notify_remove", true));
swBiometricsNotify.setChecked(prefs.getBoolean("biometrics_notify", false));
@ -400,7 +375,6 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
cbNotifyActionFlag.setEnabled(pro && !checked);
cbNotifyActionSeen.setEnabled(pro && !checked);
cbNotifyActionSnooze.setEnabled(pro && !checked);
etNotifyActionSnooze.setEnabled(pro && !checked);
swBiometricsNotify.setEnabled(!checked);
}

@ -290,9 +290,9 @@ public class ServiceUI extends IntentService {
private void onSnooze(long id) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
int notify_snooze_duration = prefs.getInt("notify_snooze_duration", 60);
int notify_snooze_duration = prefs.getInt("default_snooze", 1);
long wakeup = new Date().getTime() + notify_snooze_duration * 60 * 1000L;
long wakeup = new Date().getTime() + notify_snooze_duration * 3600 * 1000L;
DB db = DB.getInstance(this);
try {

@ -23,6 +23,39 @@
app:layout_constraintTop_toTopOf="parent"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvDefaultSnooze"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_default_snooze"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDoubleBack" />
<EditText
android:id="@+id/etDefaultSnooze"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="end"
android:inputType="number"
android:text="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDefaultSnooze" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:text="@string/title_hours"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/etDefaultSnooze"
app:layout_constraintStart_toEndOf="@+id/etDefaultSnooze"
app:layout_constraintTop_toTopOf="@+id/etDefaultSnooze" />
<TextView
android:id="@+id/tvBiometricsTimeout"
android:layout_width="0dp"
@ -34,7 +67,7 @@
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDoubleBack" />
app:layout_constraintTop_toBottomOf="@id/etDefaultSnooze" />
<Spinner
android:id="@+id/spBiometricsTimeout"

@ -191,27 +191,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbNotifyActionSeen" />
<EditText
android:id="@+id/etNotifyActionSnooze"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:gravity="end"
android:inputType="text"
android:text="60"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbNotifyActionSnooze" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:text="@string/title_minutes"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/etNotifyActionSnooze"
app:layout_constraintStart_toEndOf="@+id/etNotifyActionSnooze"
app:layout_constraintTop_toTopOf="@+id/etNotifyActionSnooze" />
<TextView
android:id="@+id/tvNotifyActionsHint"
android:layout_width="0dp"
@ -223,7 +202,7 @@
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etNotifyActionSnooze" />
app:layout_constraintTop_toBottomOf="@id/cbNotifyActionSnooze" />
<TextView
android:id="@+id/tvNotifyActionsPro"

@ -313,6 +313,7 @@
<string name="title_advanced_notify_no_channels">This Android version does not support notification channels</string>
<string name="title_advanced_double_back">Double \'back\' to exit</string>
<string name="title_advanced_default_snooze">Default snooze time</string>
<string name="title_advanced_biometrics_timeout">Biometric authentication timeout</string>
<string name="title_advanced_english">Force English language</string>
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>
@ -859,8 +860,10 @@
<string name="title_now">Now</string>
<string name="title_after">After %1$s</string>
<string name="title_reset">Reset</string>
<string name="title_hours">Hours</string>
<string name="title_minutes">Minutes</string>
<string name="title_dismiss">Dismiss</string>
<string name="title_snooze_now">Snooze</string>
<string name="title_icalendar_accept">Accept</string>
<string name="title_icalendar_decline">Decline</string>

Loading…
Cancel
Save