diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/AudioNoteActivity.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/AudioNoteActivity.kt index 9d27e02b..a15b133b 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/AudioNoteActivity.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/AudioNoteActivity.kt @@ -130,13 +130,10 @@ class AudioNoteActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_AUDIO) { return sendIntent } - override fun determineToSaveOnAction(category: Int): Pair { + override fun determineToSave(title: String, category: Int): Pair { val intent = intent return Pair( - seekBar.isEnabled || category != intent.getIntExtra( - EXTRA_CATEGORY, - -1 - ) && -5 != intent.getIntExtra( + seekBar.isEnabled && -5 != intent.getIntExtra( EXTRA_CATEGORY, -5 ), R.string.toast_emptyNote diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/BaseNoteActivity.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/BaseNoteActivity.kt index f5961f5c..292a62df 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/BaseNoteActivity.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/BaseNoteActivity.kt @@ -95,7 +95,7 @@ abstract class BaseNoteActivity(noteType: Int) : AppCompatActivity(), View.OnCli protected abstract fun shareNote(name: String): Intent protected abstract fun onNoteLoadedFromDB(note: Note) protected abstract fun onNewNote() - protected abstract fun determineToSaveOnAction(category: Int): Pair + protected abstract fun determineToSave(title: String, category: Int): Pair override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -284,13 +284,8 @@ abstract class BaseNoteActivity(noteType: Int) : AppCompatActivity(), View.OnCli finish() } R.id.action_save -> { - val (toSave, mes) = determineToSaveOnAction(if (currentCat >= 0) currentCat else savedCat) - if (toSave) { - shouldSave = true - finish() - } else { - Toast.makeText(applicationContext, mes, Toast.LENGTH_SHORT).show() - } + shouldSave = true + finish() } else -> {} } @@ -367,8 +362,16 @@ abstract class BaseNoteActivity(noteType: Int) : AppCompatActivity(), View.OnCli } private fun saveOrUpdateNote() { - if (edit) updateNote() - else saveNote() + val (toSave, mes) = determineToSave(etName.text.toString(), if (currentCat >= 0) currentCat else savedCat) + if (toSave) { + if (etName.text.isEmpty()) { + etName.setText(generateStandardName()) + } + if (edit) updateNote() + else saveNote() + } else { + Toast.makeText(applicationContext, mes, Toast.LENGTH_SHORT).show() + } } private fun saveNote() { @@ -383,7 +386,7 @@ abstract class BaseNoteActivity(noteType: Int) : AppCompatActivity(), View.OnCli private fun updateNote() { val note = updateNoteToSave( - if (etName.text.isEmpty()) generateStandardName() else etName.text.toString(), + etName.text.toString(), if (currentCat >= 0) currentCat else savedCat ) insertNoteIntoDB(note) diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/ChecklistNoteActivity.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/ChecklistNoteActivity.kt index 13a4420c..448dfd99 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/ChecklistNoteActivity.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/ChecklistNoteActivity.kt @@ -147,15 +147,10 @@ class ChecklistNoteActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_CHECKLI } } - override fun determineToSaveOnAction(category: Int): Pair { + override fun determineToSave(title: String, category: Int): Pair { val intent = intent return Pair( - category != intent.getIntExtra( - EXTRA_CATEGORY, - -1 - ) && -5 != intent.getIntExtra( - EXTRA_CATEGORY, -5 - ), + (title.isNotEmpty() || !checklistAdapter.isEmpty) && -5 != intent.getIntExtra(EXTRA_CATEGORY, -5), R.string.toast_emptyNote ) } diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/SketchActivity.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/SketchActivity.kt index 4018d46e..7db27adc 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/SketchActivity.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/SketchActivity.kt @@ -106,7 +106,7 @@ class SketchActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_SKETCH) { return sendIntent } - override fun determineToSaveOnAction(category: Int): Pair { + override fun determineToSave(title: String, category: Int): Pair { val emptyBitmap = Bitmap.createBitmap( drawView.bitmap.width, drawView.bitmap.height, @@ -114,7 +114,7 @@ class SketchActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_SKETCH) { ) val intent = intent return Pair( - !drawView.bitmap.sameAs(emptyBitmap) || -5 != intent.getIntExtra(EXTRA_CATEGORY, -5), + !drawView.bitmap.sameAs(emptyBitmap) && -5 != intent.getIntExtra(EXTRA_CATEGORY, -5), R.string.toast_emptyNote ) } diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/TextNoteActivity.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/TextNoteActivity.kt index cb1e18c2..43141104 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/TextNoteActivity.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/notes/TextNoteActivity.kt @@ -112,11 +112,10 @@ class TextNoteActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_TEXT) { return sendIntent } - override fun determineToSaveOnAction(category: Int): Pair { + override fun determineToSave(title: String, category: Int): Pair { val intent = intent return Pair( - category != intent.getIntExtra(EXTRA_CATEGORY, -1) - && -5 != intent.getIntExtra(EXTRA_CATEGORY, -5), + (title.isNotEmpty() || Html.toHtml(etContent.text) != "") && -5 != intent.getIntExtra(EXTRA_CATEGORY, -5), R.string.toast_emptyNote ) }