Remove notification permission nag (#7489)
This commit is contained in:
parent
26c0deaa09
commit
ae58f21218
|
@ -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
|
||||
|
|
|
@ -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<String> 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();
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:padding="16dp">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
app:cardCornerRadius="12dp"
|
||||
app:cardElevation="0dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:text="@string/notification_permission_text" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/denyButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/deny_label"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/openSettingsButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:text="@string/open_settings" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/allowButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@android:string/ok" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</LinearLayout>
|
|
@ -640,6 +640,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.POST_NOTIFICATIONS)
|
||||
== PackageManager.PERMISSION_GRANTED) {
|
||||
notificationManager.notify(R.id.notification_streaming_confirmation, builder.build());
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
R.string.confirm_mobile_streaming_notification_message, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.content.Intent;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
@ -122,6 +123,8 @@ public class AutomaticDatabaseExportWorker extends Worker {
|
|||
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.POST_NOTIFICATIONS)
|
||||
== PackageManager.PERMISSION_GRANTED) {
|
||||
nm.notify(R.id.notification_id_backup_error, notification);
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), description, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,11 +67,7 @@
|
|||
<string name="home_downloads_empty_text">You can download any episode to listen to it offline.</string>
|
||||
<string name="home_welcome_title">Welcome to AntennaPod!</string>
|
||||
<string name="home_welcome_text">You are not subscribed to any podcasts yet. Open the side menu to add a podcast.</string>
|
||||
<string name="notification_permission_text">AntennaPod needs your permission to show notifications. By default, AntennaPod only shows notifications while something is being downloaded or when something goes wrong.</string>
|
||||
<string name="notification_permission_denied">You denied the permission.</string>
|
||||
<string name="notification_permission_deny_warning">If you disable notifications and something goes wrong, you might be unable to find out why it went wrong.</string>
|
||||
<string name="deny_label">Deny</string>
|
||||
<string name="open_settings">Open settings</string>
|
||||
<string name="configure_home">Configure Home Screen</string>
|
||||
<string name="section_hidden">Hidden</string>
|
||||
<string name="section_shown">Shown</string>
|
||||
|
|
Loading…
Reference in New Issue