diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/room/NoteDatabase.java b/app/src/main/java/org/secuso/privacyfriendlynotes/room/NoteDatabase.java index 817e5e90..8e0e2529 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/room/NoteDatabase.java +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/room/NoteDatabase.java @@ -71,7 +71,7 @@ public void migrate(@NonNull SupportSQLiteDatabase database) { database.execSQL("DROP TABLE notes;"); database.execSQL("ALTER TABLE notes_new RENAME TO notes"); database.execSQL( - "CREATE TRIGGER [UpdateLastModified] AFTER UPDATE ON notes FOR EACH ROW WHEN NEW.last_modified = OLD.last_modified " + + "CREATE TRIGGER [UpdateLastModified] AFTER UPDATE ON notes FOR EACH ROW WHEN NEW.last_modified = OLD.last_modified AND NEW.custom_order = OLD.custom_order " + "BEGIN " + "UPDATE notes SET last_modified = DateTime('now') WHERE _id=NEW._id; " + "END;" diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/room/model/Note.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/room/model/Note.kt index 279f5b74..02b28d31 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/room/model/Note.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/room/model/Note.kt @@ -31,7 +31,6 @@ data class Note( var type: Int, var category: Int, var in_trash: Int = 0, - @ColumnInfo(defaultValue = "CURRENT_TIMESTAMP") var last_modified: String, var custom_order: Int ) { diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivity.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivity.kt index 4956603c..9459c026 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivity.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivity.kt @@ -83,6 +83,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte lateinit var adapter: NoteAdapter private val searchView: SearchView by lazy { findViewById(R.id.searchViewFilter) } private lateinit var fab: MainFABFragment + private var skipNextNoteFlow = false // A launcher to receive and react to a NoteActivity returning a category // The category is used to set the selectecCategory @@ -143,7 +144,12 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte recyclerView.adapter = adapter lifecycleScope.launch { - mainActivityViewModel.activeNotes.collect { notes -> adapter.setNotes(notes) } + mainActivityViewModel.activeNotes.collect { notes -> + if (!skipNextNoteFlow) { + adapter.setNotes(notes) + } + skipNextNoteFlow = false + } } val ith = ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP or ItemTouchHelper.DOWN, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) { @@ -156,6 +162,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte adapter.notes[from].custom_order = adapter.notes[to].custom_order adapter.notes[to].custom_order = temp Collections.swap(adapter.notes, from, to) + skipNextNoteFlow = true + mainActivityViewModel.updateAll(listOf(adapter.notes[from], adapter.notes[to])) adapter.notifyItemMoved(to, from) @@ -342,7 +350,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte override fun onPause() { // Save all changed orders if activity is paused - mainActivityViewModel.updateAll(adapter.notes) +// mainActivityViewModel.updateAll(adapter.notes) super.onPause() } diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivityViewModel.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivityViewModel.kt index 4d7eba83..b2f81967 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivityViewModel.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivityViewModel.kt @@ -112,13 +112,13 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica } fun insert(note: Note) { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { repository.noteDao().insert(note) } } fun update(note: Note) { - viewModelScope.launch(Dispatchers.Default) { + viewModelScope.launch(Dispatchers.IO) { repository.noteDao().update(note) } }