60 lines
2.2 KiB
Java
60 lines
2.2 KiB
Java
package com.thebrokenrail.mtudining.activity.list;
|
|
|
|
import com.thebrokenrail.mtudining.activity.task.Task;
|
|
import com.thebrokenrail.mtudining.api.Connection;
|
|
import com.thebrokenrail.mtudining.api.method.AllLocations;
|
|
import com.thebrokenrail.mtudining.api.method.Info;
|
|
import com.thebrokenrail.mtudining.util.Category;
|
|
import com.thebrokenrail.mtudining.util.Constants;
|
|
|
|
/**
|
|
* Task for retrieving site ID and list of dining halls.
|
|
*/
|
|
class ListTask extends Task<ListData> {
|
|
private final Connection connection;
|
|
|
|
ListTask(Connection connection) {
|
|
this.connection = connection;
|
|
}
|
|
|
|
@Override
|
|
protected void startImpl(long id) {
|
|
// Cancel Existing HTTP Calls
|
|
connection.cancelAll();
|
|
// Load Site Info
|
|
Info info = new Info();
|
|
connection.send(info, infoResponse -> {
|
|
// Load Locations
|
|
AllLocations allLocations = new AllLocations(Constants.PLATFORM, infoResponse.site.id, false, true);
|
|
connection.send(allLocations, allLocationsResponse -> {
|
|
// Success
|
|
ListData data = new ListData(infoResponse.site.id);
|
|
// Find Active Locations
|
|
for (AllLocations.Response.Building building : allLocationsResponse.buildings) {
|
|
if (building.show_menus) {
|
|
// Found Active Building
|
|
Category<AllLocations.Response.Location> category = new Category<>(building.name);
|
|
for (AllLocations.Response.Location location : building.locations) {
|
|
if (location.active) {
|
|
// Found Active Location
|
|
category.items.add(location);
|
|
}
|
|
}
|
|
// Skip Empty Category
|
|
if (category.items.size() > 0) {
|
|
data.categories.add(category);
|
|
}
|
|
}
|
|
}
|
|
done(id, data);
|
|
}, () -> {
|
|
// Failed Fetching Location Info
|
|
done(id, null);
|
|
});
|
|
}, () -> {
|
|
// Failed Fetching Site Info
|
|
done(id, null);
|
|
});
|
|
}
|
|
}
|