Skip to content

Commit c03f405

Browse files
authored
Merge pull request #12716 from Isaac-75/12194-notification-prompt-after-rotation
Notifications are no longer requested again after rotating the phone
2 parents 0a89276 + 88eb32b commit c03f405

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

app/src/main/java/org/schabi/newpipe/App.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,23 @@ public class App extends Application {
6565
private static final String TAG = App.class.toString();
6666

6767
private boolean isFirstRun = false;
68+
private boolean notificationsRequested = false;
69+
6870
private static App app;
6971

7072
@NonNull
7173
public static App getApp() {
7274
return app;
7375
}
7476

77+
public boolean getNotificationsRequested() {
78+
return notificationsRequested;
79+
}
80+
81+
public void setNotificationsRequested() {
82+
notificationsRequested = true;
83+
}
84+
7585
@Override
7686
protected void attachBaseContext(final Context base) {
7787
super.attachBaseContext(base);

app/src/main/java/org/schabi/newpipe/util/PermissionHelper.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import androidx.core.app.ActivityCompat;
1818
import androidx.core.content.ContextCompat;
1919

20+
import org.schabi.newpipe.App;
2021
import org.schabi.newpipe.R;
2122
import org.schabi.newpipe.settings.NewPipeSettings;
2223

@@ -89,9 +90,12 @@ public static boolean checkPostNotificationsPermission(final Activity activity,
8990
&& ContextCompat.checkSelfPermission(activity,
9091
Manifest.permission.POST_NOTIFICATIONS)
9192
!= PackageManager.PERMISSION_GRANTED) {
92-
ActivityCompat.requestPermissions(activity,
93-
new String[] {Manifest.permission.POST_NOTIFICATIONS}, requestCode);
94-
return false;
93+
if (!App.getApp().getNotificationsRequested()) {
94+
ActivityCompat.requestPermissions(activity,
95+
new String[]{Manifest.permission.POST_NOTIFICATIONS}, requestCode);
96+
App.getApp().setNotificationsRequested();
97+
return false;
98+
}
9599
}
96100
return true;
97101
}

0 commit comments

Comments
 (0)