Skip to content

Commit c4e6e4d

Browse files
committed
Notifications are no longer requested again after rotating the phone
1 parent 09e4bea commit c4e6e4d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,21 @@ public class App extends Application {
6666

6767
private boolean isFirstRun = false;
6868
private static App app;
69+
private boolean notificationsRequested = false;
6970

7071
@NonNull
7172
public static App getApp() {
7273
return app;
7374
}
7475

76+
public boolean getNotificationsRequested() {
77+
return notificationsRequested;
78+
}
79+
80+
public void setNotificationsRequested() {
81+
notificationsRequested = true;
82+
}
83+
7584
@Override
7685
protected void attachBaseContext(final Context base) {
7786
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)