mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-05-18 03:12:11 +00:00
Cleanup KeepAndroidOpen dialog code
This commit is contained in:
@@ -984,55 +984,48 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private void showKeepAndroidDialog() {
|
||||
final var prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
final var lastCheckKey = getString(R.string.kao_last_checked_key);
|
||||
final var lastCheck = Instant.ofEpochMilli(prefs.getLong(lastCheckKey, 0));
|
||||
final var now = Instant.now();
|
||||
final var kaoLastCheck = Instant.ofEpochMilli(prefs.getLong(
|
||||
getString(R.string.kao_last_checked_key),
|
||||
0
|
||||
));
|
||||
|
||||
final var supportedLannguages = List.of("fr", "de", "ca", "es", "id", "it", "pl",
|
||||
"pt", "cs", "sk", "fa", "ar", "tr", "el", "th", "ru", "uk", "ko", "zh", "ja");
|
||||
final var locale = Localization.getAppLocale();
|
||||
final String kaoBaseUrl = "https://keepandroidopen.org/";
|
||||
final String kaoURI;
|
||||
if (supportedLannguages.contains(locale.getLanguage())) {
|
||||
if ("zh".equals(locale.getLanguage())) {
|
||||
kaoURI = kaoBaseUrl + ("TW".equals(locale.getCountry()) ? "zh-TW" : "zh-CN");
|
||||
} else {
|
||||
kaoURI = kaoBaseUrl + locale.getLanguage();
|
||||
}
|
||||
} else {
|
||||
kaoURI = kaoBaseUrl;
|
||||
}
|
||||
final var solutionURI =
|
||||
"https://github.com/woheller69/FreeDroidWarn?tab=readme-ov-file#solutions";
|
||||
if (lastCheck.plus(30, ChronoUnit.DAYS).isBefore(now)) {
|
||||
final String detailsUrl = getKeepAndroidOpenDetailsUrl();
|
||||
final var solutionUrl = "https://github.com/woheller69/FreeDroidWarn#solutions";
|
||||
|
||||
if (kaoLastCheck.plus(30, ChronoUnit.DAYS).isBefore(now)) {
|
||||
final var dialog = new AlertDialog.Builder(this)
|
||||
.setTitle("Keep Android Open")
|
||||
.setCancelable(false)
|
||||
.setMessage(this.getString(R.string.kao_dialog_warning))
|
||||
.setPositiveButton(this.getString(android.R.string.ok), (d, w) -> {
|
||||
prefs.edit()
|
||||
.putLong(
|
||||
getString(R.string.kao_last_checked_key),
|
||||
now.toEpochMilli()
|
||||
)
|
||||
.apply();
|
||||
})
|
||||
.setNeutralButton(this.getString(R.string.kao_solution), null)
|
||||
.setNegativeButton(this.getString(R.string.kao_dialog_more_info), null)
|
||||
.setMessage(R.string.kao_dialog_warning)
|
||||
.setPositiveButton(android.R.string.ok, (d, w) -> prefs.edit()
|
||||
.putLong(lastCheckKey, now.toEpochMilli())
|
||||
.apply())
|
||||
.setNeutralButton(R.string.kao_solution, null)
|
||||
.setNegativeButton(R.string.kao_dialog_more_info, null)
|
||||
.show();
|
||||
|
||||
// If we use setNeutralButton and etc. dialog will close after pressing the buttons,
|
||||
// but we want it to close only when positive button is pressed
|
||||
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(v ->
|
||||
ShareUtils.openUrlInBrowser(this, kaoURI)
|
||||
);
|
||||
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(v ->
|
||||
ShareUtils.openUrlInBrowser(this, solutionURI)
|
||||
);
|
||||
// If we use setNeutralButton/setNegativeButton, dialog will close after pressing the
|
||||
// buttons, but we want it to close only when positive button is pressed
|
||||
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
|
||||
.setOnClickListener(v -> ShareUtils.openUrlInBrowser(this, detailsUrl));
|
||||
dialog.getButton(AlertDialog.BUTTON_NEUTRAL)
|
||||
.setOnClickListener(v -> ShareUtils.openUrlInBrowser(this, solutionUrl));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static String getKeepAndroidOpenDetailsUrl() {
|
||||
final var supportedLanguages = List.of("fr", "de", "ca", "es", "id", "it", "pl",
|
||||
"pt", "cs", "sk", "fa", "ar", "tr", "el", "th", "ru", "uk", "ko", "zh", "ja");
|
||||
final String kaoBaseUrl = "https://keepandroidopen.org/";
|
||||
final var locale = Localization.getAppLocale();
|
||||
if (supportedLanguages.contains(locale.getLanguage())) {
|
||||
if ("zh".equals(locale.getLanguage())) {
|
||||
return kaoBaseUrl + ("TW".equals(locale.getCountry()) ? "zh-TW" : "zh-CN");
|
||||
} else {
|
||||
return kaoBaseUrl + locale.getLanguage();
|
||||
}
|
||||
} else {
|
||||
return kaoBaseUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user