|
20 | 20 |
|
21 | 21 | package org.schabi.newpipe; |
22 | 22 |
|
| 23 | +import android.app.AlertDialog; |
23 | 24 | import android.content.BroadcastReceiver; |
24 | 25 | import android.content.Context; |
25 | 26 | import android.content.Intent; |
26 | 27 | import android.content.IntentFilter; |
27 | 28 | import android.content.SharedPreferences; |
28 | 29 | import android.content.pm.PackageManager; |
| 30 | +import android.net.Uri; |
29 | 31 | import android.os.Bundle; |
30 | 32 | import android.os.Handler; |
31 | 33 | import android.os.Looper; |
|
96 | 98 | import org.schabi.newpipe.util.external_communication.ShareUtils; |
97 | 99 | import org.schabi.newpipe.views.FocusOverlayView; |
98 | 100 |
|
| 101 | +import java.time.Instant; |
| 102 | +import java.time.temporal.ChronoUnit; |
99 | 103 | import java.util.ArrayList; |
100 | 104 | import java.util.List; |
101 | 105 | import java.util.Objects; |
@@ -196,6 +200,8 @@ protected void onCreate(final Bundle savedInstanceState) { |
196 | 200 | UpdateSettingsFragment.askForConsentToUpdateChecks(this); |
197 | 201 | } |
198 | 202 |
|
| 203 | + showKeepAndroidDialog(); |
| 204 | + |
199 | 205 | MigrationManager.showUserInfoIfPresent(this); |
200 | 206 | } |
201 | 207 |
|
@@ -973,4 +979,44 @@ private boolean bottomSheetHiddenOrCollapsed() { |
973 | 979 | || sheetState == BottomSheetBehavior.STATE_COLLAPSED; |
974 | 980 | } |
975 | 981 |
|
| 982 | + private void showKeepAndroidDialog() { |
| 983 | + final var prefs = PreferenceManager.getDefaultSharedPreferences(this); |
| 984 | + |
| 985 | + final var now = Instant.now(); |
| 986 | + final var kaoLastCheck = Instant.ofEpochMilli(prefs.getLong( |
| 987 | + getString(R.string.kao_last_checked_key), |
| 988 | + 0 |
| 989 | + )); |
| 990 | + |
| 991 | + final var kaoURI = Uri.parse("https://keepandroidopen.org"); |
| 992 | + final var solutionURI = Uri.parse( |
| 993 | + "https://github.com/woheller69/FreeDroidWarn?tab=readme-ov-file#solutions"); |
| 994 | + |
| 995 | + if (kaoLastCheck.plus(30, ChronoUnit.DAYS).isBefore(now)) { |
| 996 | + final var dialog = new AlertDialog.Builder(this) |
| 997 | + .setTitle("Keep Android Open") |
| 998 | + .setCancelable(false) |
| 999 | + .setMessage(this.getString(R.string.kao_dialog_warning)) |
| 1000 | + .setPositiveButton(this.getString(android.R.string.ok), (d, w) -> { |
| 1001 | + prefs.edit() |
| 1002 | + .putLong( |
| 1003 | + getString(R.string.kao_last_checked_key), |
| 1004 | + now.toEpochMilli() |
| 1005 | + ) |
| 1006 | + .apply(); |
| 1007 | + }) |
| 1008 | + .setNeutralButton(this.getString(R.string.kao_solution), null) |
| 1009 | + .setNegativeButton(this.getString(R.string.kao_dialog_more_info), null) |
| 1010 | + .show(); |
| 1011 | + |
| 1012 | + // If we use setNeutralButton and etc. dialog will close after pressing the buttons |
| 1013 | + // but we want it to close only when positive button is pressed |
| 1014 | + dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(v -> |
| 1015 | + this.startActivity(new Intent(Intent.ACTION_VIEW, kaoURI)) |
| 1016 | + ); |
| 1017 | + dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(v -> |
| 1018 | + this.startActivity(new Intent(Intent.ACTION_VIEW, solutionURI)) |
| 1019 | + ); |
| 1020 | + } |
| 1021 | + } |
976 | 1022 | } |
0 commit comments