If the user decides to remain in the system even if the server is not reachable, the dialog will not appear for a fixed period of time

This commit is contained in:
antonio 2023-03-13 10:55:50 +01:00
parent 301142b2c6
commit 281e1ba3ee
4 changed files with 29 additions and 11 deletions

View file

@ -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);
}

View file

@ -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();
});
}
}
}

View file

@ -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()
}
}

View file

@ -134,7 +134,7 @@
<string name="server_unreachable_dialog_neutral_button">Go to login</string>
<string name="server_unreachable_dialog_positive_button">Continue anyway</string>
<string name="server_unreachable_dialog_title">Server unreachable</string>
<string name="server_unreachable_dialog_summary">The requested server is unavailable. Please contact your support and describe your issue.</string>
<string name="server_unreachable_dialog_summary">The requested server is unavailable. If you choose to continue this dialog will not appear for the next hour.</string>
<string name="settings_about_summary">Play is an open source and lightweight music client for Subsonic, designed and built natively for Android.</string>
<string name="settings_about_title">About</string>
<string name="settings_audio_transcode_format_mobile">Transcode format in mobile</string>