mirror of
https://github.com/ChronosX88/Influence-P2P.git
synced 2024-11-22 07:12:19 +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 {
|
||||
void sendMessage(MessageEntity message);
|
||||
void stopTrackingForNewMsgs();
|
||||
}
|
||||
|
@ -3,4 +3,5 @@ package io.github.chronosx88.influence.contracts.chatactivity;
|
||||
public interface IChatPresenterContract {
|
||||
void sendMessage(String text);
|
||||
void updateAdapter();
|
||||
void onDestroy();
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ public class ChatLogic implements IChatLogicContract {
|
||||
private ChatEntity chatEntity;
|
||||
private Thread checkNewMessagesThread = null;
|
||||
private KeyPairManager keyPairManager;
|
||||
private Timer timer;
|
||||
|
||||
public ChatLogic(ChatEntity chatEntity) {
|
||||
this.chatEntity = chatEntity;
|
||||
@ -44,7 +45,7 @@ public class ChatLogic implements IChatLogicContract {
|
||||
checkForNewMessages();
|
||||
}
|
||||
};
|
||||
Timer timer = new Timer();
|
||||
this.timer = new Timer();
|
||||
timer.schedule(timerTask, 1, 1000);
|
||||
this.keyPairManager = new KeyPairManager();
|
||||
}
|
||||
@ -167,4 +168,10 @@ public class ChatLogic implements IChatLogicContract {
|
||||
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
presenter.onDestroy();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user