Skip to content

Commit 6e3b858

Browse files
authored
Merge pull request #13458 from Stypox/minsdk-23-popup
2 parents 1ce1dbe + 6d52522 commit 6e3b858

3 files changed

Lines changed: 65 additions & 38 deletions

File tree

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

Lines changed: 61 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.content.IntentFilter;
2828
import android.content.SharedPreferences;
2929
import android.content.pm.PackageManager;
30+
import android.os.Build;
3031
import android.os.Bundle;
3132
import android.os.Handler;
3233
import android.os.Looper;
@@ -203,6 +204,7 @@ protected void onCreate(final Bundle savedInstanceState) {
203204
// We want every release build (nightly, nightly-refactor) to show the popup
204205
if (!DEBUG) {
205206
showKeepAndroidDialog();
207+
showApi23RequirementDialog();
206208
}
207209

208210
MigrationManager.showUserInfoIfPresent(this);
@@ -984,55 +986,76 @@ private boolean bottomSheetHiddenOrCollapsed() {
984986

985987
private void showKeepAndroidDialog() {
986988
final var prefs = PreferenceManager.getDefaultSharedPreferences(this);
987-
989+
final var lastCheckKey = getString(R.string.kao_last_checked_key);
990+
final var lastCheck = Instant.ofEpochMilli(prefs.getLong(lastCheckKey, 0));
988991
final var now = Instant.now();
989-
final var kaoLastCheck = Instant.ofEpochMilli(prefs.getLong(
990-
getString(R.string.kao_last_checked_key),
991-
0
992-
));
993992

994-
final var supportedLannguages = List.of("fr", "de", "ca", "es", "id", "it", "pl",
993+
if (lastCheck.plus(30, ChronoUnit.DAYS).isBefore(now)) {
994+
final String detailsUrl = getKeepAndroidOpenDetailsUrl();
995+
final var solutionUrl = "https://github.com/woheller69/FreeDroidWarn#solutions";
996+
997+
final var dialog = new AlertDialog.Builder(this)
998+
.setTitle("Keep Android Open")
999+
.setCancelable(false)
1000+
.setMessage(R.string.kao_dialog_warning)
1001+
.setPositiveButton(android.R.string.ok, (d, w) -> prefs.edit()
1002+
.putLong(lastCheckKey, now.toEpochMilli())
1003+
.apply())
1004+
.setNeutralButton(R.string.kao_solution, null)
1005+
.setNegativeButton(R.string.kao_dialog_more_info, null)
1006+
.show();
1007+
1008+
// If we use setNeutralButton/setNegativeButton, dialog will close after pressing the
1009+
// buttons, but we want it to close only when positive button is pressed
1010+
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
1011+
.setOnClickListener(v -> ShareUtils.openUrlInBrowser(this, detailsUrl));
1012+
dialog.getButton(AlertDialog.BUTTON_NEUTRAL)
1013+
.setOnClickListener(v -> ShareUtils.openUrlInBrowser(this, solutionUrl));
1014+
}
1015+
}
1016+
1017+
@NonNull
1018+
private static String getKeepAndroidOpenDetailsUrl() {
1019+
final var supportedLanguages = List.of("fr", "de", "ca", "es", "id", "it", "pl",
9951020
"pt", "cs", "sk", "fa", "ar", "tr", "el", "th", "ru", "uk", "ko", "zh", "ja");
996-
final var locale = Localization.getAppLocale();
9971021
final String kaoBaseUrl = "https://keepandroidopen.org/";
998-
final String kaoURI;
999-
if (supportedLannguages.contains(locale.getLanguage())) {
1022+
final var locale = Localization.getAppLocale();
1023+
if (supportedLanguages.contains(locale.getLanguage())) {
10001024
if ("zh".equals(locale.getLanguage())) {
1001-
kaoURI = kaoBaseUrl + ("TW".equals(locale.getCountry()) ? "zh-TW" : "zh-CN");
1025+
return kaoBaseUrl + ("TW".equals(locale.getCountry()) ? "zh-TW" : "zh-CN");
10021026
} else {
1003-
kaoURI = kaoBaseUrl + locale.getLanguage();
1027+
return kaoBaseUrl + locale.getLanguage();
10041028
}
10051029
} else {
1006-
kaoURI = kaoBaseUrl;
1030+
return kaoBaseUrl;
10071031
}
1008-
final var solutionURI =
1009-
"https://github.com/woheller69/FreeDroidWarn?tab=readme-ov-file#solutions";
1032+
}
10101033

1011-
if (kaoLastCheck.plus(30, ChronoUnit.DAYS).isBefore(now)) {
1012-
final var dialog = new AlertDialog.Builder(this)
1013-
.setTitle("Keep Android Open")
1014-
.setCancelable(false)
1015-
.setMessage(this.getString(R.string.kao_dialog_warning))
1016-
.setPositiveButton(this.getString(android.R.string.ok), (d, w) -> {
1017-
prefs.edit()
1018-
.putLong(
1019-
getString(R.string.kao_last_checked_key),
1020-
now.toEpochMilli()
1021-
)
1022-
.apply();
1023-
})
1024-
.setNeutralButton(this.getString(R.string.kao_solution), null)
1025-
.setNegativeButton(this.getString(R.string.kao_dialog_more_info), null)
1026-
.show();
1034+
private void showApi23RequirementDialog() {
1035+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
1036+
return; // only show dialog on the devices that will stop being supported
1037+
}
10271038

1028-
// If we use setNeutralButton and etc. dialog will close after pressing the buttons,
1029-
// but we want it to close only when positive button is pressed
1030-
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(v ->
1031-
ShareUtils.openUrlInBrowser(this, kaoURI)
1032-
);
1033-
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(v ->
1034-
ShareUtils.openUrlInBrowser(this, solutionURI)
1035-
);
1039+
final var prefs = PreferenceManager.getDefaultSharedPreferences(this);
1040+
final var shownKey = getString(R.string.api23_requirement_dialog_shown_key);
1041+
if (prefs.getBoolean(shownKey, false)) {
1042+
return; // dialog was already shown in the past, no need to show it again
10361043
}
1044+
1045+
final var dialog = new AlertDialog.Builder(this)
1046+
.setTitle(R.string.api23_requirement_dialog_title)
1047+
.setCancelable(false)
1048+
.setMessage(R.string.api23_requirement_dialog_message)
1049+
.setPositiveButton(android.R.string.ok, (d, w) -> prefs.edit()
1050+
.putBoolean(shownKey, true)
1051+
.apply())
1052+
.setNegativeButton(R.string.api23_requirement_dialog_blogpost, null)
1053+
.show();
1054+
1055+
// If we use setNegativeButton, dialog will close after pressing the button,
1056+
// but we want it to close only when positive button is pressed
1057+
final var blogpostUrl = "https://newpipe.net/blog/pinned/announcement/drop-android-5/";
1058+
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
1059+
.setOnClickListener(v -> ShareUtils.openUrlInBrowser(this, blogpostUrl));
10371060
}
10381061
}

app/src/main/res/values/settings_keys.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<!-- Key values -->
1313
<string name="kao_last_checked_key">kao_last_checked</string>
14+
<string name="api23_requirement_dialog_shown_key">api23_requirement_dialog_shown</string>
1415

1516
<string name="download_path_video_key">download_path</string>
1617
<string name="download_path_audio_key">download_path_audio</string>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,4 +900,7 @@
900900
<string name="kao_dialog_warning">In August 2025, Google announced that as of September 2026, installing apps will require developer verification for all Android apps on certified devices, including those installed outside of the Play Store. Since the developers of NewPipe do not agree to this requirement, NewPipe will no longer work on certified Android devices after that time.</string>
901901
<string name="kao_dialog_more_info">Details</string>
902902
<string name="kao_solution">Solution</string>
903+
<string name="api23_requirement_dialog_title">NewPipe is dropping support for Android 5</string>
904+
<string name="api23_requirement_dialog_message">Unfortunately NewPipe depends on a few libraries that dropped support for Android 5.0 and 5.1. The next NewPipe release will therefore only work on devices with Android 6 or higher, sadly. Read more in the blogpost.</string>
905+
<string name="api23_requirement_dialog_blogpost">Blogpost</string>
903906
</resources>

0 commit comments

Comments
 (0)