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();
}
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);
}
}
}
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();
}
}
}
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;
}
}
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);
}
Aggregations