Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Option to delete the last open note ([#157])
- Option to uncheck all checked items ([#156])

## [1.3.1] - 2025-07-12
Expand Down Expand Up @@ -64,6 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#99]: https://github.com/FossifyOrg/Notes/issues/99
[#110]: https://github.com/FossifyOrg/Notes/issues/110
[#156]: https://github.com/FossifyOrg/Notes/issues/156
[#157]: https://github.com/FossifyOrg/Notes/issues/157
[#164]: https://github.com/FossifyOrg/Notes/issues/164
[#178]: https://github.com/FossifyOrg/Notes/issues/178

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class MainActivity : SimpleActivity() {
private var searchIndex = 0
private var searchMatches = emptyList<Int>()
private var isSearchActive = false
private var wasNoteTextEmpty: Boolean = false

private lateinit var searchQueryET: MyEditText
private lateinit var searchPrevBtn: ImageView
Expand Down Expand Up @@ -252,6 +253,7 @@ class MainActivity : SimpleActivity() {
private fun refreshMenuItems() {
val multipleNotesExist = mNotes.size > 1
val isCurrentItemChecklist = isCurrentItemChecklist()
val isDefaultEmptyNote = isDefaultEmptyNote()

binding.mainToolbar.menu.apply {
findItem(R.id.undo).apply {
Expand All @@ -266,7 +268,6 @@ class MainActivity : SimpleActivity() {

findItem(R.id.rename_note).isVisible = multipleNotesExist
findItem(R.id.open_note).isVisible = multipleNotesExist
findItem(R.id.delete_note).isVisible = multipleNotesExist
findItem(R.id.open_search).isVisible = !isCurrentItemChecklist
findItem(R.id.remove_done_items).isVisible = isCurrentItemChecklist
findItem(R.id.uncheck_all_items).isVisible = isCurrentItemChecklist
Expand All @@ -278,6 +279,7 @@ class MainActivity : SimpleActivity() {
mNotes.isNotEmpty() && (::mCurrentNote.isInitialized && mCurrentNote.isLocked())
findItem(R.id.more_apps_from_us).isVisible =
!resources.getBoolean(org.fossify.commons.R.bool.hide_google_relations)
findItem(R.id.delete_note).isVisible = !isDefaultEmptyNote || mNotes.size > 1

saveNoteButton = findItem(R.id.save_note)
saveNoteButton!!.isVisible =
Expand Down Expand Up @@ -399,6 +401,16 @@ class MainActivity : SimpleActivity() {
}
}

private fun isDefaultEmptyNote(): Boolean {
return if (::mCurrentNote.isInitialized) {
(mCurrentNote.title == getString(R.string.general_note) &&
getCurrentNoteText().isNullOrEmpty() &&
mCurrentNote.value.isEmpty())
} else {
false
}
}

@SuppressLint("NewApi")
private fun checkShortcuts() {
val appIconColor = config.appIconColor
Expand Down Expand Up @@ -557,6 +569,7 @@ class MainActivity : SimpleActivity() {

mNotes = notes
mCurrentNote = mNotes[0]
wasNoteTextEmpty = mCurrentNote.value.isEmpty()
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes, this)
binding.viewPager.apply {
adapter = mAdapter
Expand Down Expand Up @@ -1339,7 +1352,7 @@ class MainActivity : SimpleActivity() {
}

fun deleteNote(deleteFile: Boolean, note: Note) {
if (mNotes.size <= 1 || note != mCurrentNote) {
if (mNotes.isEmpty() || note != mCurrentNote) {
return
}

Expand All @@ -1360,8 +1373,12 @@ class MainActivity : SimpleActivity() {
private fun doDeleteNote(note: Note, deleteFile: Boolean) {
ensureBackgroundThread {
val currentNoteIndex = mNotes.indexOf(note)
val noteToRefresh =

val noteToRefresh = if (mNotes.size == 1) {
null
} else {
mNotes[if (currentNoteIndex > 0) currentNoteIndex - 1 else currentNoteIndex + 1]
}

notesDB.deleteNote(note)
widgetsDB.deleteNoteWidgets(note.id!!)
Expand All @@ -1370,20 +1387,21 @@ class MainActivity : SimpleActivity() {
}
}

private fun refreshNotes(note: Note, deleteFile: Boolean) {
private fun refreshNotes(note: Note?, deleteFile: Boolean) {
NotesHelper(this).getNotes {
mNotes = it
val noteId = note.id
val currentNote = note ?: mNotes[0]
val noteId = currentNote.id
updateSelectedNote(noteId!!)
if (config.widgetNoteId == note.id) {
if (config.widgetNoteId == currentNote.id) {
config.widgetNoteId = mCurrentNote.id!!
updateWidgets()
}

initViewPager()

if (deleteFile) {
deleteFile(FileDirItem(note.path, note.title)) {
deleteFile(FileDirItem(currentNote.path, currentNote.title)) {
if (!it) {
toast(org.fossify.commons.R.string.unknown_error_occurred)
}
Expand Down Expand Up @@ -1541,6 +1559,14 @@ class MainActivity : SimpleActivity() {
}
}

if (getCurrentNoteText().isNullOrEmpty()) {
wasNoteTextEmpty = true
shouldRecreateMenu = true
} else if (wasNoteTextEmpty) {
wasNoteTextEmpty = false
shouldRecreateMenu = true
}

if (shouldRecreateMenu) {
refreshMenuItems()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.fossify.notes.helpers
import android.content.Context
import android.os.Handler
import android.os.Looper
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.fossify.commons.activities.BaseSimpleActivity
import org.fossify.commons.helpers.ExportResult
Expand Down Expand Up @@ -42,7 +41,8 @@ class NotesHelper(val context: Context) {
if (notes.isEmpty()) {
val generalNote = context.resources.getString(R.string.general_note)
val note = Note(null, generalNote, "", NoteType.TYPE_TEXT, "", PROTECTION_NONE, "")
context.notesDB.insertOrUpdate(note)
val insertedId = context.notesDB.insertOrUpdate(note)
note.id = insertedId
notes.add(note)
}

Expand Down
Loading