@@ -147,6 +147,7 @@ class MainActivity : SimpleActivity() {
147
147
private var searchIndex = 0
148
148
private var searchMatches = emptyList<Int >()
149
149
private var isSearchActive = false
150
+ private var wasNoteTextEmpty: Boolean = false
150
151
151
152
private lateinit var searchQueryET: MyEditText
152
153
private lateinit var searchPrevBtn: ImageView
@@ -252,6 +253,7 @@ class MainActivity : SimpleActivity() {
252
253
private fun refreshMenuItems () {
253
254
val multipleNotesExist = mNotes.size > 1
254
255
val isCurrentItemChecklist = isCurrentItemChecklist()
256
+ val isDefaultEmptyNote = isDefaultEmptyNote()
255
257
256
258
binding.mainToolbar.menu.apply {
257
259
findItem(R .id.undo).apply {
@@ -266,7 +268,6 @@ class MainActivity : SimpleActivity() {
266
268
267
269
findItem(R .id.rename_note).isVisible = multipleNotesExist
268
270
findItem(R .id.open_note).isVisible = multipleNotesExist
269
- findItem(R .id.delete_note).isVisible = multipleNotesExist
270
271
findItem(R .id.open_search).isVisible = ! isCurrentItemChecklist
271
272
findItem(R .id.remove_done_items).isVisible = isCurrentItemChecklist
272
273
findItem(R .id.uncheck_all_items).isVisible = isCurrentItemChecklist
@@ -278,6 +279,7 @@ class MainActivity : SimpleActivity() {
278
279
mNotes.isNotEmpty() && (::mCurrentNote.isInitialized && mCurrentNote.isLocked())
279
280
findItem(R .id.more_apps_from_us).isVisible =
280
281
! resources.getBoolean(org.fossify.commons.R .bool.hide_google_relations)
282
+ findItem(R .id.delete_note).isVisible = ! isDefaultEmptyNote || mNotes.size > 1
281
283
282
284
saveNoteButton = findItem(R .id.save_note)
283
285
saveNoteButton!! .isVisible =
@@ -399,6 +401,16 @@ class MainActivity : SimpleActivity() {
399
401
}
400
402
}
401
403
404
+ private fun isDefaultEmptyNote (): Boolean {
405
+ return if (::mCurrentNote.isInitialized) {
406
+ (mCurrentNote.title == getString(R .string.general_note) &&
407
+ getCurrentNoteText().isNullOrEmpty() &&
408
+ mCurrentNote.value.isEmpty())
409
+ } else {
410
+ false
411
+ }
412
+ }
413
+
402
414
@SuppressLint(" NewApi" )
403
415
private fun checkShortcuts () {
404
416
val appIconColor = config.appIconColor
@@ -557,6 +569,7 @@ class MainActivity : SimpleActivity() {
557
569
558
570
mNotes = notes
559
571
mCurrentNote = mNotes[0 ]
572
+ wasNoteTextEmpty = mCurrentNote.value.isEmpty()
560
573
mAdapter = NotesPagerAdapter (supportFragmentManager, mNotes, this )
561
574
binding.viewPager.apply {
562
575
adapter = mAdapter
@@ -1339,7 +1352,7 @@ class MainActivity : SimpleActivity() {
1339
1352
}
1340
1353
1341
1354
fun deleteNote (deleteFile : Boolean , note : Note ) {
1342
- if (mNotes.size <= 1 || note != mCurrentNote) {
1355
+ if (mNotes.isEmpty() || note != mCurrentNote) {
1343
1356
return
1344
1357
}
1345
1358
@@ -1360,8 +1373,12 @@ class MainActivity : SimpleActivity() {
1360
1373
private fun doDeleteNote (note : Note , deleteFile : Boolean ) {
1361
1374
ensureBackgroundThread {
1362
1375
val currentNoteIndex = mNotes.indexOf(note)
1363
- val noteToRefresh =
1376
+
1377
+ val noteToRefresh = if (mNotes.size == 1 ) {
1378
+ null
1379
+ } else {
1364
1380
mNotes[if (currentNoteIndex > 0 ) currentNoteIndex - 1 else currentNoteIndex + 1 ]
1381
+ }
1365
1382
1366
1383
notesDB.deleteNote(note)
1367
1384
widgetsDB.deleteNoteWidgets(note.id!! )
@@ -1370,20 +1387,21 @@ class MainActivity : SimpleActivity() {
1370
1387
}
1371
1388
}
1372
1389
1373
- private fun refreshNotes (note : Note , deleteFile : Boolean ) {
1390
+ private fun refreshNotes (note : Note ? , deleteFile : Boolean ) {
1374
1391
NotesHelper (this ).getNotes {
1375
1392
mNotes = it
1376
- val noteId = note.id
1393
+ val currentNote = note ? : mNotes[0 ]
1394
+ val noteId = currentNote.id
1377
1395
updateSelectedNote(noteId!! )
1378
- if (config.widgetNoteId == note .id) {
1396
+ if (config.widgetNoteId == currentNote .id) {
1379
1397
config.widgetNoteId = mCurrentNote.id!!
1380
1398
updateWidgets()
1381
1399
}
1382
1400
1383
1401
initViewPager()
1384
1402
1385
1403
if (deleteFile) {
1386
- deleteFile(FileDirItem (note .path, note .title)) {
1404
+ deleteFile(FileDirItem (currentNote .path, currentNote .title)) {
1387
1405
if (! it) {
1388
1406
toast(org.fossify.commons.R .string.unknown_error_occurred)
1389
1407
}
@@ -1541,6 +1559,14 @@ class MainActivity : SimpleActivity() {
1541
1559
}
1542
1560
}
1543
1561
1562
+ if (getCurrentNoteText().isNullOrEmpty()) {
1563
+ wasNoteTextEmpty = true
1564
+ shouldRecreateMenu = true
1565
+ } else if (wasNoteTextEmpty) {
1566
+ wasNoteTextEmpty = false
1567
+ shouldRecreateMenu = true
1568
+ }
1569
+
1544
1570
if (shouldRecreateMenu) {
1545
1571
refreshMenuItems()
1546
1572
}
0 commit comments