From ae58f212180b46e80faa11778c4c0ed7e6483df5 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 10 Nov 2024 11:46:10 +0100 Subject: [PATCH] Remove notification permission nag (#7489) --- .../ui/screen/home/HomeFragment.java | 12 ---- .../sections/AllowNotificationsSection.java | 68 ------------------- .../res/layout/home_section_notification.xml | 66 ------------------ .../playback/service/PlaybackService.java | 3 + .../AutomaticDatabaseExportWorker.java | 3 + ui/i18n/src/main/res/values/strings.xml | 4 -- 6 files changed, 6 insertions(+), 150 deletions(-) delete mode 100644 app/src/main/java/de/danoeh/antennapod/ui/screen/home/sections/AllowNotificationsSection.java delete mode 100644 app/src/main/res/layout/home_section_notification.xml diff --git a/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java index 0b6132ef0..be0793290 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/screen/home/HomeFragment.java @@ -1,10 +1,7 @@ package de.danoeh.antennapod.ui.screen.home; -import android.Manifest; import android.content.Context; import android.content.SharedPreferences; -import android.content.pm.PackageManager; -import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -13,7 +10,6 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; -import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentContainerView; import de.danoeh.antennapod.R; @@ -26,7 +22,6 @@ import de.danoeh.antennapod.net.download.serviceinterface.FeedUpdateManager; import de.danoeh.antennapod.storage.database.DBReader; import de.danoeh.antennapod.ui.echo.EchoConfig; import de.danoeh.antennapod.ui.screen.SearchFragment; -import de.danoeh.antennapod.ui.screen.home.sections.AllowNotificationsSection; import de.danoeh.antennapod.ui.screen.home.sections.DownloadsSection; import de.danoeh.antennapod.ui.screen.home.sections.EchoSection; import de.danoeh.antennapod.ui.screen.home.sections.EpisodesSurpriseSection; @@ -54,7 +49,6 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis public static final String TAG = "HomeFragment"; public static final String PREF_NAME = "PrefHomeFragment"; - public static final String PREF_DISABLE_NOTIFICATION_PERMISSION_NAG = "DisableNotificationPermissionNag"; public static final String PREF_HIDE_ECHO = "HideEcho"; private static final String KEY_UP_ARROW = "up_arrow"; @@ -88,12 +82,6 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis viewBinding.homeContainer.removeAllViews(); SharedPreferences prefs = getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE); - if (Build.VERSION.SDK_INT >= 33 && ContextCompat.checkSelfPermission(getContext(), - Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { - if (!prefs.getBoolean(HomeFragment.PREF_DISABLE_NOTIFICATION_PERMISSION_NAG, false)) { - addSection(new AllowNotificationsSection()); - } - } if (Calendar.getInstance().get(Calendar.YEAR) == EchoConfig.RELEASE_YEAR && Calendar.getInstance().get(Calendar.MONTH) == Calendar.DECEMBER && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) >= 10 diff --git a/app/src/main/java/de/danoeh/antennapod/ui/screen/home/sections/AllowNotificationsSection.java b/app/src/main/java/de/danoeh/antennapod/ui/screen/home/sections/AllowNotificationsSection.java deleted file mode 100644 index 0b26865c8..000000000 --- a/app/src/main/java/de/danoeh/antennapod/ui/screen/home/sections/AllowNotificationsSection.java +++ /dev/null @@ -1,68 +0,0 @@ -package de.danoeh.antennapod.ui.screen.home.sections; - -import android.Manifest; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.provider.Settings; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Toast; -import androidx.activity.result.ActivityResultLauncher; -import androidx.activity.result.contract.ActivityResultContracts; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.databinding.HomeSectionNotificationBinding; -import de.danoeh.antennapod.ui.screen.home.HomeFragment; - -public class AllowNotificationsSection extends Fragment { - HomeSectionNotificationBinding viewBinding; - - private final ActivityResultLauncher requestPermissionLauncher = - registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { - if (isGranted) { - ((MainActivity) getActivity()).loadFragment(HomeFragment.TAG, null); - } else { - viewBinding.openSettingsButton.setVisibility(View.VISIBLE); - viewBinding.allowButton.setVisibility(View.GONE); - Toast.makeText(getContext(), R.string.notification_permission_denied, Toast.LENGTH_LONG).show(); - } - }); - - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, - @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - viewBinding = HomeSectionNotificationBinding.inflate(inflater); - viewBinding.allowButton.setOnClickListener(v -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS); - } - }); - viewBinding.openSettingsButton.setOnClickListener(view -> { - Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); - Uri uri = Uri.fromParts("package", getContext().getPackageName(), null); - intent.setData(uri); - startActivity(intent); - }); - viewBinding.denyButton.setOnClickListener(v -> { - MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext()); - builder.setMessage(R.string.notification_permission_deny_warning); - builder.setPositiveButton(R.string.deny_label, (dialog, which) -> { - getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE) - .edit().putBoolean(HomeFragment.PREF_DISABLE_NOTIFICATION_PERMISSION_NAG, true).apply(); - ((MainActivity) getActivity()).loadFragment(HomeFragment.TAG, null); - }); - builder.setNegativeButton(R.string.cancel_label, null); - builder.show(); - }); - return viewBinding.getRoot(); - } -} diff --git a/app/src/main/res/layout/home_section_notification.xml b/app/src/main/res/layout/home_section_notification.xml deleted file mode 100644 index 4d250b5a8..000000000 --- a/app/src/main/res/layout/home_section_notification.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - -