use of de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoomGroup 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.StudyRoomGroup in project TumCampusApp by TCA-Team.
the class StudyRoomsActivity method selectCurrentSpinnerItem.
private void selectCurrentSpinnerItem(Spinner spinner) {
for (int i = 0; i < mStudyRoomGroupList.size(); i++) {
StudyRoomGroup s = mStudyRoomGroupList.get(i);
if (mSelectedStudyRoomGroupId == -1 || mSelectedStudyRoomGroupId == s.getId()) {
mSelectedStudyRoomGroupId = s.getId();
spinner.setSelection(i);
return;
}
}
}
use of de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoomGroup 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.StudyRoomGroup in project TumCampusApp by TCA-Team.
the class StudyRoomsActivity method getStudyRoomGroupsSpinner.
private Spinner getStudyRoomGroupsSpinner() {
// Adapter for drop-down navigation
SpinnerAdapter adapterCafeterias = new ArrayAdapter<StudyRoomGroup>(this, R.layout.simple_spinner_item_actionbar, android.R.id.text1, mStudyRoomGroupList) {
final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(LAYOUT_INFLATER_SERVICE);
@Override
public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) {
View v = inflater.inflate(R.layout.simple_spinner_dropdown_item_actionbar, parent, false);
StudyRoomGroup studyRoomGroup = getItem(position);
// Set name
TextView name = v.findViewById(android.R.id.text1);
// Set detail
TextView details = v.findViewById(android.R.id.text2);
if (studyRoomGroup != null) {
name.setText(studyRoomGroup.getName());
details.setText(studyRoomGroup.getDetails());
}
return v;
}
};
Spinner spinner = findViewById(R.id.spinnerToolbar);
spinner.setAdapter(adapterCafeterias);
spinner.setOnItemSelectedListener(this);
return spinner;
}
use of de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoomGroup in project TumCampusApp by TCA-Team.
the class StudyRoomsActivity method onLoadFinished.
@Override
protected void onLoadFinished(Void result) {
StudyRoomGroupManager studyRoomGroupManager = new StudyRoomGroupManager(this);
mStudyRoomGroupList = studyRoomGroupManager.getAllFromDb();
for (StudyRoomGroup group : mStudyRoomGroupList) {
sortStudyRoomsByOccupation(group.getRooms());
}
if (hasGotStudyRoomGroups()) {
Spinner spinner = getStudyRoomGroupsSpinner();
selectCurrentSpinnerItem(spinner);
} else {
showCorrectErrorLayout();
}
showLoadingEnded();
}
Aggregations