Skip to content

Commit

Permalink
better chat deletion logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DevEmperor committed Feb 6, 2024
1 parent 6c79673 commit bdbc735
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public void editTitle(View view) {
public void deleteChat(View view) {
chatHistoryDatabaseHelper.delete(this, id);
Toast.makeText(this, R.string.wristassist_chat_deleted, Toast.LENGTH_SHORT).show();
Intent data = new Intent();
data.putExtra("net.devemperor.wristassist.chat_deleted", true);
setResult(RESULT_OK, data);
finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected void onCreate(Bundle savedInstanceState) {
intent = new Intent(this, EditChatActivity.class);
}
intent.putExtra("net.devemperor.wristassist.chatId", chats.get(chatPosition).getId());
startActivity(intent);
startActivityForResult(intent, 1337);
});
savedChatsWrv.setAdapter(savedChatsAdapter);

Expand All @@ -68,10 +68,11 @@ protected void onCreate(Bundle savedInstanceState) {
});
}

@Override
protected void onResume() {
super.onResume();
if (savedChatsAdapter.getItemCount() != chatHistoryDatabaseHelper.getCount()) {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) return;

if (requestCode == 1337 && data.getBooleanExtra("net.devemperor.wristassist.chat_deleted", false)) {
savedChatsAdapter.getData().remove(currentEditPosition);
savedChatsAdapter.notifyItemRemoved(currentEditPosition);
findViewById(R.id.no_saved_chats).setVisibility(savedChatsAdapter.getData().isEmpty() ? android.view.View.VISIBLE : android.view.View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,4 @@ public List<ChatHistoryModel> getAllChats() {
db.close();
return chatHistoryModels;
}

public long getCount() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT COUNT(*) FROM CHAT_HISTORY_TABLE", null);
cursor.moveToFirst();
long count = cursor.getLong(0);
cursor.close();
db.close();
return count;
}
}

0 comments on commit bdbc735

Please sign in to comment.