Search in sources :

Example 1 with ChatRoomAndLastMessage

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage in project TumCampusApp by TCA-Team.

the class ChatRoomListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View listItem = convertView;
    ViewHolder holder;
    ChatRoomAndLastMessage room = getItem(position);
    if (listItem == null) {
        listItem = mInflater.inflate(R.layout.activity_lectures_listview, parent, false);
        holder = new ViewHolder();
        // set UI elements
        holder.tvLectureName = listItem.findViewById(R.id.tvLectureName);
        holder.tvDozent = listItem.findViewById(R.id.tvDozent);
        holder.tvMembers = listItem.findViewById(R.id.tvMembers);
        holder.tvLastmsg = listItem.findViewById(R.id.tvLastmsg);
        holder.llAdditionalInfo = listItem.findViewById(R.id.llAdditionalInfo);
        holder.tvUnreadCounter = listItem.findViewById(R.id.nrUnreadMessages);
        listItem.findViewById(R.id.tvTypeSWSSemester).setVisibility(View.GONE);
        listItem.setTag(holder);
    } else {
        holder = (ViewHolder) listItem.getTag();
    }
    holder.tvLectureName.setText(room.getChatRoomDbRow().getName());
    holder.tvDozent.setText(room.getText());
    if (room.getNrUnread() > 0 && holder.tvUnreadCounter != null) {
        holder.tvUnreadCounter.setVisibility(View.VISIBLE);
        holder.tvUnreadCounter.setText(room.getNrUnread() >= 25 ? "25+" : room.getNrUnread() + "");
    } else {
        holder.tvUnreadCounter.setVisibility(View.GONE);
    }
    if (showDateAndNumber) {
        holder.tvMembers.setText(String.format(Locale.getDefault(), "%d", room.getChatRoomDbRow().getMembers()));
        holder.tvLastmsg.setText(DateUtils.getTimeOrDayISO(room.getTimestamp(), mContext));
        holder.llAdditionalInfo.setVisibility(View.VISIBLE);
    } else {
        holder.tvDozent.setText(room.getChatRoomDbRow().getContributor());
    }
    return listItem;
}
Also used : ChatRoomAndLastMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage) TextView(android.widget.TextView) View(android.view.View)

Example 2 with ChatRoomAndLastMessage

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage in project TumCampusApp by TCA-Team.

the class ChatRoomListAdapter method getHeaderId.

@Override
public long getHeaderId(int i) {
    ChatRoomAndLastMessage item = getItem(i);
    String semester = item.getChatRoomDbRow().getSemester();
    if (!filters.contains(semester)) {
        filters.add(semester);
    }
    return filters.indexOf(semester);
}
Also used : ChatRoomAndLastMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage)

Example 3 with ChatRoomAndLastMessage

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage in project TumCampusApp by TCA-Team.

the class ChatRoomListAdapter method getHeaderView.

@Override
public View getHeaderView(int pos, View view, ViewGroup parent) {
    HeaderViewHolder holder;
    View convertview = view;
    if (convertview == null) {
        holder = new HeaderViewHolder();
        convertview = mInflater.inflate(R.layout.header, parent, false);
        holder.text = convertview.findViewById(R.id.lecture_header);
        convertview.setTag(holder);
    } else {
        holder = (HeaderViewHolder) convertview.getTag();
    }
    // set header text as first char in name
    ChatRoomAndLastMessage item = getItem(pos);
    String semester = item.getChatRoomDbRow().getSemester();
    if (semester.isEmpty()) {
        semester = mContext.getString(R.string.my_chat_rooms);
    }
    holder.text.setText(semester);
    return convertview;
}
Also used : ChatRoomAndLastMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage) TextView(android.widget.TextView) View(android.view.View)

Example 4 with ChatRoomAndLastMessage

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage in project TumCampusApp by TCA-Team.

the class ChatRoomsActivity method createOrJoinChatRoom.

/**
 * Creates a given chat room if it does not exist and joins it
 * Works asynchronously.
 */
private void createOrJoinChatRoom(String name) {
    if (this.currentChatMember == null) {
        Utils.showToast(this, getString(R.string.chat_not_setup));
        return;
    }
    Utils.logv("create or join chat room " + name);
    currentChatRoom = new ChatRoom(name);
    ChatVerification verification;
    try {
        verification = ChatVerification.Companion.getChatVerification(this, this.currentChatMember);
    } catch (NoPrivateKey noPrivateKey) {
        this.finish();
        return;
    }
    Callback callback = new Callback<ChatRoom>() {

        @Override
        public void onResponse(@NonNull Call<ChatRoom> call, @NonNull Response<ChatRoom> response) {
            if (!response.isSuccessful()) {
                Utils.logv("Error creating&joining chat room: " + response.message());
                return;
            }
            // The POST request is successful: go to room. API should have auto joined it
            Utils.logv("Success creating&joining chat room: " + response.body());
            currentChatRoom = response.body();
            manager.join(currentChatRoom);
            // When we show joined chat rooms open chat room directly
            if (mCurrentMode == 1) {
                moveToChatActivity();
            } else {
                // Otherwise show a nice information, that we added the room
                final List<ChatRoomAndLastMessage> rooms = manager.getAllByStatus(mCurrentMode);
                runOnUiThread(() -> {
                    chatRoomAdapter.updateRooms(rooms);
                    Utils.showToast(ChatRoomsActivity.this, R.string.joined_chat_room);
                });
            }
        }

        @Override
        public void onFailure(@NonNull Call<ChatRoom> call, @NonNull Throwable t) {
            Utils.log(t, "Failure creating/joining chat room - trying to GET it from the server");
            Utils.showToastOnUIThread(ChatRoomsActivity.this, R.string.activate_key);
        }
    };
    TUMCabeClient.getInstance(this).createRoom(currentChatRoom, verification, callback);
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) ChatRoom(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom) ChatRoomAndLastMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage) NonNull(android.support.annotation.NonNull) ChatVerification(de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification)

Example 5 with ChatRoomAndLastMessage

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage in project TumCampusApp by TCA-Team.

the class ChatRoomsActivity method onItemClick.

/**
 * Handle click on chat room
 */
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
    ChatRoomAndLastMessage item = (ChatRoomAndLastMessage) lvMyChatRoomList.getItemAtPosition(position);
    // set bundle for LectureDetails and show it
    Bundle bundle = new Bundle();
    final Intent intent = new Intent(this, ChatActivity.class);
    intent.putExtras(bundle);
    String chatRoomUid = item.getChatRoomDbRow().getSemesterId() + ':' + item.getChatRoomDbRow().getName();
    this.createOrJoinChatRoom(chatRoomUid);
}
Also used : ChatRoomAndLastMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage) Bundle(android.os.Bundle) Intent(android.content.Intent)

Aggregations

ChatRoomAndLastMessage (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage)5 View (android.view.View)2 TextView (android.widget.TextView)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 NoPrivateKey (de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)1 ChatRoom (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom)1 ChatVerification (de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1 Response (retrofit2.Response)1