mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Implemented the alert dialog for checking the type of internet connection
This commit is contained in:
parent
5fc09cfcf8
commit
77c45e2fec
6 changed files with 102 additions and 3 deletions
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
|
|
@ -44,6 +44,7 @@
|
||||||
<entry key="app/src/main/res/layout/bottom_sheet_artist_dialog.xml" value="0.225" />
|
<entry key="app/src/main/res/layout/bottom_sheet_artist_dialog.xml" value="0.225" />
|
||||||
<entry key="app/src/main/res/layout/bottom_sheet_song_dialog.xml" value="0.21666666666666667" />
|
<entry key="app/src/main/res/layout/bottom_sheet_song_dialog.xml" value="0.21666666666666667" />
|
||||||
<entry key="app/src/main/res/layout/chip_search_filter_genre.xml" value="0.3229166666666667" />
|
<entry key="app/src/main/res/layout/chip_search_filter_genre.xml" value="0.3229166666666667" />
|
||||||
|
<entry key="app/src/main/res/layout/dialog_connection_alert.xml" value="0.528125" />
|
||||||
<entry key="app/src/main/res/layout/dialog_playlist_chooser.xml" value="0.3229166666666667" />
|
<entry key="app/src/main/res/layout/dialog_playlist_chooser.xml" value="0.3229166666666667" />
|
||||||
<entry key="app/src/main/res/layout/dialog_playlist_creator.xml" value="0.3229166666666667" />
|
<entry key="app/src/main/res/layout/dialog_playlist_creator.xml" value="0.3229166666666667" />
|
||||||
<entry key="app/src/main/res/layout/dialog_playlist_editor.xml" value="0.3229166666666667" />
|
<entry key="app/src/main/res/layout/dialog_playlist_editor.xml" value="0.3229166666666667" />
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package com.cappielloantonio.play.ui.activity;
|
package com.cappielloantonio.play.ui.activity;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
@ -22,7 +22,7 @@ import com.cappielloantonio.play.repository.QueueRepository;
|
||||||
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
||||||
import com.cappielloantonio.play.ui.activity.base.BaseActivity;
|
import com.cappielloantonio.play.ui.activity.base.BaseActivity;
|
||||||
import com.cappielloantonio.play.ui.fragment.PlayerBottomSheetFragment;
|
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.ui.fragment.dialog.ServerUnreachableDialog;
|
||||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||||
import com.cappielloantonio.play.viewmodel.MainViewModel;
|
import com.cappielloantonio.play.viewmodel.MainViewModel;
|
||||||
|
|
@ -59,6 +59,7 @@ public class MainActivity extends BaseActivity {
|
||||||
connectivityStatusReceiverManager(true);
|
connectivityStatusReceiverManager(true);
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
checkConnectionType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -250,11 +251,21 @@ public class MainActivity extends BaseActivity {
|
||||||
private void pingServer() {
|
private void pingServer() {
|
||||||
if (PreferenceUtil.getInstance(this).getToken() != null) {
|
if (PreferenceUtil.getInstance(this).getToken() != null) {
|
||||||
mainViewModel.ping().observe(this, isPingSuccessfull -> {
|
mainViewModel.ping().observe(this, isPingSuccessfull -> {
|
||||||
if(!isPingSuccessfull) {
|
if (!isPingSuccessfull) {
|
||||||
ServerUnreachableDialog dialog = new ServerUnreachableDialog();
|
ServerUnreachableDialog dialog = new ServerUnreachableDialog();
|
||||||
dialog.show(getSupportFragmentManager(), null);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -162,4 +162,10 @@ public class PreferenceUtil {
|
||||||
public final boolean isDataSavingMode() {
|
public final boolean isDataSavingMode() {
|
||||||
return mPreferences.getBoolean(DATA_SAVING_MODE, false);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
15
app/src/main/res/layout/dialog_connection_alert.xml
Normal file
15
app/src/main/res/layout/dialog_connection_alert.xml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:layout_marginBottom="4dp"
|
||||||
|
android:layout_marginEnd="24dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/connection_alert_dialog_summary" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -184,4 +184,9 @@
|
||||||
<string name="server_unreachable_dialog_positive_button">Continue anyway</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_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. Please contact your support and describe your issue.</string>
|
||||||
|
<string name="connection_alert_dialog_title">Wi-Fi not connected</string>
|
||||||
|
<string name="connection_alert_dialog_positive_button">Continue anyway</string>
|
||||||
|
<string name="connection_alert_dialog_neutral_button">Enable data saver</string>
|
||||||
|
<string name="connection_alert_dialog_negative_button">Cancel</string>
|
||||||
|
<string name="connection_alert_dialog_summary">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.</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue