Notify rate limit option

pull/217/head
M66B 7 months ago
parent 2f058f732c
commit 305377af61

@ -1460,6 +1460,8 @@ public class DebugHelper {
mark = true;
if ("notify_suppress_in_car".equals(key) && Boolean.TRUE.equals(value))
mark = true;
if ("notify_rate_limit".equals(key) && (value == null || (Integer) value != 0))
mark = true;
options.append(' ').append(key).append('=')
.append(value)
.append(mark ? " !!!" : "")

@ -47,11 +47,13 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@ -125,6 +127,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private SwitchCompat swBiometricsNotify;
private SwitchCompat swNotifyOpenFolder;
private SwitchCompat swBackground;
private Spinner spRateLimit;
private SwitchCompat swAlertOnce;
private ImageButton ibTileSync;
private ImageButton ibTileUnseen;
@ -149,7 +152,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
"notify_subtext", "notify_preview", "notify_preview_all", "notify_preview_only", "notify_transliterate", "notify_ascii",
"wearable_preview",
"notify_messaging",
"biometrics_notify", "notify_open_folder", "background_service", "alert_once"
"biometrics_notify", "notify_open_folder", "background_service", "notify_rate_limit", "alert_once"
));
@Override
@ -216,6 +219,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
swBiometricsNotify = view.findViewById(R.id.swBiometricsNotify);
swNotifyOpenFolder = view.findViewById(R.id.swNotifyOpenFolder);
swBackground = view.findViewById(R.id.swBackground);
spRateLimit = view.findViewById(R.id.spRateLimit);
swAlertOnce = view.findViewById(R.id.swAlertOnce);
ibTileSync = view.findViewById(R.id.ibTileSync);
ibTileUnseen = view.findViewById(R.id.ibTileUnseen);
@ -738,6 +742,21 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
}
});
int[] undoValues = getResources().getIntArray(R.array.undoValues);
spRateLimit.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
int value = undoValues[position];
prefs.edit().putInt("notify_rate_limit", value).apply();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
prefs.edit().remove("notify_rate_limit").apply();
}
});
swAlertOnce.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -766,6 +785,13 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
swUnseenIgnored.setVisibility(Helper.isXiaomi() ? View.GONE : View.VISIBLE);
swAlertOnce.setVisibility(Helper.isXiaomi() || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
int notity_rate_limit = prefs.getInt("notity_rate_limit", 0);
for (int pos = 0; pos < undoValues.length; pos++)
if (undoValues[pos] == notity_rate_limit) {
spRateLimit.setSelection(pos);
break;
}
// https://developer.android.com/training/notify-user/group
tvNoGrouping.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.N ? View.VISIBLE : View.GONE);

@ -390,7 +390,7 @@ class NotificationHelper {
boolean biometrics = prefs.getBoolean("biometrics", false);
String pin = prefs.getString("pin", null);
boolean biometric_notify = prefs.getBoolean("biometrics_notify", true);
long notify_rate_limit = prefs.getInt("notify_rate_limit", 0) * 1000L;
long notify_rate_limit = prefs.getInt("notify_rate_limit", 0);
long now = new Date().getTime();
boolean pro = ActivityBilling.isPro(context);

@ -916,6 +916,28 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swBackground" />
<TextView
android:id="@+id/tvRateLimit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_rate_limit"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvBackgroundHint" />
<eu.faircode.email.SpinnerEx
android:id="@+id/spRateLimit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:entries="@array/undoNames"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRateLimit" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAlertOnce"
android:layout_width="0dp"
@ -924,7 +946,7 @@
android:text="@string/title_advanced_alert_once"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvBackgroundHint"
app:layout_constraintTop_toBottomOf="@id/spRateLimit"
app:switchPadding="12dp" />
<TextView

@ -807,6 +807,7 @@
<string name="title_advanced_notify_screen_on">Briefly turn on the screen for new message notifications</string>
<string name="title_advanced_notifications_background">Use background service to synchronize messages</string>
<string name="title_advanced_notifications_background_hint">A background service can be stopped by Android at any time, but doesn\'t require a status bar notification</string>
<string name="title_advanced_rate_limit">Limit notification sounds to once per:</string>
<string name="title_advanced_alert_once" translatable="false">MIUI notification sound workaround</string>
<string name="title_advanced_tiles" translatable="false">Add quick settings tiles</string>

Loading…
Cancel
Save