Skip to content

Commit 711a296

Browse files
committed
read-only implementation (2)
1 parent 3439158 commit 711a296

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import org.fossify.notes.databases.NotesDatabase
4343
import org.fossify.notes.databinding.ActivityMainBinding
4444
import org.fossify.notes.dialogs.*
4545
import org.fossify.notes.extensions.*
46-
import org.fossify.notes.fragments.NoteFragment
4746
import org.fossify.notes.fragments.TextFragment
4847
import org.fossify.notes.helpers.*
4948
import org.fossify.notes.models.Note
@@ -92,7 +91,6 @@ class MainActivity : SimpleActivity() {
9291
super.onCreate(savedInstanceState)
9392
setContentView(binding.root)
9493
appLaunched(BuildConfig.APPLICATION_ID)
95-
9694
setupOptionsMenu()
9795
refreshMenuItems()
9896

@@ -492,14 +490,6 @@ class MainActivity : SimpleActivity() {
492490
}
493491
}
494492

495-
private fun checkReadOnlyState() {
496-
getCurrentFragment()?.apply {
497-
if (this is TextFragment) {
498-
(this as TextFragment).getNotesView().isEnabled = !mCurrentNote.isReadOnly
499-
}
500-
}
501-
}
502-
503493
private fun setupSearchButtons() {
504494
searchQueryET.onTextChangeListener {
505495
searchTextChanged(it)
@@ -1329,6 +1319,14 @@ class MainActivity : SimpleActivity() {
13291319
}
13301320
}
13311321

1322+
private fun checkReadOnlyState() {
1323+
getCurrentFragment()?.apply {
1324+
if (this is TextFragment) {
1325+
(this as TextFragment).getNotesView().isEnabled = !mCurrentNote.isReadOnly
1326+
}
1327+
}
1328+
}
1329+
13321330
private fun toggleReadOnly() {
13331331
mCurrentNote.isReadOnly = !mCurrentNote.isReadOnly
13341332
NotesHelper(this).insertOrUpdateNote(mCurrentNote) {

app/src/main/kotlin/org/fossify/notes/helpers/NotesHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ class NotesHelper(val context: Context) {
7272

7373
fun insertOrUpdateNote(note: Note, callback: ((newNoteId: Long) -> Unit)? = null) {
7474
ensureBackgroundThread {
75+
val noteId = context.notesDB.insertOrUpdate(note)
7576
if (note.isReadOnly) {
7677
Handler(Looper.getMainLooper()).post {
77-
callback?.invoke(note.id ?: -1L)
78+
callback?.invoke(noteId)
7879
}
7980
} else {
80-
val noteId = context.notesDB.insertOrUpdate(note)
8181
Handler(Looper.getMainLooper()).post {
8282
callback?.invoke(noteId)
8383
}

0 commit comments

Comments
 (0)