minor code cleanup

This commit is contained in:
tibbi 2017-06-18 21:28:10 +02:00
parent 63606269de
commit dbdfc7b49f
2 changed files with 7 additions and 9 deletions

View File

@ -69,20 +69,22 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
private fun handleText(text: String) {
val notes = DBHelper.newInstance(this@MainActivity).getNotes()
val notes = mDb.getNotes()
val list = arrayListOf<RadioItem>().apply {
add(RadioItem(0, getString(R.string.create_new_note)))
notes.forEachIndexed { index, note -> add(RadioItem(index + 1, note.title)) }
notes.forEachIndexed { index, note ->
add(RadioItem(index + 1, note.title))
}
}
RadioGroupDialog(this@MainActivity, list, -1, R.string.add_to_note, {
RadioGroupDialog(this, list, -1, R.string.add_to_note) {
if (it as Int == 0) {
displayNewNoteDialog(text)
} else {
updateSelectedNote(notes[it - 1].id)
addTextToCurrentNote(if (mCurrentNote.value.isEmpty()) text else "\n$text")
}
}).create()
}
}
private fun initViewPager() {

View File

@ -36,11 +36,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
fun getCurrentNoteViewText(position: Int) = fragments[position]?.getCurrentNoteViewText()
fun appendText(position: Int, text: String) {
val fragment = fragments[position]
val finalText = fragment?.getCurrentNoteViewText() + text
fragment?.getNotesView()?.setText(finalText)
}
fun appendText(position: Int, text: String) = fragments[position]?.getNotesView()?.append(text)
fun saveCurrentNote(position: Int) = fragments[position]?.saveText()