From 7221131d788d1bb9a04ac534600ccd80460f6e99 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 6 Oct 2019 21:01:01 +0200 Subject: [PATCH] Addes swipe snooze action --- .../java/eu/faircode/email/ApplicationEx.java | 9 +++++ .../eu/faircode/email/FragmentAccount.java | 6 ++++ .../eu/faircode/email/FragmentMessages.java | 34 ++++++++++++++---- .../faircode/email/FragmentOptionsMisc.java | 27 +++++++++++++- .../email/FragmentOptionsNotifications.java | 28 +-------------- .../java/eu/faircode/email/ServiceUI.java | 4 +-- .../main/res/layout/fragment_options_misc.xml | 35 ++++++++++++++++++- .../layout/fragment_options_notifications.xml | 23 +----------- app/src/main/res/values/strings.xml | 3 ++ 9 files changed, 109 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index 4ee794afae..3ad6611025 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -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"); diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index ea49bd2d4b..216f63234f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -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(); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 5861a13fc3..f96d9aeea2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -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)); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 2dbaec4cec..edfbaf3cee 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -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); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java index c851dc3ff4..c4668847d9 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsNotifications.java @@ -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); } diff --git a/app/src/main/java/eu/faircode/email/ServiceUI.java b/app/src/main/java/eu/faircode/email/ServiceUI.java index 6cf372504b..4ceb6faea5 100644 --- a/app/src/main/java/eu/faircode/email/ServiceUI.java +++ b/app/src/main/java/eu/faircode/email/ServiceUI.java @@ -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 { diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 1b41eb94d1..43d1d8be00 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -23,6 +23,39 @@ app:layout_constraintTop_toTopOf="parent" app:switchPadding="12dp" /> + + + + + + + app:layout_constraintTop_toBottomOf="@id/etDefaultSnooze" /> - - - - + app:layout_constraintTop_toBottomOf="@id/cbNotifyActionSnooze" /> This Android version does not support notification channels Double \'back\' to exit + Default snooze time Biometric authentication timeout Force English language Periodically check if FairEmail is still active @@ -859,8 +860,10 @@ Now After %1$s Reset + Hours Minutes Dismiss + Snooze Accept Decline