Skip to content

Commit 74f968c

Browse files
committed
Made changes so that new chats can also be added and displayed in order
1 parent 6a889d3 commit 74f968c

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

src/main/java/appscreen/AppScreen.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.ArrayList;
88
import testerEntities.*;
99

10-
1110
public class AppScreen implements AppScreenPresenter, AppScreenController, ChatName, Refresh {
1211

1312
private final JFrame jFrame;
@@ -17,9 +16,9 @@ public class AppScreen implements AppScreenPresenter, AppScreenController, ChatN
1716

1817

1918
/**
20-
Create an appscreen.AppScreen object
21-
@param chats This is a list of chats given by the user (the list will always come as sorted with the
22-
most recent chats at the end of the list)
19+
Create an AppScreen object
20+
@param chats This is a list of chats given by the user (the list will always come as sorted with the
21+
most recent chats at the end of the list)
2322
*/
2423
public AppScreen(String currentUsername, ArrayList<Chat> chats) {
2524
this.currentUsername = currentUsername;
@@ -63,11 +62,10 @@ public void openScreen() {
6362
}
6463

6564
/**
66-
Display a screen containing an ordered list of chats to the user based on latest conversation times
65+
Display a screen containing an ordered list of chats to the user based on latest conversation times
6766
*/
6867
public void displayAppScreen(){
6968

70-
7169
JPanel jPanel = new JPanel();
7270

7371
// getting the names of each chat to display and creating buttons for each chat
@@ -88,7 +86,7 @@ public void displayAppScreen(){
8886
public void actionPerformed(ActionEvent e) {
8987

9088
/* TODO: call chatView to open the display the window (?) for chat
91-
- not sure if appscreen.AppScreen and ChatView would be combined into one window, or
89+
- not sure if AppScreen and ChatView would be combined into one window, or
9290
two separate windows
9391
*/
9492
}
@@ -110,8 +108,8 @@ public void actionPerformed(ActionEvent e) {
110108
}
111109

112110
/**
113-
Make the chat list scrollable
114-
@param jPanel The panel containing the chats
111+
Make the chat list scrollable
112+
@param jPanel The panel containing the chats
115113
*/
116114
private void scrollableChats(JPanel jPanel) {
117115
JScrollPane scrollFrame = new JScrollPane(jPanel);
@@ -147,9 +145,26 @@ public void updateChatOrder(Chat chat){
147145

148146
}
149147

148+
/**
149+
* Add a new chat to the screen, if the chat already exists (i.e. there exists a chat with the
150+
* same ID, do nothing.
151+
* @param chat The new chat to be added
152+
*/
153+
public void addNewChat(Chat chat){
154+
155+
if (!(this.chats.contains(chat))){
156+
updateChatOrder(chat);
157+
jFrame.remove(this.jScrollPane);
158+
159+
// refresh the screen
160+
displayAppScreen();
161+
162+
}
163+
}
164+
150165

151166
/**
152-
* Update the screen if the given chat has been updated
167+
* Update the order of chats that appear on screen if there was a change to conversation history
153168
* @param chatID The ID of the given chat
154169
*/
155170
@Override
@@ -175,6 +190,11 @@ public boolean hasUpdate(String chatID) {
175190
return this.chats.get(this.chats.size() - 1) != chat;
176191
}
177192

193+
/**
194+
* Get the chat object given its chat ID
195+
* @param chatID The ID of the chat
196+
* @return The chat with the given ID
197+
*/
178198
@Override
179199
public Chat getChat(String chatID) {
180200
for (Chat chat: this.chats){

src/main/java/appscreen/AppScreenLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public AppScreenLoader(String username, UserDataBase userDataBase){
2626
}
2727

2828
/**
29-
* Open an app screen for the user to see all their chats
29+
* Create the screen to show to the user
3030
*/
3131
@Override
3232
public void openScreen() {
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package appscreen;
2-
32
public interface AppScreenPresenter {
43
void displayAppScreen();
54
}
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
package appscreen;
2-
3-
import testerEntities.*;
4-
import java.util.ArrayList;
5-
62
public interface LoginSuccess {
73
void openScreen();
84
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package appscreen;
2-
3-
import testerEntities.*;
4-
52
public interface Refresh {
6-
boolean hasUpdate(Chat chat);
7-
8-
void updateScreen(Chat chat);
3+
boolean hasUpdate(String chatID);
4+
void updateScreen(String chatID);
95
}

0 commit comments

Comments
 (0)