Better offline access with bad network connection
This commit is contained in:
@@ -49,12 +49,11 @@ public class CanteenBrowser extends HTTPService {
|
||||
}
|
||||
|
||||
public void getCanteens(final NetworkCallback<Canteens> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
||||
queue.add("list", () -> {
|
||||
if (this.canteens != null && !forceRefresh) {
|
||||
callback.onResponse(this.canteens);
|
||||
queue.next("list");
|
||||
return;
|
||||
}
|
||||
queue.add("list", () -> {
|
||||
this.upgradeCanteens(success -> {
|
||||
if (this.canteens == null)
|
||||
this.canteens = success;
|
||||
@@ -111,12 +110,11 @@ public class CanteenBrowser extends HTTPService {
|
||||
}
|
||||
|
||||
public void getAvailableCanteens(final NetworkCallback<Canteens> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
||||
queue.add("available", () -> {
|
||||
if (this.availableCanteens != null && !forceRefresh) {
|
||||
callback.onResponse(this.availableCanteens);
|
||||
queue.next("available");
|
||||
return;
|
||||
}
|
||||
queue.add("available", () -> {
|
||||
this.upgradeAvailableCanteens(success -> {
|
||||
if (this.availableCanteens == null)
|
||||
this.availableCanteens = success;
|
||||
@@ -186,12 +184,11 @@ public class CanteenBrowser extends HTTPService {
|
||||
|
||||
public void getCanteen(Canteen canteen, final NetworkCallback<Canteen> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
||||
String hash = "canteen" + canteen.getId();
|
||||
queue.add(hash, () -> {
|
||||
if (canteen.size() > 0 && !forceRefresh) {
|
||||
callback.onResponse(canteen);
|
||||
queue.next(hash);
|
||||
return;
|
||||
}
|
||||
queue.add(hash, () -> {
|
||||
this.upgradeCanteen(canteen, success -> {
|
||||
canteen.update(success);
|
||||
this.save();
|
||||
@@ -233,12 +230,11 @@ public class CanteenBrowser extends HTTPService {
|
||||
|
||||
public void getDay(Day day, final NetworkCallback<Day> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
||||
String hash = "day" + day.getCanteenId() + "@@@" + Canteen.calendarToKey(day.getCalendar());
|
||||
queue.add(hash, () -> {
|
||||
if (day.size() > 0 && !forceRefresh) {
|
||||
callback.onResponse(day);
|
||||
queue.next(hash);
|
||||
return;
|
||||
}
|
||||
queue.add(hash, () -> {
|
||||
this.upgradeDay(day, success -> {
|
||||
day.update(success);
|
||||
this.save();
|
||||
|
||||
@@ -131,6 +131,10 @@ public class ModulesList extends HTTPService {
|
||||
mLogin.getLoginTokenBB() != null && mLogin.getLoginTokenBB().isOtherUser(mModules.getUsername())
|
||||
)
|
||||
delete();
|
||||
if (this.mModules != null && !forceRefresh) {
|
||||
callback.onResponse(this.mModules);
|
||||
return;
|
||||
}
|
||||
mQueue.add(() -> {
|
||||
if (mLogin.isLoginPending()) {
|
||||
mLogin.restoreOnlineLogin(resCode -> {
|
||||
@@ -141,11 +145,6 @@ public class ModulesList extends HTTPService {
|
||||
}
|
||||
});
|
||||
mQueue.add(() -> {
|
||||
if (this.mModules != null && !forceRefresh) {
|
||||
callback.onResponse(this.mModules);
|
||||
mQueue.next();
|
||||
return;
|
||||
}
|
||||
Function<Integer, NetworkErrorCallback> errorFunc = ((Integer errorCode) -> (error -> {
|
||||
if (retries > 0 && (error.getHttpStatus() == 401 || error.getHttpStatus() == 403)) {
|
||||
mLogin.refreshLogin(success -> {
|
||||
|
||||
@@ -19,6 +19,10 @@ abstract class PartModules<T> extends Part<Modules.Module> {
|
||||
|
||||
@Override
|
||||
protected void recv(final Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, final boolean forceRefresh, final int retries) {
|
||||
if (getPart(module) != null && !forceRefresh) {
|
||||
callback.onResponse(module);
|
||||
return;
|
||||
}
|
||||
mQueue.add(() -> {
|
||||
if (mLogin.isLoginPending()) {
|
||||
mLogin.restoreOnlineLogin(resCode -> {
|
||||
@@ -29,11 +33,6 @@ abstract class PartModules<T> extends Part<Modules.Module> {
|
||||
}
|
||||
});
|
||||
mQueue.add(() -> {
|
||||
if (getPart(module) != null && !forceRefresh) {
|
||||
callback.onResponse(module);
|
||||
mQueue.next();
|
||||
return;
|
||||
}
|
||||
upgrade(module.getModuleType(), module.getID(), success -> {
|
||||
if (setPart(module, success)) {
|
||||
this.mList.store();
|
||||
|
||||
Reference in New Issue
Block a user