From d2d3917ab2b1a7410b63a16c5630ed0a50a38c1e Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 29 Oct 2018 10:43:45 +0000 Subject: [PATCH] Added manage notifications button --- .../java/eu/faircode/email/FragmentSetup.java | 20 +++++++++++++++++++ app/src/main/res/layout/fragment_setup.xml | 16 ++++++++++++--- app/src/main/res/values/strings.xml | 1 + 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index 1fc639db..7ef9ad91 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -90,6 +90,8 @@ public class FragmentSetup extends FragmentEx { private Button btnData; + private Button btnNotifications; + private ToggleButton tbDarkTheme; private Button btnOptions; @@ -136,6 +138,8 @@ public class FragmentSetup extends FragmentEx { btnDoze = view.findViewById(R.id.btnDoze); tvDozeDone = view.findViewById(R.id.tvDozeDone); + btnNotifications = view.findViewById(R.id.btnNotifications); + btnData = view.findViewById(R.id.btnData); tbDarkTheme = view.findViewById(R.id.tbDarkTheme); @@ -209,6 +213,15 @@ public class FragmentSetup extends FragmentEx { } }); + PackageManager pm = getContext().getPackageManager(); + btnNotifications.setVisibility(getIntentNotifications(getContext()).resolveActivity(pm) == null ? View.GONE : View.VISIBLE); + btnNotifications.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(getIntentNotifications(getContext())); + } + }); + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); String theme = prefs.getString("theme", "light"); @@ -499,6 +512,13 @@ public class FragmentSetup extends FragmentEx { return intent; } + private static Intent getIntentNotifications(Context context) { + return new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) + .putExtra("app_package", context.getPackageName()) + .putExtra("app_uid", context.getApplicationInfo().uid) + .putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); + } + private void handleExport(Intent data) { Bundle args = new Bundle(); args.putParcelable("uri", data.getData()); diff --git a/app/src/main/res/layout/fragment_setup.xml b/app/src/main/res/layout/fragment_setup.xml index 340bbee3..76d009e5 100644 --- a/app/src/main/res/layout/fragment_setup.xml +++ b/app/src/main/res/layout/fragment_setup.xml @@ -200,13 +200,23 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="9dp" - android:minHeight="0dp" android:minWidth="0dp" + android:minHeight="0dp" android:text="@string/title_setup_data" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/vSeparatorDoze" /> +