Search in sources :

Example 1 with TUMOnlineRequest

use of de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest in project TumCampusApp by TCA-Team.

the class CacheManager method fillCache.

/**
 * Download usual tumOnline requests
 */
public void fillCache() {
    NetUtils net = new NetUtils(mContext);
    // Cache news source images
    NewsController newsController = new NewsController(mContext);
    List<NewsSources> newsSources = newsController.getNewsSources();
    for (NewsSources newsSource : newsSources) {
        String imgUrl = newsSource.getIcon();
        if (!imgUrl.isEmpty() && !"null".equals(imgUrl)) {
            net.downloadImage(imgUrl);
        }
    }
    // Cache news images
    List<News> news = newsController.getAllFromDb(mContext);
    for (News n : news) {
        String imgUrl = n.getImage();
        if (!imgUrl.isEmpty() && !"null".equals(imgUrl)) {
            net.downloadImage(imgUrl);
        }
    }
    // Cache kino covers
    kinoDao.getAll().subscribe(it -> {
        for (Kino kino : it) {
            String imgUrl = kino.getCover();
            if (!imgUrl.isEmpty() && !"null".equals(imgUrl)) {
                net.downloadImage(imgUrl);
            }
        }
    });
    // acquire access token
    if (!new AccessTokenManager(mContext).hasValidAccessToken()) {
        return;
    }
    // ALL STUFF BELOW HERE NEEDS A VALID ACCESS TOKEN
    // Sync organisation tree
    TUMOnlineRequest<OrgItemList> requestHandler = new TUMOnlineRequest<>(TUMOnlineConst.Companion.getORG_TREE(), mContext);
    if (shouldRefresh(requestHandler.getRequestURL())) {
        requestHandler.fetch();
    }
    // Sync fee status
    TUMOnlineRequest<TuitionList> requestHandler2 = new TUMOnlineRequest<>(TUMOnlineConst.Companion.getTUITION_FEE_STATUS(), mContext);
    if (shouldRefresh(requestHandler2.getRequestURL())) {
        requestHandler2.fetch();
    }
    // Sync lectures, details and appointments
    importLecturesFromTUMOnline();
    // Sync calendar
    syncCalendar();
}
Also used : TUMOnlineRequest(de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest) AccessTokenManager(de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager) OrgItemList(de.tum.in.tumcampusapp.component.other.departments.model.OrgItemList) TuitionList(de.tum.in.tumcampusapp.component.tumui.tutionfees.model.TuitionList) NewsController(de.tum.in.tumcampusapp.component.ui.news.NewsController) NewsSources(de.tum.in.tumcampusapp.component.ui.news.model.NewsSources) News(de.tum.in.tumcampusapp.component.ui.news.model.News) Kino(de.tum.in.tumcampusapp.component.ui.tufilm.model.Kino)

Example 2 with TUMOnlineRequest

use of de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest in project TumCampusApp by TCA-Team.

the class CacheManager method syncCalendar.

public void syncCalendar() {
    TUMOnlineRequest<CalendarRowSet> requestHandler = new TUMOnlineRequest<>(TUMOnlineConst.Companion.getCALENDER(), mContext);
    requestHandler.setParameter("pMonateVor", "2");
    requestHandler.setParameter("pMonateNach", "3");
    if (shouldRefresh(requestHandler.getRequestURL())) {
        Optional<CalendarRowSet> set = requestHandler.fetch();
        if (set.isPresent()) {
            CalendarController calendarController = new CalendarController(mContext);
            calendarController.importCalendar(set.get());
            CalendarController.QueryLocationsService.loadGeo(mContext);
        }
    }
}
Also used : TUMOnlineRequest(de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest) CalendarController(de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController) CalendarRowSet(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarRowSet)

Example 3 with TUMOnlineRequest

use of de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest 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 4 with TUMOnlineRequest

use of de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest in project TumCampusApp by TCA-Team.

the class WizNavCheckTokenActivity method onLoadInBackground.

/**
 * Check in background if token has been enabled and get identity for enabling chat.
 */
@Override
protected Integer onLoadInBackground(Void... arg) {
    // Check if token has been enabled
    if (TUMOnlineRequest.checkTokenInactive(this)) {
        if (NetUtils.isConnected(this)) {
            return R.string.token_not_enabled;
        } else {
            return R.string.no_internet_connection;
        }
    } else {
        // Token was activated
        // Get users full name
        TUMOnlineRequest<IdentitySet> request = new TUMOnlineRequest<>(TUMOnlineConst.Companion.getIDENTITY(), this, true);
        Optional<IdentitySet> id = request.fetch();
        if (!id.isPresent()) {
            return R.string.no_rights_to_access_id;
        }
        Identity identity = id.get().getIds().get(0);
        // Save the name to preferences
        Utils.setSetting(this, Const.CHAT_ROOM_DISPLAY_NAME, identity.toString());
        // Save the TUMOnline id to preferences
        Utils.setSetting(this, Const.TUMO_PIDENT_NR, identity.getObfuscated_ids().getStudierende());
        Utils.setSetting(this, Const.TUMO_STUDENT_ID, identity.getObfuscated_ids().getStudierende());
        Utils.setSetting(this, Const.TUMO_EXTERNAL_ID, identity.getObfuscated_ids().getExtern());
        Utils.setSetting(this, Const.TUMO_EMPLOYEE_ID, identity.getObfuscated_ids().getBedienstete());
        return null;
    }
}
Also used : TUMOnlineRequest(de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest) IdentitySet(de.tum.in.tumcampusapp.component.tumui.person.model.IdentitySet) Identity(de.tum.in.tumcampusapp.component.tumui.person.model.Identity)

Example 5 with TUMOnlineRequest

use of de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest 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

TUMOnlineRequest (de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest)5 LecturesSearchRow (de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow)2 LecturesSearchRowSet (de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRowSet)2 NoPrivateKey (de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)1 AccessTokenManager (de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager)1 OrgItemList (de.tum.in.tumcampusapp.component.other.departments.model.OrgItemList)1 CalendarController (de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController)1 CalendarRowSet (de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarRowSet)1 Identity (de.tum.in.tumcampusapp.component.tumui.person.model.Identity)1 IdentitySet (de.tum.in.tumcampusapp.component.tumui.person.model.IdentitySet)1 TuitionList (de.tum.in.tumcampusapp.component.tumui.tutionfees.model.TuitionList)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 NewsController (de.tum.in.tumcampusapp.component.ui.news.NewsController)1 News (de.tum.in.tumcampusapp.component.ui.news.model.News)1 NewsSources (de.tum.in.tumcampusapp.component.ui.news.model.NewsSources)1 Kino (de.tum.in.tumcampusapp.component.ui.tufilm.model.Kino)1 IOException (java.io.IOException)1