Search in sources :

Example 1 with StudyRoomGroup

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);
}
Also used : StudyRoom(de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoom) NetUtils(de.tum.in.tumcampusapp.utils.NetUtils) JSONObject(org.json.JSONObject) SyncManager(de.tum.in.tumcampusapp.utils.sync.SyncManager) StudyRoomGroup(de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoomGroup)

Example 2 with StudyRoomGroup

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;
        }
    }
}
Also used : StudyRoomGroup(de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoomGroup)

Example 3 with StudyRoomGroup

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;
}
Also used : StudyRoom(de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoom) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) StudyRoomGroup(de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoomGroup)

Example 4 with StudyRoomGroup

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;
}
Also used : SpinnerAdapter(android.widget.SpinnerAdapter) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) LayoutInflater(android.view.LayoutInflater) NonNull(android.support.annotation.NonNull) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter) StudyRoomGroup(de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoomGroup)

Example 5 with StudyRoomGroup

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();
}
Also used : Spinner(android.widget.Spinner) StudyRoomGroup(de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoomGroup)

Aggregations

StudyRoomGroup (de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoomGroup)5 Spinner (android.widget.Spinner)2 StudyRoom (de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoom)2 JSONObject (org.json.JSONObject)2 NonNull (android.support.annotation.NonNull)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 SpinnerAdapter (android.widget.SpinnerAdapter)1 TextView (android.widget.TextView)1 NetUtils (de.tum.in.tumcampusapp.utils.NetUtils)1 SyncManager (de.tum.in.tumcampusapp.utils.sync.SyncManager)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1