@@ -984,55 +984,48 @@ private boolean bottomSheetHiddenOrCollapsed() {
984984
985985 private void showKeepAndroidDialog () {
986986 final var prefs = PreferenceManager .getDefaultSharedPreferences (this );
987-
987+ final var lastCheckKey = getString (R .string .kao_last_checked_key );
988+ final var lastCheck = Instant .ofEpochMilli (prefs .getLong (lastCheckKey , 0 ));
988989 final var now = Instant .now ();
989- final var kaoLastCheck = Instant .ofEpochMilli (prefs .getLong (
990- getString (R .string .kao_last_checked_key ),
991- 0
992- ));
993990
994- final var supportedLannguages = List .of ("fr" , "de" , "ca" , "es" , "id" , "it" , "pl" ,
995- "pt" , "cs" , "sk" , "fa" , "ar" , "tr" , "el" , "th" , "ru" , "uk" , "ko" , "zh" , "ja" );
996- final var locale = Localization .getAppLocale ();
997- final String kaoBaseUrl = "https://keepandroidopen.org/" ;
998- final String kaoURI ;
999- if (supportedLannguages .contains (locale .getLanguage ())) {
1000- if ("zh" .equals (locale .getLanguage ())) {
1001- kaoURI = kaoBaseUrl + ("TW" .equals (locale .getCountry ()) ? "zh-TW" : "zh-CN" );
1002- } else {
1003- kaoURI = kaoBaseUrl + locale .getLanguage ();
1004- }
1005- } else {
1006- kaoURI = kaoBaseUrl ;
1007- }
1008- final var solutionURI =
1009- "https://github.com/woheller69/FreeDroidWarn?tab=readme-ov-file#solutions" ;
991+ if (lastCheck .plus (30 , ChronoUnit .DAYS ).isBefore (now )) {
992+ final String detailsUrl = getKeepAndroidOpenDetailsUrl ();
993+ final var solutionUrl = "https://github.com/woheller69/FreeDroidWarn#solutions" ;
1010994
1011- if (kaoLastCheck .plus (30 , ChronoUnit .DAYS ).isBefore (now )) {
1012995 final var dialog = new AlertDialog .Builder (this )
1013996 .setTitle ("Keep Android Open" )
1014997 .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 )
998+ .setMessage (R .string .kao_dialog_warning )
999+ .setPositiveButton (android .R .string .ok , (d , w ) -> prefs .edit ()
1000+ .putLong (lastCheckKey , now .toEpochMilli ())
1001+ .apply ())
1002+ .setNeutralButton (R .string .kao_solution , null )
1003+ .setNegativeButton (R .string .kao_dialog_more_info , null )
10261004 .show ();
10271005
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- );
1006+ // If we use setNeutralButton/setNegativeButton, dialog will close after pressing the
1007+ // buttons, but we want it to close only when positive button is pressed
1008+ dialog .getButton (AlertDialog .BUTTON_NEGATIVE )
1009+ .setOnClickListener (v -> ShareUtils .openUrlInBrowser (this , detailsUrl ));
1010+ dialog .getButton (AlertDialog .BUTTON_NEUTRAL )
1011+ .setOnClickListener (v -> ShareUtils .openUrlInBrowser (this , solutionUrl ));
1012+ }
1013+ }
1014+
1015+ @ NonNull
1016+ private static String getKeepAndroidOpenDetailsUrl () {
1017+ final var supportedLanguages = List .of ("fr" , "de" , "ca" , "es" , "id" , "it" , "pl" ,
1018+ "pt" , "cs" , "sk" , "fa" , "ar" , "tr" , "el" , "th" , "ru" , "uk" , "ko" , "zh" , "ja" );
1019+ final String kaoBaseUrl = "https://keepandroidopen.org/" ;
1020+ final var locale = Localization .getAppLocale ();
1021+ if (supportedLanguages .contains (locale .getLanguage ())) {
1022+ if ("zh" .equals (locale .getLanguage ())) {
1023+ return kaoBaseUrl + ("TW" .equals (locale .getCountry ()) ? "zh-TW" : "zh-CN" );
1024+ } else {
1025+ return kaoBaseUrl + locale .getLanguage ();
1026+ }
1027+ } else {
1028+ return kaoBaseUrl ;
10361029 }
10371030 }
10381031}
0 commit comments