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