fix: Lag during startup when local url is not available (#110)

This commit is contained in:
eddyizm 2025-10-02 07:10:32 -07:00 committed by GitHub
commit c2354d4d42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View file

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

View file

@ -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 -> {