Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ protected void onCreate(Bundle savedInstanceState) {
binding.buttonAdd.setOnClickListener(v -> {
String text = String.valueOf(binding.editTextNote.getText()).trim();
if (!text.isEmpty()) {
executor.execute(() -> {
db.noteDao().insert(new Note(text));
runOnUiThread(() -> {
binding.editTextNote.setText("");
loadNotes();
if (!executor.isShutdown()) {
executor.execute(() -> {
db.noteDao().insert(new Note(text));
runOnUiThread(() -> {
binding.editTextNote.setText("");
loadNotes();
});
});
});
}
}
});

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

private void loadNotes() {
executor.execute(() -> {
List<Note> notes = db.noteDao().getAll();
runOnUiThread(() -> adapter.setNotes(notes));
});
if (!executor.isShutdown()) {
executor.execute(() -> {
List<Note> notes = db.noteDao().getAll();
runOnUiThread(() -> adapter.setNotes(notes));
});
}
}

@Override
protected void onDestroy() {
super.onDestroy();
executor.shutdown();
}

private static class NotesAdapter extends RecyclerView.Adapter<NotesAdapter.NoteViewHolder> {
Expand Down