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 a15b133b..5e54d6d0 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 @@ -271,17 +271,6 @@ class AudioNoteActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_AUDIO) { return Note(name, mFileName, DbContract.NoteEntry.TYPE_AUDIO, category) } - override fun noteFromIntent(intent: Intent): Note { - return Note( - intent.getStringExtra(EXTRA_TITLE)!!, - intent.getStringExtra(EXTRA_CONTENT)!!, - DbContract.NoteEntry.TYPE_AUDIO, - intent.getIntExtra( - EXTRA_CATEGORY, 0 - ) - ) - } - override fun onSaveExternalStorage(basePath: File, name: String) { val file = File(basePath, "/$name.aac") try { 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 292a62df..1567df65 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 @@ -91,7 +91,6 @@ abstract class BaseNoteActivity(noteType: Int) : AppCompatActivity(), View.OnCli protected abstract fun updateNoteToSave(name: String, category: Int): Note? protected abstract fun onLoadActivity() protected abstract fun onSaveExternalStorage(basePath: File, name: String) - protected abstract fun noteFromIntent(intent: Intent): Note protected abstract fun shareNote(name: String): Intent protected abstract fun onNoteLoadedFromDB(note: Note) protected abstract fun onNewNote() @@ -438,33 +437,33 @@ abstract class BaseNoteActivity(noteType: Int) : AppCompatActivity(), View.OnCli private fun displayTrashDialog() { val sp = getSharedPreferences(PreferenceKeys.SP_DATA, MODE_PRIVATE) - val note = noteFromIntent(intent) - note._id = id - if (sp.getBoolean(PreferenceKeys.SP_DATA_DISPLAY_TRASH_MESSAGE, true)) { - //we never displayed the message before, so show it now - AlertDialog.Builder(this) - .setTitle(getString(R.string.dialog_trash_title)) - .setMessage(getString(R.string.dialog_trash_message)) - .setPositiveButton(R.string.dialog_ok) { _, _ -> - shouldSave = false - sp.edit().putBoolean(PreferenceKeys.SP_DATA_DISPLAY_TRASH_MESSAGE, false).apply() + createEditNoteViewModel.getNoteByID(id.toLong()).observe(this) { note -> + if (sp.getBoolean(PreferenceKeys.SP_DATA_DISPLAY_TRASH_MESSAGE, true)) { + //we never displayed the message before, so show it now + AlertDialog.Builder(this) + .setTitle(getString(R.string.dialog_trash_title)) + .setMessage(getString(R.string.dialog_trash_message)) + .setPositiveButton(R.string.dialog_ok) { _, _ -> + shouldSave = false + sp.edit().putBoolean(PreferenceKeys.SP_DATA_DISPLAY_TRASH_MESSAGE, false).apply() + note.in_trash = 1 + createEditNoteViewModel.update(note) + finish() + } + .setIcon(android.R.drawable.ic_dialog_alert) + .show() + sp.edit().putBoolean(PreferenceKeys.SP_DATA_DISPLAY_TRASH_MESSAGE, false).apply() + } else { + shouldSave = false + note.in_trash = intent.getIntExtra(EXTRA_ISTRASH, 0) + if (note.in_trash == 1) { + createEditNoteViewModel.delete(note) + } else { note.in_trash = 1 createEditNoteViewModel.update(note) - finish() } - .setIcon(android.R.drawable.ic_dialog_alert) - .show() - sp.edit().putBoolean(PreferenceKeys.SP_DATA_DISPLAY_TRASH_MESSAGE, false).apply() - } else { - shouldSave = false - note.in_trash = intent.getIntExtra(EXTRA_ISTRASH, 0) - if (note.in_trash == 1) { - createEditNoteViewModel.delete(note) - } else { - note.in_trash = 1 - createEditNoteViewModel.update(note) + finish() } - finish() } } 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 448dfd99..aaafef7a 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 @@ -208,17 +208,6 @@ class ChecklistNoteActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_CHECKLI return Note(name, jsonArray.toString(), DbContract.NoteEntry.TYPE_CHECKLIST, category) } - override fun noteFromIntent(intent: Intent): Note { - return Note( - intent.getStringExtra(EXTRA_TITLE)!!, - intent.getStringExtra(EXTRA_CONTENT)!!, - DbContract.NoteEntry.TYPE_CHECKLIST, - intent.getIntExtra( - EXTRA_CATEGORY, -1 - ) - ) - } - override fun onSaveExternalStorage(basePath: File, name: String) { val file = File(basePath, "/checklist_$name.txt") try { 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 7db27adc..a2884372 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 @@ -165,17 +165,6 @@ class SketchActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_SKETCH) { return Note(name, mFileName, DbContract.NoteEntry.TYPE_SKETCH, category) } - override fun noteFromIntent(intent: Intent): Note { - return Note( - intent.getStringExtra(EXTRA_TITLE)!!, - intent.getStringExtra(EXTRA_CONTENT)!!, - DbContract.NoteEntry.TYPE_SKETCH, - intent.getIntExtra( - EXTRA_CATEGORY, -1 - ) - ) - } - private fun displayColorDialog() { ColorPicker(this) .setOnFastChooseColorListener(object : OnFastChooseColorListener { 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 43141104..46fd5714 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 @@ -93,17 +93,6 @@ class TextNoteActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_TEXT) { adaptFontSize(etContent) } - override fun noteFromIntent(intent: Intent): Note { - return Note( - intent.getStringExtra(EXTRA_TITLE)!!, - intent.getStringExtra(EXTRA_CONTENT)!!, - DbContract.NoteEntry.TYPE_TEXT, - intent.getIntExtra( - EXTRA_CATEGORY, -1 - ) - ) - } - public override fun shareNote(name: String): Intent { val sendIntent = Intent() sendIntent.action = Intent.ACTION_SEND