Skip to content

Commit f07484f

Browse files
committed
Added some changes to invert dependency
1 parent b8f2220 commit f07484f

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

src/main/java/interface_adapters/appscreen/AppScreenLoader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import entities.chat.Chat;
44
import screens.appscreen.AppScreen;
5+
import use_cases.appscreen.AppScreenStatus;
56

67
import java.util.ArrayList;
78

@@ -28,6 +29,10 @@ public AppScreenLoader(String username, ArrayList<Chat> chats){
2829
public void openScreen() {
2930
try {
3031
this.appScreen = new AppScreen(this.username, this.chats);
32+
33+
// set and save the current app screen
34+
AppScreenStatus.setAppScreen(this.appScreen);
35+
3136
} catch (Exception e) {
3237
throw new RuntimeException("Unexpected Interruption: cannot load screen");
3338
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package use_cases.appscreen;
22

33
import interface_adapters.appscreen.AppScreenController;
4-
import interface_adapters.appscreen.Refresh;
54

6-
public class AppScreenRequestModel implements Refresh {
7-
private final AppScreenController appScreenController;
5+
public class AppScreenRequestModel {
86

97
public AppScreenRequestModel(String username, String chatID){
10-
this.appScreenController = new AppScreenController(username, chatID);
8+
AppScreenController appScreenController = new AppScreenController(username, chatID);
9+
appScreenController.updateScreen();
10+
AppScreenResponseModel.refreshScreen(chatID);
1111
}
1212

13-
@Override
14-
public void refreshScreen(String chatID) {
15-
this.appScreenController.updateScreen();
16-
}
1713
}
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
package use_cases.appscreen;
22

3-
import screens.appscreen.AppScreen;
4-
53
public class AppScreenResponseModel {
64

7-
AppScreen appScreen;
8-
String chatID;
9-
public AppScreenResponseModel(AppScreen appScreen, String chatID){
10-
this.appScreen = appScreen;
11-
this.chatID = chatID;
12-
appScreen.refreshScreen(chatID);
5+
public static void refreshScreen(String chatID) {
6+
AppScreenStatus.getAppScreen().refreshScreen(chatID);
137
}
148
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package use_cases.appscreen;
2+
3+
import screens.appscreen.AppScreen;
4+
5+
public class AppScreenStatus {
6+
7+
public static AppScreen appScreen;
8+
9+
/**
10+
* Create an empty constructor, so we can access the current app screen in a static context
11+
* (so we can access it globally)
12+
*/
13+
public AppScreenStatus(){
14+
15+
}
16+
17+
/**
18+
* Set current status to be this app screen
19+
* @param thisAppScreen The current app screen
20+
*/
21+
public static void setAppScreen(AppScreen thisAppScreen){
22+
appScreen = thisAppScreen;
23+
}
24+
25+
/**
26+
* Return the current app screen
27+
* @return current app screen
28+
*/
29+
public static AppScreen getAppScreen(){
30+
return appScreen;
31+
}
32+
}

0 commit comments

Comments
 (0)