diff --git a/app/src/main/java/com/cappielloantonio/play/ui/activity/MainActivity.java b/app/src/main/java/com/cappielloantonio/play/ui/activity/MainActivity.java index c9583e97..cee1d4ad 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/activity/MainActivity.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/activity/MainActivity.java @@ -292,7 +292,7 @@ public class MainActivity extends BaseActivity { private void pingServer() { if (Preferences.getToken() != null) { mainViewModel.ping().observe(this, isPingSuccessfull -> { - if (!isPingSuccessfull) { + if (!isPingSuccessfull && Preferences.showServerUnreachableDialog()) { ServerUnreachableDialog dialog = new ServerUnreachableDialog(); dialog.show(getSupportFragmentManager(), null); } diff --git a/app/src/main/java/com/cappielloantonio/play/ui/dialog/ServerUnreachableDialog.java b/app/src/main/java/com/cappielloantonio/play/ui/dialog/ServerUnreachableDialog.java index a8ac3c63..b668b8cd 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/dialog/ServerUnreachableDialog.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/dialog/ServerUnreachableDialog.java @@ -11,6 +11,7 @@ import androidx.fragment.app.DialogFragment; import com.cappielloantonio.play.R; import com.cappielloantonio.play.databinding.DialogServerUnreachableBinding; import com.cappielloantonio.play.ui.activity.MainActivity; +import com.cappielloantonio.play.util.Preferences; import java.util.Objects; @@ -28,8 +29,8 @@ public class ServerUnreachableDialog extends DialogFragment { builder.setView(bind.getRoot()) .setTitle(R.string.server_unreachable_dialog_title) - .setPositiveButton(R.string.server_unreachable_dialog_positive_button, (dialog, id) -> dialog.cancel()) - .setNeutralButton(R.string.server_unreachable_dialog_neutral_button, (dialog, id) -> { }) + .setPositiveButton(R.string.server_unreachable_dialog_positive_button, null) + .setNeutralButton(R.string.server_unreachable_dialog_neutral_button, null) .setNegativeButton(R.string.server_unreachable_dialog_negative_button, (dialog, id) -> dialog.cancel()); AlertDialog popup = builder.create(); @@ -54,14 +55,19 @@ public class ServerUnreachableDialog extends DialogFragment { } private void setButtonAction() { - ((AlertDialog) Objects.requireNonNull(getDialog())).getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(v -> { - MainActivity activity = (MainActivity) getActivity(); + AlertDialog dialog = (AlertDialog) getDialog(); - if (activity != null) { - activity.quit(); - } + if(dialog != null) { + (dialog).getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(v -> { + MainActivity activity = (MainActivity) getActivity(); + if (activity != null) activity.quit(); + dialog.dismiss(); + }); - Objects.requireNonNull(getDialog()).dismiss(); - }); + (dialog).getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> { + Preferences.setServerUnreachableDatetime(System.currentTimeMillis()); + dialog.dismiss(); + }); + } } } diff --git a/app/src/main/java/com/cappielloantonio/play/util/Preferences.kt b/app/src/main/java/com/cappielloantonio/play/util/Preferences.kt index 95ed7349..6380b86d 100644 --- a/app/src/main/java/com/cappielloantonio/play/util/Preferences.kt +++ b/app/src/main/java/com/cappielloantonio/play/util/Preferences.kt @@ -23,6 +23,7 @@ object Preferences { private const val AUDIO_TRANSCODE_FORMAT_MOBILE = "audio_transcode_format_mobile" private const val WIFI_ONLY = "wifi_only" private const val DATA_SAVING_MODE = "data_saving_mode" + private const val SERVER_UNREACHABLE = "server_unreachable" private const val SYNC_STARRED_TRACKS_FOR_OFFLINE_USE = "sync_starred_tracks_for_offline_use" @JvmStatic @@ -186,4 +187,15 @@ object Preferences { SYNC_STARRED_TRACKS_FOR_OFFLINE_USE, isStarredSyncEnabled ).apply() } + + @JvmStatic + fun showServerUnreachableDialog(): Boolean { + return App.getInstance().preferences.getLong(SERVER_UNREACHABLE, 0) + 360000 < System.currentTimeMillis() + } + + @JvmStatic + fun setServerUnreachableDatetime(datetime: Long) { + App.getInstance().preferences.edit() + .putLong(SERVER_UNREACHABLE, datetime).apply() + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 671c3cec..e8969263 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -134,7 +134,7 @@ Go to login Continue anyway Server unreachable - The requested server is unavailable. Please contact your support and describe your issue. + The requested server is unavailable. If you choose to continue this dialog will not appear for the next hour. Play is an open source and lightweight music client for Subsonic, designed and built natively for Android. About Transcode format in mobile