use of de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController in project TumCampusApp by TCA-Team.
the class CardManager method update.
/**
* Refreshes or initialises all cards.
* WARNING: Must not be called from UI thread.
* <p/>
* HOW TO ADD A NEW CARD:
* 1. Let the manager class implement {@link Card.ProvidesCard}
* 2. Create a new class extending {@link Card}
* 3. Implement the getCardView method in this class
* 4. Create a new instance of this card in the
* {@link Card.ProvidesCard#onRequestCard(Context)} method of the manager
* 5. Add this card to the CardManager by calling {@link Card#apply()} from
* {@link Card.ProvidesCard#onRequestCard(Context)}
* 6. Add an instance of the manager class to the managers list below
*/
public static synchronized void update(Context context) {
// Use temporary array to avoid that the main thread is trying to access an empty array
newCards.clear();
new NoInternetCard(context).apply();
new LoginPromtCard(context).apply();
new SupportCard(context).apply();
new EduroamCard(context).apply();
new EduroamFixCard(context).apply();
Collection<Card.ProvidesCard> managers = new ArrayList<>();
// Add those managers only if valid access token is available
if (new AccessTokenManager(context).hasValidAccessToken()) {
managers.add(new CalendarController(context));
managers.add(new TuitionFeeManager());
managers.add(new ChatRoomController(context));
}
// Those don't need TUMOnline access
managers.add(new CafeteriaManager(context));
managers.add(new TransportController(context));
managers.add(new NewsController(context));
for (Card.ProvidesCard manager : managers) {
manager.onRequestCard(context);
}
// Always append the restore card at the end of our list
new RestoreCard(context).apply();
shouldRefresh = false;
}
use of de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController in project TumCampusApp by TCA-Team.
the class ChatActivity method onClick.
/**
* When user confirms the leave dialog send the request to the server.
*
* @param dialog Dialog handle
* @param which The users choice (ignored because this is only called when the user confirms)
*/
@Override
public void onClick(DialogInterface dialog, int which) {
// Send request to the server to remove the user from this room
ChatVerification verification;
try {
verification = ChatVerification.Companion.getChatVerification(this, currentChatMember);
} catch (NoPrivateKey noPrivateKey) {
return;
}
TUMCabeClient.getInstance(this).leaveChatRoom(currentChatRoom, verification, new Callback<ChatRoom>() {
@Override
public void onResponse(Call<ChatRoom> call, Response<ChatRoom> room) {
Utils.logv("Success leaving chat room: " + room.body().getName());
new ChatRoomController(ChatActivity.this).leave(currentChatRoom);
// Move back to ChatRoomsActivity
Intent intent = new Intent(ChatActivity.this, ChatRoomsActivity.class);
startActivity(intent);
}
@Override
public void onFailure(Call<ChatRoom> call, Throwable t) {
Utils.log(t, "Failure leaving chat room");
}
});
}
use of de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController in project TumCampusApp by TCA-Team.
the class ChatRoomsActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// bind UI elements
lvMyChatRoomList = findViewById(R.id.lvMyChatRoomList);
lvMyChatRoomList.setOnItemClickListener(this);
manager = new ChatRoomController(this);
// Load the lectures list
requestHandler = new TUMOnlineRequest<>(TUMOnlineConst.Companion.getLECTURES_PERSONAL(), this, true);
TabLayout tabLayout = findViewById(R.id.chat_rooms_tabs);
// Create a tab listener that is called when the user changes tabs.
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
// show the given tab
mCurrentMode = 1 - tab.getPosition();
startLoading();
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
// hide the given tab
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
// probably ignore this event
}
});
tabLayout.addTab(tabLayout.newTab().setText(R.string.joined));
tabLayout.addTab(tabLayout.newTab().setText(R.string.not_joined));
}
use of de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController in project TumCampusApp by TCA-Team.
the class WizNavExtrasActivity method onLoadInBackground.
@Override
protected ChatMember onLoadInBackground(Void... arg) {
if (!NetUtils.isConnected(this)) {
showNoInternetLayout();
return null;
}
// Get the users lrzId and initialise chat member
ChatMember currentChatMember = new ChatMember(Utils.getSetting(this, Const.LRZ_ID, ""));
currentChatMember.setDisplayName(Utils.getSetting(this, Const.CHAT_ROOM_DISPLAY_NAME, ""));
if (currentChatMember.getLrzId().equals("")) {
return currentChatMember;
}
// Tell the server the new member
ChatMember member;
try {
// After the user has entered their display name, send a request to the server to create the new member
member = TUMCabeClient.getInstance(this).createMember(currentChatMember);
} catch (IOException e) {
Utils.log(e);
Utils.showToastOnUIThread(this, R.string.error_setup_chat_member);
return null;
}
// Catch a possible error, when we didn't get something returned
if (member == null || member.getLrzId() == null) {
Utils.showToastOnUIThread(this, R.string.error_setup_chat_member);
return null;
}
// Generate the private key and upload the public key to the server
AuthenticationManager am = new AuthenticationManager(this);
if (!am.generatePrivateKey(member)) {
// We cannot continue if the upload of the Public Key does not work
Utils.showToastOnUIThread(this, getString(R.string.failure_uploading_public_key));
return null;
}
// Try to restore already joined chat rooms from server
try {
List<ChatRoom> rooms = TUMCabeClient.getInstance(this).getMemberRooms(member.getId(), ChatVerification.Companion.getChatVerification(this, member));
new ChatRoomController(this).replaceIntoRooms(rooms);
// Store that this key was activated
Utils.setSetting(this, Const.PRIVATE_KEY_ACTIVE, true);
return member;
} catch (IOException | NoPrivateKey e) {
Utils.log(e);
}
return null;
}
use of de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController 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