Fix network error on first startup

This commit is contained in:
Phillip Thelen 2016-06-17 12:44:06 +02:00
parent af2be913c4
commit 3bca8be3f4
2 changed files with 7 additions and 2 deletions

View file

@ -342,6 +342,10 @@ public class APIHelper implements Action1<Throwable> {
return taskList;
}
public boolean hasAuthenticationKeys() {
return this.hostConfig.getUser() != null;
}
public class ErrorResponse{
public String message;
}

View file

@ -192,8 +192,9 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!HabiticaApplication.checkUserAuthentication(this, hostConfig))
if (!HabiticaApplication.checkUserAuthentication(this, hostConfig)) {
return;
}
//Check if reminder alarm is set
scheduleReminder(this);
@ -232,7 +233,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
//resync, if last sync was more than 10 minutes ago
if (this.lastSync == null || (new Date().getTime() - this.lastSync.getTime()) > 180000) {
if (this.apiHelper != null) {
if (this.apiHelper != null && this.apiHelper.hasAuthenticationKeys()) {
this.apiHelper.retrieveUser(true)
.compose(apiHelper.configureApiCallObserver())
.subscribe(new HabitRPGUserCallback(this), throwable -> {});