mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
fix: Lag during startup when local url is not available (#110)
This commit is contained in:
commit
c2354d4d42
2 changed files with 22 additions and 1 deletions
|
|
@ -5,6 +5,9 @@ import android.util.Log;
|
||||||
import com.cappielloantonio.tempo.subsonic.RetrofitClient;
|
import com.cappielloantonio.tempo.subsonic.RetrofitClient;
|
||||||
import com.cappielloantonio.tempo.subsonic.Subsonic;
|
import com.cappielloantonio.tempo.subsonic.Subsonic;
|
||||||
import com.cappielloantonio.tempo.subsonic.base.ApiResponse;
|
import com.cappielloantonio.tempo.subsonic.base.ApiResponse;
|
||||||
|
import com.cappielloantonio.tempo.util.Preferences;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
|
|
||||||
|
|
@ -21,7 +24,15 @@ public class SystemClient {
|
||||||
|
|
||||||
public Call<ApiResponse> ping() {
|
public Call<ApiResponse> ping() {
|
||||||
Log.d(TAG, "ping()");
|
Log.d(TAG, "ping()");
|
||||||
return systemService.ping(subsonic.getParams());
|
Call<ApiResponse> pingCall = systemService.ping(subsonic.getParams());
|
||||||
|
if (Preferences.isInUseServerAddressLocal()) {
|
||||||
|
pingCall.timeout()
|
||||||
|
.timeout(1, TimeUnit.SECONDS);
|
||||||
|
} else {
|
||||||
|
pingCall.timeout()
|
||||||
|
.timeout(3, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return pingCall;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Call<ApiResponse> getLicense() {
|
public Call<ApiResponse> getLicense() {
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ public class MainActivity extends BaseActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
pingServer();
|
||||||
initService();
|
initService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -351,6 +352,7 @@ public class MainActivity extends BaseActivity {
|
||||||
Preferences.switchInUseServerAddress();
|
Preferences.switchInUseServerAddress();
|
||||||
App.refreshSubsonicClient();
|
App.refreshSubsonicClient();
|
||||||
pingServer();
|
pingServer();
|
||||||
|
resetView();
|
||||||
} else {
|
} else {
|
||||||
Preferences.setOpenSubsonic(subsonicResponse.getOpenSubsonic() != null && subsonicResponse.getOpenSubsonic());
|
Preferences.setOpenSubsonic(subsonicResponse.getOpenSubsonic() != null && subsonicResponse.getOpenSubsonic());
|
||||||
}
|
}
|
||||||
|
|
@ -361,6 +363,7 @@ public class MainActivity extends BaseActivity {
|
||||||
Preferences.switchInUseServerAddress();
|
Preferences.switchInUseServerAddress();
|
||||||
App.refreshSubsonicClient();
|
App.refreshSubsonicClient();
|
||||||
pingServer();
|
pingServer();
|
||||||
|
resetView();
|
||||||
} else {
|
} else {
|
||||||
mainViewModel.ping().observe(this, subsonicResponse -> {
|
mainViewModel.ping().observe(this, subsonicResponse -> {
|
||||||
if (subsonicResponse == null) {
|
if (subsonicResponse == null) {
|
||||||
|
|
@ -376,6 +379,13 @@ public class MainActivity extends BaseActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resetView() {
|
||||||
|
resetViewModel();
|
||||||
|
int id = Objects.requireNonNull(navController.getCurrentDestination()).getId();
|
||||||
|
navController.popBackStack(id, true);
|
||||||
|
navController.navigate(id);
|
||||||
|
}
|
||||||
|
|
||||||
private void getOpenSubsonicExtensions() {
|
private void getOpenSubsonicExtensions() {
|
||||||
if (Preferences.getToken() != null) {
|
if (Preferences.getToken() != null) {
|
||||||
mainViewModel.getOpenSubsonicExtensions().observe(this, openSubsonicExtensions -> {
|
mainViewModel.getOpenSubsonicExtensions().observe(this, openSubsonicExtensions -> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue