mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-29 03:05:31 +00:00
Debug: delete notification channels
This commit is contained in:
parent
4e02aad8ae
commit
654339da5d
4 changed files with 83 additions and 0 deletions
|
@ -189,6 +189,9 @@ public interface DaoAccount {
|
|||
@Query("UPDATE account SET `primary` = :primary WHERE id = :id AND NOT (`primary` IS :primary)")
|
||||
int setAccountPrimary(long id, boolean primary);
|
||||
|
||||
@Query("UPDATE account SET notify = :notify WHERE id = :id AND NOT (notify IS :notify)")
|
||||
int setAccountNotify(long id, boolean notify);
|
||||
|
||||
@Query("UPDATE account SET thread = :thread WHERE id = :id AND NOT (thread IS :thread)")
|
||||
int setAccountThread(long id, Long thread);
|
||||
|
||||
|
|
|
@ -48,13 +48,17 @@ import android.widget.TextView;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FragmentOptionsNotifications extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private Button btnManage;
|
||||
private ImageButton ibClear;
|
||||
private Button btnManageDefault;
|
||||
private ImageView ivChannelDefault;
|
||||
private Button btnManageService;
|
||||
|
@ -134,6 +138,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
|
|||
// Get controls
|
||||
|
||||
btnManage = view.findViewById(R.id.btnManage);
|
||||
ibClear = view.findViewById(R.id.ibClear);
|
||||
btnManageDefault = view.findViewById(R.id.btnManageDefault);
|
||||
ivChannelDefault = view.findViewById(R.id.ivChannelDefault);
|
||||
btnManageService = view.findViewById(R.id.btnManageService);
|
||||
|
@ -192,6 +197,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
|
|||
|
||||
PackageManager pm = getContext().getPackageManager();
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean debug = prefs.getBoolean("debug", false);
|
||||
|
||||
final Intent manage = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
|
||||
.putExtra("app_package", getContext().getPackageName())
|
||||
|
@ -206,6 +212,43 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
|
|||
}
|
||||
});
|
||||
|
||||
ibClear.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||
(BuildConfig.DEBUG || debug) ? View.VISIBLE : View.GONE);
|
||||
ibClear.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
List<EntityAccount> accounts = db.account().getAccounts();
|
||||
if (accounts == null)
|
||||
return null;
|
||||
|
||||
for (EntityAccount account : accounts)
|
||||
if (account.notify) {
|
||||
EntityLog.log(context, account.name + " disabling notify");
|
||||
db.account().setAccountNotify(account.id, false);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
protected void onExecuted(Bundle args, Void data) {
|
||||
NotificationHelper.clear(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(FragmentOptionsNotifications.this, new Bundle(), "notification:clear");
|
||||
}
|
||||
});
|
||||
|
||||
final Intent channelNotification = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName())
|
||||
.putExtra(Settings.EXTRA_CHANNEL_ID, "notification");
|
||||
|
|
|
@ -36,6 +36,10 @@ import androidx.annotation.RequiresApi;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
class NotificationHelper {
|
||||
static final int NOTIFICATION_SYNCHRONIZE = 100;
|
||||
static final int NOTIFICATION_SEND = 200;
|
||||
|
@ -43,6 +47,17 @@ class NotificationHelper {
|
|||
static final int NOTIFICATION_UPDATE = 400;
|
||||
static final int NOTIFICATION_TAGGED = 500;
|
||||
|
||||
private static final List<String> PERSISTENT_IDS = Collections.unmodifiableList(Arrays.asList(
|
||||
"service",
|
||||
"send",
|
||||
"notification",
|
||||
"progress",
|
||||
"update",
|
||||
"warning",
|
||||
"error",
|
||||
"alerts"
|
||||
));
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
static void createNotificationChannels(Context context) {
|
||||
// https://issuetracker.google.com/issues/65108694
|
||||
|
@ -134,6 +149,18 @@ class NotificationHelper {
|
|||
nm.createNotificationChannelGroup(group);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
static void clear(Context context) {
|
||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
for (NotificationChannel channel : nm.getNotificationChannels()) {
|
||||
String id = channel.getId();
|
||||
if (!PERSISTENT_IDS.contains(id)) {
|
||||
EntityLog.log(context, "Deleting channel=" + id);
|
||||
nm.deleteNotificationChannel(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
static JSONObject channelToJSON(NotificationChannel channel) throws JSONException {
|
||||
JSONObject jchannel = new JSONObject();
|
||||
|
|
|
@ -75,6 +75,16 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvCaptionGeneral" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibClear"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/title_delete"
|
||||
android:tooltipText="@string/title_delete"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/btnManage"
|
||||
app:srcCompat="@drawable/twotone_delete_24" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvManageHint"
|
||||
android:layout_width="0dp"
|
||||
|
|
Loading…
Reference in a new issue