diff --git a/.idea/misc.xml b/.idea/misc.xml
index d8107723..077fd1ec 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -44,6 +44,7 @@
+
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 ac0a1a31..eb0ae678 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
@@ -1,9 +1,9 @@
package com.cappielloantonio.play.ui.activity;
+import android.content.Context;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle;
-import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
@@ -22,7 +22,7 @@ import com.cappielloantonio.play.repository.QueueRepository;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.ui.activity.base.BaseActivity;
import com.cappielloantonio.play.ui.fragment.PlayerBottomSheetFragment;
-import com.cappielloantonio.play.ui.fragment.dialog.PlaylistEditorDialog;
+import com.cappielloantonio.play.ui.fragment.dialog.ConnectionAlertDialog;
import com.cappielloantonio.play.ui.fragment.dialog.ServerUnreachableDialog;
import com.cappielloantonio.play.util.PreferenceUtil;
import com.cappielloantonio.play.viewmodel.MainViewModel;
@@ -59,6 +59,7 @@ public class MainActivity extends BaseActivity {
connectivityStatusReceiverManager(true);
init();
+ checkConnectionType();
}
@Override
@@ -250,11 +251,21 @@ public class MainActivity extends BaseActivity {
private void pingServer() {
if (PreferenceUtil.getInstance(this).getToken() != null) {
mainViewModel.ping().observe(this, isPingSuccessfull -> {
- if(!isPingSuccessfull) {
+ if (!isPingSuccessfull) {
ServerUnreachableDialog dialog = new ServerUnreachableDialog();
dialog.show(getSupportFragmentManager(), null);
}
});
}
}
+
+ private void checkConnectionType() {
+ if (PreferenceUtil.getInstance(this).isWifiOnly()) {
+ ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (connectivityManager.getActiveNetworkInfo().getType() != ConnectivityManager.TYPE_WIFI) {
+ ConnectionAlertDialog dialog = new ConnectionAlertDialog();
+ dialog.show(getSupportFragmentManager(), null);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/dialog/ConnectionAlertDialog.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/dialog/ConnectionAlertDialog.java
new file mode 100644
index 00000000..45496caf
--- /dev/null
+++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/dialog/ConnectionAlertDialog.java
@@ -0,0 +1,61 @@
+package com.cappielloantonio.play.ui.fragment.dialog;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.DialogFragment;
+
+import com.cappielloantonio.play.R;
+import com.cappielloantonio.play.databinding.DialogConnectionAlertBinding;
+import com.cappielloantonio.play.util.PreferenceUtil;
+
+import java.util.Objects;
+
+public class ConnectionAlertDialog extends DialogFragment {
+ private static final String TAG = "ServerUnreachableDialog";
+
+ private DialogConnectionAlertBinding bind;
+
+ @NonNull
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ bind = DialogConnectionAlertBinding.inflate(LayoutInflater.from(requireContext()));
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_AlertDialog);
+
+ builder.setView(bind.getRoot())
+ .setTitle(R.string.connection_alert_dialog_title)
+ .setPositiveButton(R.string.connection_alert_dialog_positive_button, (dialog, id) -> dialog.cancel())
+ .setNeutralButton(R.string.connection_alert_dialog_neutral_button, (dialog, id) -> { })
+ .setNegativeButton(R.string.connection_alert_dialog_negative_button, (dialog, id) -> dialog.cancel());
+
+ return builder.create();
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ setButtonAction();
+ }
+
+ @Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ bind = null;
+ }
+
+ private void setButtonAction() {
+ ((AlertDialog) Objects.requireNonNull(getDialog())).getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(getResources().getColor(R.color.colorAccent, null));
+ ((AlertDialog) Objects.requireNonNull(getDialog())).getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.colorAccent, null));
+ ((AlertDialog) Objects.requireNonNull(getDialog())).getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.colorAccent, null));
+
+ ((AlertDialog) Objects.requireNonNull(getDialog())).getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(v -> {
+ PreferenceUtil.getInstance(requireContext()).setDataSavingMode(true);
+ Objects.requireNonNull(getDialog()).dismiss();
+ });
+ }
+}
diff --git a/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java b/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java
index 259aba8c..75f92c5f 100644
--- a/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java
+++ b/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java
@@ -162,4 +162,10 @@ public class PreferenceUtil {
public final boolean isDataSavingMode() {
return mPreferences.getBoolean(DATA_SAVING_MODE, false);
}
+
+ public void setDataSavingMode(Boolean isDataSavingModeEnabled) {
+ final SharedPreferences.Editor editor = mPreferences.edit();
+ editor.putBoolean(DATA_SAVING_MODE, isDataSavingModeEnabled);
+ editor.apply();
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_connection_alert.xml b/app/src/main/res/layout/dialog_connection_alert.xml
new file mode 100644
index 00000000..7645ba09
--- /dev/null
+++ b/app/src/main/res/layout/dialog_connection_alert.xml
@@ -0,0 +1,15 @@
+
+
+
+
\ 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 dfa61839..cd08a2b3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -184,4 +184,9 @@
Continue anyway
Server unreachable
The requested server is unavailable. Please contact your support and describe your issue.
+ Wi-Fi not connected
+ Continue anyway
+ Enable data saver
+ Cancel
+ Access to the Subsonic server on connections other than WiFi has been restricted. To prevent this alert dialod from reappearing, disable the connection check in the app settings.
\ No newline at end of file