Skip to content

Commit

Permalink
Merge pull request #129 from SecUSo/FixNPENoteFromIntent
Browse files Browse the repository at this point in the history
Fixed the NPE in noteFromIntent caused by empty extras.
  • Loading branch information
coderPaddyS authored Dec 2, 2022
2 parents 1c86d9d + cd4627a commit 53cbd07
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 53cbd07

Please sign in to comment.