Login stabilized
This commit is contained in:
@@ -227,19 +227,15 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
private void checkAndDoLogin() {
|
||||
changeFragment(FRAGMENT_STARTUP);
|
||||
this.getKVV().startUpdate();
|
||||
this.getGoogleAuth().connect(() -> getGoogleAuth().getLoginState(credentials -> {
|
||||
if (credentials == null || credentials.getUsername() == null || credentials.getPassword() == null) {
|
||||
this.getKVV().endUpdate();
|
||||
toLogoutState();
|
||||
return;
|
||||
}
|
||||
this.getKVV().login(credentials.getUsername(), credentials.getPassword(), success -> {
|
||||
this.getKVV().endUpdate();
|
||||
toLoginState(success, getDefaultFragmentAfterLogin(), "");
|
||||
}, error -> {
|
||||
log.e(error);
|
||||
this.getKVV().endUpdate();
|
||||
toLogoutState();
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.HashMap;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
|
||||
@@ -21,20 +20,19 @@ import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
public class KVV {
|
||||
private Context context;
|
||||
private LoginToken lastToken;
|
||||
private boolean isUpdating;
|
||||
private boolean isLoginPending = true;
|
||||
private ArrayList<LastTokenCallback> updatingList;
|
||||
private HashMap<String, Object> addons = new HashMap<>();
|
||||
private Logger log = new Logger(this);
|
||||
|
||||
public KVV(Context context) {
|
||||
this.context = context;
|
||||
this.isUpdating = false;
|
||||
this.updatingList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public LoginToken easyLogin() {
|
||||
KVVLogin login = new KVVLogin(this.context);
|
||||
lastToken = login.easyLogin();
|
||||
this.endUpdate();
|
||||
return lastToken;
|
||||
}
|
||||
|
||||
@@ -42,13 +40,17 @@ public class KVV {
|
||||
KVVLogin login = new KVVLogin(this.context);
|
||||
login.login(username, password, success -> {
|
||||
lastToken = success;
|
||||
this.endUpdate();
|
||||
try {
|
||||
login.saveOffline(this.context);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
callback.onResponse(success);
|
||||
}, error);
|
||||
}, error1 -> {
|
||||
this.endUpdate();
|
||||
error.onError(error1);
|
||||
});
|
||||
}
|
||||
|
||||
public void logout() {
|
||||
@@ -61,6 +63,7 @@ public class KVV {
|
||||
modules.deleteModulesOffline(this.context);
|
||||
}
|
||||
addons.clear();
|
||||
this.isLoginPending = true;
|
||||
}
|
||||
|
||||
public void getModule(String id, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error) {
|
||||
@@ -84,7 +87,6 @@ public class KVV {
|
||||
|
||||
public void getModuleList(final NetworkCallback<Modules> callback, final NetworkErrorCallback error, boolean forceRefresh) {
|
||||
this.getLastToken(token -> {
|
||||
log.d("token here", token);
|
||||
KVVModuleList modules = (KVVModuleList) addons.get("modules");
|
||||
if (modules == null) {
|
||||
modules = new KVVModuleList(KVV.this.context, token);
|
||||
@@ -164,19 +166,15 @@ public class KVV {
|
||||
}
|
||||
|
||||
private void getLastToken(LastTokenCallback lastTokenCallback) {
|
||||
if (this.isUpdating) {
|
||||
if (this.isLoginPending) {
|
||||
this.updatingList.add(lastTokenCallback);
|
||||
} else {
|
||||
lastTokenCallback.onReceived(this.lastToken);
|
||||
}
|
||||
}
|
||||
|
||||
public void startUpdate() {
|
||||
this.isUpdating = true;
|
||||
}
|
||||
|
||||
public void endUpdate() {
|
||||
this.isUpdating = false;
|
||||
private void endUpdate() {
|
||||
this.isLoginPending = false;
|
||||
for (LastTokenCallback s: this.updatingList) {
|
||||
s.onReceived(this.lastToken);
|
||||
}
|
||||
|
||||
@@ -212,7 +212,6 @@ public class KVVModuleList extends HTTPService {
|
||||
JSONArray sites = json.getJSONArray("announcement_collection");
|
||||
|
||||
for (int i = 0; i < sites.length(); i++) {
|
||||
//log.d("ANNOUNCEMENT FOUND!", i);
|
||||
JSONObject site = sites.getJSONObject(i);
|
||||
String id = site.getString("announcementId");
|
||||
String title = site.getString("title");
|
||||
@@ -266,7 +265,6 @@ public class KVVModuleList extends HTTPService {
|
||||
JSONArray sites = json.getJSONArray("assignment_collection");
|
||||
|
||||
for (int i = 0; i < sites.length(); i++) {
|
||||
//log.d("Assignment FOUND!", i);
|
||||
JSONObject site = sites.getJSONObject(i);
|
||||
String id = site.getString("id");
|
||||
String title = site.getString("title");
|
||||
@@ -282,11 +280,9 @@ public class KVVModuleList extends HTTPService {
|
||||
ArrayList<String> urls = new ArrayList<>();
|
||||
for (int j =0; j<attachments.length(); j++){
|
||||
urls.add(attachments.getJSONObject(j).optString("url",null));
|
||||
//log.d("URL:", attachments.getJSONObject(j).optString("url",null));
|
||||
}
|
||||
|
||||
|
||||
//log.d("Assignment:", id, dueTime, gradebookItemName, gradeScale);
|
||||
assignments.add(0, new Assignment(id, title, dueTime, gradebookItemName, gradeScale, urls, instructions));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
@@ -336,7 +332,6 @@ public class KVVModuleList extends HTTPService {
|
||||
JSONArray sites = json.getJSONArray("calendar_collection");
|
||||
|
||||
for (int i = 0; i < sites.length(); i++) {
|
||||
//log.d("CALENDAR ENTRY FOUND!", i);
|
||||
JSONObject site = sites.getJSONObject(i);
|
||||
String id = site.getString("eventId");
|
||||
String type = site.getString("type");
|
||||
|
||||
Reference in New Issue
Block a user