Search in sources :

Example 1 with LecturesSearchRow

use of de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow in project TumCampusApp by TCA-Team.

the class LecturesListAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    ViewHolder holder;
    View convertView = view;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.activity_lectures_listview, parent, false);
        holder = new ViewHolder();
        // set UI elements
        holder.tvLectureName = convertView.findViewById(R.id.tvLectureName);
        holder.tvTypeSWSSemester = convertView.findViewById(R.id.tvTypeSWSSemester);
        holder.tvDozent = convertView.findViewById(R.id.tvDozent);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    LecturesSearchRow lvItem = infoList.get(position);
    // if we have something to display - set for each lecture element
    if (lvItem != null) {
        holder.tvLectureName.setText(lvItem.getTitel());
        holder.tvTypeSWSSemester.setText(String.format("%s - %s - %s SWS", lvItem.getStp_lv_art_name(), lvItem.getSemester_id(), lvItem.getDauer_info()));
        holder.tvDozent.setText(lvItem.getVortragende_mitwirkende());
    }
    return convertView;
}
Also used : LecturesSearchRow(de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow) TextView(android.widget.TextView) View(android.view.View)

Example 2 with LecturesSearchRow

use of de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow in project TumCampusApp by TCA-Team.

the class LecturesPersonalActivity method onLoadFinished.

@Override
public void onLoadFinished(LecturesSearchRowSet response) {
    if (response == null || response.getLehrveranstaltungen() == null) {
        // no results found
        lvMyLecturesList.setAdapter(new NoResultsAdapter(this));
    } else {
        // Sort lectures by semester id
        List<LecturesSearchRow> lectures = response.getLehrveranstaltungen();
        Collections.sort(lectures);
        // set ListView to data via the LecturesListAdapter
        lvMyLecturesList.setAdapter(LecturesListAdapter.newInstance(this, lectures));
    }
}
Also used : NoResultsAdapter(de.tum.in.tumcampusapp.component.other.generic.adapter.NoResultsAdapter) LecturesSearchRow(de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow)

Example 3 with LecturesSearchRow

use of de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow in project TumCampusApp by TCA-Team.

the class ChatRoomController method createLectureRooms.

/**
 * Saves the given lectures into database
 */
public void createLectureRooms(Iterable<LecturesSearchRow> lectures) {
    // Create a Set of all existing lectures
    List<Integer> roomLvIds = chatRoomDao.getLvIds();
    Collection<String> set = new HashSet<>();
    for (Integer id : roomLvIds) {
        set.add(String.valueOf(id));
    }
    // Add lectures that are not yet in DB
    for (LecturesSearchRow lecture : lectures) {
        if (!set.contains(lecture.getStp_lv_nr())) {
            chatRoomDao.replaceRoom(ChatRoomDbRow.Companion.fromLecture(lecture));
        }
    }
}
Also used : LecturesSearchRow(de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow) HashSet(java.util.HashSet)

Example 4 with LecturesSearchRow

use of de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow in project TumCampusApp by TCA-Team.

the class ChatRoomController method onRequestCard.

@Override
public void onRequestCard(Context context) {
    // Get all of the users lectures and save them as possible chat rooms
    TUMOnlineRequest<LecturesSearchRowSet> requestHandler = new TUMOnlineRequest<>(TUMOnlineConst.Companion.getLECTURES_PERSONAL(), context, true);
    Optional<LecturesSearchRowSet> lecturesList = requestHandler.fetch();
    if (lecturesList.isPresent()) {
        List<LecturesSearchRow> lectures = lecturesList.get().getLehrveranstaltungen();
        this.createLectureRooms(lectures);
    }
    // Join all new chat rooms
    if (Utils.getSettingBool(context, Const.AUTO_JOIN_NEW_ROOMS, false)) {
        List<String> newRooms = this.getNewUnjoined();
        ChatMember currentChatMember = Utils.getSetting(context, Const.CHAT_MEMBER, ChatMember.class);
        for (String roomId : newRooms) {
            // Join chat room
            try {
                ChatRoom currentChatRoom = new ChatRoom(roomId);
                currentChatRoom = TUMCabeClient.getInstance(context).createRoom(currentChatRoom, ChatVerification.Companion.getChatVerification(context, currentChatMember));
                if (currentChatRoom != null) {
                    this.join(currentChatRoom);
                }
            } catch (IOException e) {
                Utils.log(e, " - error occured while creating the room!");
            } catch (NoPrivateKey noPrivateKey) {
                return;
            }
        }
    }
    // Get all rooms that have unread messages
    List<ChatRoomDbRow> rooms = chatRoomDao.getUnreadRooms();
    if (!rooms.isEmpty()) {
        for (ChatRoomDbRow room : rooms) {
            ChatMessagesCard card = new ChatMessagesCard(context, room);
            card.apply();
        }
    }
}
Also used : ChatMember(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember) TUMOnlineRequest(de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest) LecturesSearchRowSet(de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRowSet) LecturesSearchRow(de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow) IOException(java.io.IOException) NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) ChatRoom(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom) ChatRoomDbRow(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomDbRow)

Example 5 with LecturesSearchRow

use of de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow in project TumCampusApp by TCA-Team.

the class CacheManager method importLecturesFromTUMOnline.

/**
 * this function allows us to import all lecture items from TUMOnline
 */
private void importLecturesFromTUMOnline() {
    // get my lectures
    TUMOnlineRequest<LecturesSearchRowSet> requestHandler = new TUMOnlineRequest<>(TUMOnlineConst.Companion.getLECTURES_PERSONAL(), mContext);
    if (!shouldRefresh(requestHandler.getRequestURL())) {
        return;
    }
    Optional<LecturesSearchRowSet> lecturesList = requestHandler.fetch();
    if (!lecturesList.isPresent()) {
        return;
    }
    List<LecturesSearchRow> lectures = lecturesList.get().getLehrveranstaltungen();
    ChatRoomController manager = new ChatRoomController(mContext);
    manager.createLectureRooms(lectures);
}
Also used : TUMOnlineRequest(de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest) LecturesSearchRowSet(de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRowSet) LecturesSearchRow(de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow) ChatRoomController(de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)

Aggregations

LecturesSearchRow (de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow)6 TUMOnlineRequest (de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest)2 LecturesSearchRowSet (de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRowSet)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 View (android.view.View)1 TextView (android.widget.TextView)1 NoPrivateKey (de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)1 NoResultsAdapter (de.tum.in.tumcampusapp.component.other.generic.adapter.NoResultsAdapter)1 ChatRoomController (de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)1 ChatMember (de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember)1 ChatRoom (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom)1 ChatRoomDbRow (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomDbRow)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1