Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1217 from TUM-Dev/chat-improv
Browse files Browse the repository at this point in the history
Further Chat Improvements
  • Loading branch information
kordianbruck authored Nov 18, 2018
2 parents f209682 + 25d07c0 commit 89a5bf6
Show file tree
Hide file tree
Showing 23 changed files with 111 additions and 148 deletions.
13 changes: 8 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ android {
proguardFiles(file('../proguard').listFiles())
proguardFile getDefaultProguardFile('proguard-android.txt')
minifyEnabled true
shrinkResources true
useProguard true
}
release.debuggable false
release {
debuggable false
shrinkResources true
}
debug {
debuggable true
shrinkResources false
testCoverageEnabled true
}
}
Expand Down Expand Up @@ -108,9 +111,9 @@ dependencies {
implementation 'com.google.android.gms:play-services-location:16.0.0'

// Firebase
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.6'

// Helpers
implementation 'com.google.code.gson:gson:2.8.5'
Expand Down Expand Up @@ -148,7 +151,7 @@ dependencies {
implementation 'com.github.thellmund:Android-Week-View:2.0.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'

// Testing
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ Call<List<RoomFinderSchedule>> fetchSchedule(@Path("roomId") String archId,
Call<List<Event>> getEvents();

// Getting Ticket information

@POST(API_EVENTS + API_TICKET + "my")
Call<List<Ticket>> getTickets(@Body TUMCabeVerification verification);

Expand All @@ -229,12 +228,10 @@ Call<List<RoomFinderSchedule>> fetchSchedule(@Path("roomId") String archId,
Call<List<TicketType>> getTicketTypes(@Path("eventID") int eventID);

// Ticket reservation

@POST(API_EVENTS + API_TICKET + "reserve")
Call<TicketReservationResponse> reserveTicket(@Body TUMCabeVerification verification);

// Ticket purchase

@POST(API_EVENTS + API_TICKET + "payment/stripe/purchase")
Call<Ticket> purchaseTicketStripe(@Body TUMCabeVerification verification);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.inputmethod.EditorInfo;
Expand All @@ -16,6 +14,8 @@
import java.util.List;
import java.util.regex.Pattern;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import de.tum.in.tumcampusapp.R;
import de.tum.in.tumcampusapp.api.app.ApiHelper;
import de.tum.in.tumcampusapp.api.app.TUMCabeClient;
Expand Down Expand Up @@ -58,10 +58,9 @@ protected void onCreate(Bundle savedInstanceState) {
delayHandler = new Handler();
tumIdPattern = Pattern.compile(Const.TUM_ID_PATTERN);

room = new ChatRoom();
room.setName(getIntent().getStringExtra(Const.CHAT_ROOM_NAME));
room = new ChatRoom(getIntent().getStringExtra(Const.CHAT_ROOM_NAME));
room.setId(getIntent().getIntExtra(Const.CURRENT_CHAT_ROOM, -1));
Utils.log("ChatRoom: " + room.getActualName() + " (roomId: " + room.getId() + ")");
Utils.log("ChatRoom: " + room.getTitle() + " (roomId: " + room.getId() + ")");

tumCabeClient = TUMCabeClient.getInstance(this);

Expand Down Expand Up @@ -150,7 +149,7 @@ public void afterTextChanged(Editable editable) {
});

ImageView qrCode = findViewById(R.id.join_chat_qr_code);
qrCode.setImageBitmap(ApiHelper.createQRCode(room.getName()));
qrCode.setImageBitmap(ApiHelper.createQRCode(room.getCombinedName()));
}

private void getSuggestions() {
Expand Down Expand Up @@ -179,7 +178,7 @@ private void onError() {

private void showConfirmDialog(ChatMember member) {
String message = getString(R.string.add_user_to_chat_message,
member.getDisplayName(), room.getActualName());
member.getDisplayName(), room.getTitle());
AlertDialog dialog = new AlertDialog.Builder(this)
.setMessage(message)
.setPositiveButton(R.string.add, (dialogInterface, i) -> {
Expand Down Expand Up @@ -221,7 +220,7 @@ public void onResponse(@NonNull Call<ChatRoom> call,
if (room != null) {
TcaDb.getInstance(getBaseContext())
.chatRoomDao()
.updateMemberCount(room.getMembers(), room.getId(), room.getName());
.updateMemberCount(room.getMembers(), room.getId());
Utils.showToast(getBaseContext(), R.string.chat_member_added);
} else {
Utils.showToast(getBaseContext(), R.string.error_something_wrong);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package de.tum.in.tumcampusapp.component.ui.chat;

import java.util.List;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import java.util.List;

import de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage;

@Dao
Expand All @@ -18,8 +17,7 @@ public interface ChatMessageDao {
@Query("SELECT c.* FROM chat_message c WHERE c.room=:room ORDER BY c.sending, c._id")
List<ChatMessage> getAll(int room);

@Query("UPDATE chat_room "
+ "SET last_read = "
@Query("UPDATE chat_room SET last_read = "
+ "case when (select MAX(_id) from chat_message where room=:room) is null then -1 "
+ "else (select MAX(_id) from chat_message where room=:room) end "
+ "WHERE room=:room")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class ChatPushNotification(private val fcmChatPayload: FcmChat, context: Context
val n = NotificationCompat.Builder(context, Const.NOTIFICATION_CHANNEL_CHAT)
.setSmallIcon(defaultIcon)
.setLargeIcon(Utils.getLargeIcon(context, R.drawable.ic_chat_with_lines))
.setContentTitle(chatRoom.name.substring(4))
.setContentTitle(chatRoom.title)
.setStyle(NotificationCompat.BigTextStyle().bigText(text))
.setContentText(text)
.setContentIntent(contentIntent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,8 @@ public void replaceIntoRooms(Collection<ChatRoom> rooms) {
chatRoomDao.markAsNotJoined();
Utils.log("reset join status of all rooms");

/* TODO(jacqueline8711): load the last messages when joining the chat (here or somewhere else?)
TUMCabeVerification verification;
try {
ChatMember currentChatMember = Utils.getSetting(context, Const.CHAT_MEMBER, ChatMember.class);
if (currentChatMember != null) {
verification = TUMCabeVerification.create(context, currentChatMember);
}
} catch (NoPrivateKey noPrivateKey) {
return; //In this case we simply cannot do anything
}
ChatMessageRemoteRepository remoteRepository = ChatMessageRemoteRepository.INSTANCE;
remoteRepository.setTumCabeClient(TUMCabeClient.getInstance(context));
ChatMessageLocalRepository localRepository = ChatMessageLocalRepository.INSTANCE;
localRepository.setDb(TcaDb.getInstance(context));
ChatMessageViewModel chatMessageViewModel = new ChatMessageViewModel(localRepository, remoteRepository, new CompositeDisposable());
*/

for (ChatRoom room : rooms) {
String roomName = room.getActualName();
String roomName = room.getTitle();
String semester = room.getSemester();

List<Integer> roomIds = chatRoomDao.getGivenLecture(roomName, semester);
Expand All @@ -120,24 +102,18 @@ public void replaceIntoRooms(Collection<ChatRoom> rooms) {
"", room.getMembers(), -1);
chatRoomDao.replaceRoom(chatRoom);
} else {
//in dao
chatRoomDao.updateRoomToJoined(room.getId(), room.getMembers(), roomName, semester);
/* TODO(jacqueline8711) load the last messages when joining the chat
chatMessageViewModel.getNewMessages(room.getId(), verification,
context instanceof ChatMessageViewModel.DataLoadInterface ?
(ChatMessageViewModel.DataLoadInterface)context : null);
Utils.log("Loading some messages for a newly joined chatroom");*/
}
}

}

public void join(ChatRoom currentChatRoom) {
chatRoomDao.updateJoinedRooms(currentChatRoom.getId(), currentChatRoom.getActualName(), currentChatRoom.getSemester());
chatRoomDao.updateJoinedRooms(currentChatRoom.getId(), currentChatRoom.getTitle(), currentChatRoom.getSemester());
}

public void leave(ChatRoom currentChatRoom) {
chatRoomDao.updateLeftRooms(currentChatRoom.getId(), currentChatRoom.getActualName(), currentChatRoom.getSemester());
chatRoomDao.updateLeftRooms(currentChatRoom.getId(), currentChatRoom.getTitle(), currentChatRoom.getSemester());
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package de.tum.in.tumcampusapp.component.ui.chat;

import java.util.List;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

import de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage;
import de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomDbRow;

Expand Down Expand Up @@ -65,8 +64,8 @@ public interface ChatRoomDao {
@Query("UPDATE chat_room SET room=:room, joined=0 WHERE name=:name AND semester_id=:semesterId")
void updateLeftRooms(int room, String name, String semesterId);

@Query("UPDATE chat_room SET members=:memberCount WHERE room=:roomId AND name=:roomName")
void updateMemberCount(int memberCount, int roomId, String roomName);
@Query("UPDATE chat_room SET members=:memberCount WHERE room=:roomId")
void updateMemberCount(int memberCount, int roomId);

@Query("SELECT r.* " +
"FROM chat_room r, (SELECT semester_id FROM chat_room " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void setupToolbarTitle() {
currentChatMember = Utils.getSetting(this, Const.CHAT_MEMBER, ChatMember.class);

if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(currentChatRoom.getName().substring(4));
getSupportActionBar().setTitle(currentChatRoom.getTitle());
}
}

Expand Down Expand Up @@ -248,7 +248,7 @@ protected void onNewIntent(Intent intent) {
// If currently in a room which does not match the one from the notification --> Switch
currentChatRoom = room;
if (getSupportActionBar() != null) {
getSupportActionBar().setSubtitle(currentChatRoom.getName().substring(4));
getSupportActionBar().setSubtitle(currentChatRoom.getTitle());
}
chatHistoryAdapter = null;
getNextHistoryFromServer(true);
Expand Down Expand Up @@ -281,15 +281,15 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
private void openAddChatMemberActivity() {
Intent intent = new Intent(this, AddChatMemberActivity.class);
intent.putExtra(Const.CURRENT_CHAT_ROOM, currentChatRoom.getId());
intent.putExtra(Const.CHAT_ROOM_NAME, currentChatRoom.getName());
intent.putExtra(Const.CHAT_ROOM_NAME, currentChatRoom.getCombinedName());
startActivity(intent);
}

private void showLeaveChatRoomDialog() {
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle(R.string.leave_chat_room)
.setMessage(getResources().getString(R.string.leave_chat_room_body))
.setPositiveButton(R.string.leave, (dialogInterface, i) -> removeUserFromChatRoom())
.setPositiveButton(R.string.leave, (dialogInterface, i) -> leaveChatRoom())
.setNegativeButton(android.R.string.cancel, null)
.create();

Expand All @@ -300,7 +300,7 @@ private void showLeaveChatRoomDialog() {
dialog.show();
}

private void removeUserFromChatRoom() {
private void leaveChatRoom() {
TUMCabeVerification verification = TUMCabeVerification.create(this, null);
if (verification == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import androidx.annotation.NonNull;
import com.google.android.material.tabs.TabLayout;
import androidx.appcompat.app.AlertDialog;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;

import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import de.tum.in.tumcampusapp.R;
import de.tum.in.tumcampusapp.api.app.TUMCabeClient;
import de.tum.in.tumcampusapp.api.app.model.TUMCabeVerification;
Expand All @@ -47,8 +47,7 @@
* This activity presents the chat rooms of user's
* lectures using the TUMOnline web service
*/
public class ChatRoomsActivity
extends ActivityForAccessingTumOnline<LecturesResponse> implements OnItemClickListener {
public class ChatRoomsActivity extends ActivityForAccessingTumOnline<LecturesResponse> implements OnItemClickListener {

private static final int CAMERA_REQUEST_CODE = 34;
private static final int JOIN_ROOM_REQUEST_CODE = 22;
Expand Down Expand Up @@ -97,8 +96,10 @@ public void onTabReselected(TabLayout.Tab tab) {
}
});

tabLayout.addTab(tabLayout.newTab().setText(R.string.joined));
tabLayout.addTab(tabLayout.newTab().setText(R.string.not_joined));
tabLayout.addTab(tabLayout.newTab()
.setText(R.string.joined));
tabLayout.addTab(tabLayout.newTab()
.setText(R.string.not_joined));
}

@Override
Expand Down Expand Up @@ -161,8 +162,8 @@ private void createLectureRoomsAndUpdateDatabase(List<Lecture> lectures) {

List<ChatRoomAndLastMessage> chatRoomAndLastMessages = manager.getAllByStatus(mCurrentMode);
runOnUiThread(() -> {
displayChatRoomsAndMessages(chatRoomAndLastMessages);
showLoadingEnded();
displayChatRoomsAndMessages(chatRoomAndLastMessages);
showLoadingEnded();
});
}

Expand Down Expand Up @@ -252,15 +253,17 @@ private void newChatRoom() {
.setMessage(R.string.new_chat_room_desc)
.setView(view)
.setPositiveButton(R.string.create, (dialogInterface, whichButton) -> {
String value = input.getText().toString();
String value = input.getText()
.toString();
String randId = Integer.toHexString((int) (Math.random() * 4096));
createOrJoinChatRoom(randId + ':' + value);
})
.setNegativeButton(android.R.string.cancel, null)
.create();

if (dialog.getWindow() != null) {
dialog.getWindow().setBackgroundDrawableResource(R.drawable.rounded_corners_background);
dialog.getWindow()
.setBackgroundDrawableResource(R.drawable.rounded_corners_background);
}

dialog.show();
Expand Down
Loading

0 comments on commit 89a5bf6

Please sign in to comment.