use of de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoom in project TumCampusApp by TCA-Team.
the class StudyRoomGroupManager method downloadFromExternal.
public void downloadFromExternal() throws JSONException {
Optional<JSONObject> jsonObject = new NetUtils(mContext).downloadJsonObject(STUDYROOM_URL, CacheManager.VALIDITY_DO_NOT_CACHE, true);
if (!jsonObject.isPresent()) {
return;
}
dao.removeCache();
groupDao.removeCache();
List<StudyRoomGroup> groups = getAllFromJson(jsonObject.get());
for (StudyRoomGroup group : groups) {
groupDao.insert(group);
for (StudyRoom room : group.getRooms()) {
room.setStudyRoomGroup(group.getId());
dao.insert(room);
}
}
new SyncManager(mContext).replaceIntoDb(this);
}
use of de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoom in project TumCampusApp by TCA-Team.
the class StudyRoomGroupManager method getAllFromJson.
public static List<StudyRoomGroup> getAllFromJson(JSONObject jsonObject) throws JSONException {
JSONArray groupsJsonArray = jsonObject.getJSONArray("gruppen");
JSONArray roomsJsonArray = jsonObject.getJSONArray("raeume");
List<StudyRoomGroup> studyRoomGroups = new ArrayList<>();
for (int i = 0; i < groupsJsonArray.length(); i++) {
JSONObject groupJsonObject = groupsJsonArray.getJSONObject(i);
List<StudyRoom> studyRoomList = getStudyRoomsFromJson(groupJsonObject.getJSONArray("raeume"), roomsJsonArray);
studyRoomGroups.add(new StudyRoomGroup(groupJsonObject.getInt("nr"), groupJsonObject.getString("name"), groupJsonObject.getString("detail"), studyRoomList));
}
return studyRoomGroups;
}
use of de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoom in project TumCampusApp by TCA-Team.
the class StudyRoomGroupManager method getStudyRoomsFromJson.
private static List<StudyRoom> getStudyRoomsFromJson(JSONArray groupRoomList, JSONArray allRooms) throws JSONException {
List<StudyRoom> studyRooms = new ArrayList<>();
for (int i = 0; i < allRooms.length(); i++) {
int roomNumber = allRooms.getJSONObject(i).getInt("raum_nr");
for (int j = 0; j < groupRoomList.length(); j++) {
if (groupRoomList.getInt(j) == roomNumber) {
StudyRoom studyRoom;
try {
studyRoom = new StudyRoom(roomNumber, allRooms.getJSONObject(i).getString("raum_code"), allRooms.getJSONObject(i).getString("raum_name"), allRooms.getJSONObject(i).getString("gebaeude_name"), -1, new SimpleDateFormat(DATEFORMAT, Locale.US).parse(allRooms.getJSONObject(i).getString("belegung_bis")));
} catch (ParseException e) {
// Room is not occupied
studyRoom = new StudyRoom(roomNumber, allRooms.getJSONObject(i).getString("raum_code"), allRooms.getJSONObject(i).getString("raum_name"), allRooms.getJSONObject(i).getString("gebaeude_name"), -1, new Date());
}
studyRooms.add(studyRoom);
}
}
}
return studyRooms;
}
Aggregations