mirror of
https://github.com/CappielloAntonio/tempo.git
synced 2026-02-03 07:53:37 +00:00
Add dialog when server is unreachable
This commit is contained in:
@@ -3,6 +3,7 @@ package com.cappielloantonio.play.ui.activity;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -21,6 +22,8 @@ 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.ServerUnreachableDialog;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
import com.cappielloantonio.play.viewmodel.MainViewModel;
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
@@ -58,6 +61,12 @@ public class MainActivity extends BaseActivity {
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
pingServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
@@ -187,6 +196,8 @@ public class MainActivity extends BaseActivity {
|
||||
navController.navigate(R.id.action_landingFragment_to_loginFragment);
|
||||
} else if (Objects.requireNonNull(navController.getCurrentDestination()).getId() == R.id.settingsFragment) {
|
||||
navController.navigate(R.id.action_settingsFragment_to_loginFragment);
|
||||
} else if (Objects.requireNonNull(navController.getCurrentDestination()).getId() == R.id.homeFragment) {
|
||||
navController.navigate(R.id.action_homeFragment_to_loginFragment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,4 +246,15 @@ public class MainActivity extends BaseActivity {
|
||||
unregisterReceiver(connectivityStatusBroadcastReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
private void pingServer() {
|
||||
if (PreferenceUtil.getInstance(this).getToken() != null) {
|
||||
mainViewModel.ping().observe(this, isPingSuccessfull -> {
|
||||
if(!isPingSuccessfull) {
|
||||
ServerUnreachableDialog dialog = new ServerUnreachableDialog();
|
||||
dialog.show(getSupportFragmentManager(), null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user