Search in sources :

Example 1 with ChatRoomController

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;
}
Also used : CalendarController(de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController) CafeteriaManager(de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager) AccessTokenManager(de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager) EduroamFixCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard) LoginPromtCard(de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard) ArrayList(java.util.ArrayList) NewsController(de.tum.in.tumcampusapp.component.ui.news.NewsController) Card(de.tum.in.tumcampusapp.component.ui.overview.card.Card) LoginPromtCard(de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard) EduroamFixCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard) EduroamCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard) EduroamCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard) TuitionFeeManager(de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeeManager) TransportController(de.tum.in.tumcampusapp.component.ui.transportation.TransportController) ChatRoomController(de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)

Example 2 with ChatRoomController

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");
        }
    });
}
Also used : NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) ChatRoom(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom) ChatVerification(de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification) Intent(android.content.Intent) ChatRoomController(de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)

Example 3 with ChatRoomController

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));
}
Also used : TabLayout(android.support.design.widget.TabLayout) ChatRoomController(de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)

Example 4 with ChatRoomController

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;
}
Also used : ChatMember(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember) AuthenticationManager(de.tum.in.tumcampusapp.api.app.AuthenticationManager) NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) ChatRoom(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom) IOException(java.io.IOException) ChatRoomController(de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)

Example 5 with ChatRoomController

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

ChatRoomController (de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)5 NoPrivateKey (de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)2 ChatRoom (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom)2 Intent (android.content.Intent)1 TabLayout (android.support.design.widget.TabLayout)1 AuthenticationManager (de.tum.in.tumcampusapp.api.app.AuthenticationManager)1 AccessTokenManager (de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager)1 TUMOnlineRequest (de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest)1 CalendarController (de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController)1 LecturesSearchRow (de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow)1 LecturesSearchRowSet (de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRowSet)1 TuitionFeeManager (de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeeManager)1 CafeteriaManager (de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager)1 ChatMember (de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember)1 ChatVerification (de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification)1 EduroamCard (de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard)1 EduroamFixCard (de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard)1 NewsController (de.tum.in.tumcampusapp.component.ui.news.NewsController)1 LoginPromtCard (de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard)1 Card (de.tum.in.tumcampusapp.component.ui.overview.card.Card)1