mirror of
https://github.com/ChronosX88/Influence-P2P.git
synced 2024-11-22 15:22:18 +00:00
Added stop for tracking new messages when chat activity closed
This commit is contained in:
parent
6670715418
commit
a0d50a3d1c
@ -4,4 +4,5 @@ import io.github.chronosx88.influence.models.roomEntities.MessageEntity;
|
|||||||
|
|
||||||
public interface IChatLogicContract {
|
public interface IChatLogicContract {
|
||||||
void sendMessage(MessageEntity message);
|
void sendMessage(MessageEntity message);
|
||||||
|
void stopTrackingForNewMsgs();
|
||||||
}
|
}
|
||||||
|
@ -3,4 +3,5 @@ package io.github.chronosx88.influence.contracts.chatactivity;
|
|||||||
public interface IChatPresenterContract {
|
public interface IChatPresenterContract {
|
||||||
void sendMessage(String text);
|
void sendMessage(String text);
|
||||||
void updateAdapter();
|
void updateAdapter();
|
||||||
|
void onDestroy();
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ public class ChatLogic implements IChatLogicContract {
|
|||||||
private ChatEntity chatEntity;
|
private ChatEntity chatEntity;
|
||||||
private Thread checkNewMessagesThread = null;
|
private Thread checkNewMessagesThread = null;
|
||||||
private KeyPairManager keyPairManager;
|
private KeyPairManager keyPairManager;
|
||||||
|
private Timer timer;
|
||||||
|
|
||||||
public ChatLogic(ChatEntity chatEntity) {
|
public ChatLogic(ChatEntity chatEntity) {
|
||||||
this.chatEntity = chatEntity;
|
this.chatEntity = chatEntity;
|
||||||
@ -44,7 +45,7 @@ public class ChatLogic implements IChatLogicContract {
|
|||||||
checkForNewMessages();
|
checkForNewMessages();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Timer timer = new Timer();
|
this.timer = new Timer();
|
||||||
timer.schedule(timerTask, 1, 1000);
|
timer.schedule(timerTask, 1, 1000);
|
||||||
this.keyPairManager = new KeyPairManager();
|
this.keyPairManager = new KeyPairManager();
|
||||||
}
|
}
|
||||||
@ -167,4 +168,10 @@ public class ChatLogic implements IChatLogicContract {
|
|||||||
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
|
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
|
||||||
return jsonObject.get("action").getAsInt();
|
return jsonObject.get("action").getAsInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopTrackingForNewMsgs() {
|
||||||
|
timer.cancel();
|
||||||
|
timer.purge();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,4 +58,9 @@ public class ChatPresenter implements IChatPresenterContract, IObserver {
|
|||||||
List<MessageEntity> entities = LocalDBWrapper.getMessagesByChatID(chatID);
|
List<MessageEntity> entities = LocalDBWrapper.getMessagesByChatID(chatID);
|
||||||
view.updateMessageList(entities == null ? new ArrayList<>() : entities);
|
view.updateMessageList(entities == null ? new ArrayList<>() : entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
logic.stopTrackingForNewMsgs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,4 +86,10 @@ public class ChatActivity extends AppCompatActivity implements IChatViewContract
|
|||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
presenter.onDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user