couple code style updates

This commit is contained in:
tibbi 2017-09-18 20:00:39 +02:00
parent a13ea825ea
commit 8ed2901389
3 changed files with 15 additions and 15 deletions

View File

@ -36,9 +36,9 @@ import java.io.File
import java.nio.charset.Charset import java.nio.charset.Charset
class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
private val STORAGE_OPEN_FILE_ACTION = 0
private val STORAGE_OPEN_FILE = 1 private val STORAGE_OPEN_FILE = 1
private val STORAGE_EXPORT_AS_FILE = 2 private val STORAGE_OPEN_FILE_ACTION = 2
private val STORAGE_EXPORT_AS_FILE = 3
private var openFilePath = "" private var openFilePath = ""
private var mAdapter: NotesPagerAdapter? = null private var mAdapter: NotesPagerAdapter? = null
@ -267,13 +267,14 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
} }
private fun importFileWithSync(path: String) { private fun importFileWithSync(path: String) {
openFile(path, false, { openFile(path, false) {
var title = path.getFilenameFromPath() var title = path.getFilenameFromPath()
if (mDb.doesTitleExist(title)) title += " (file)" if (mDb.doesTitleExist(title))
title += " (file)"
val note = Note(0, title, "", TYPE_NOTE, path) val note = Note(0, title, "", TYPE_NOTE, path)
addNewNote(note) addNewNote(note)
}) }
} }
private fun tryExportAsFile() { private fun tryExportAsFile() {
@ -286,8 +287,9 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
private fun exportAsFile() { private fun exportAsFile() {
ExportAsDialog(this, mCurrentNote) { ExportAsDialog(this, mCurrentNote) {
if (getCurrentNoteText()?.isNotEmpty() == true) if (getCurrentNoteText()?.isNotEmpty() == true) {
exportNoteValueToFile(it, getCurrentNoteText()!!) exportNoteValueToFile(it, getCurrentNoteText()!!)
}
} }
} }
@ -371,7 +373,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
} }
private fun getNoteIndexWithId(id: Int): Int { private fun getNoteIndexWithId(id: Int): Int {
for (i in 0..mNotes.count() - 1) { for (i in 0 until mNotes.count()) {
if (mNotes[i].id == id) { if (mNotes[i].id == id) {
mCurrentNote = mNotes[i] mCurrentNote = mNotes[i]
return i return i
@ -402,12 +404,10 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
super.onRequestPermissionsResult(requestCode, permissions, grantResults) super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (requestCode == STORAGE_OPEN_FILE) { when (requestCode) {
openFile() STORAGE_OPEN_FILE -> openFile()
} else if (requestCode == STORAGE_EXPORT_AS_FILE) { STORAGE_EXPORT_AS_FILE -> exportAsFile()
exportAsFile() STORAGE_OPEN_FILE_ACTION -> importFileWithSync(openFilePath)
} else if (requestCode == STORAGE_OPEN_FILE_ACTION) {
importFileWithSync(openFilePath)
} }
} }
} }

View File

@ -26,7 +26,7 @@ import kotlinx.android.synthetic.main.fragment_note.view.*
import java.io.File import java.io.File
class NoteFragment : Fragment() { class NoteFragment : Fragment() {
var noteId = 0 private var noteId = 0
lateinit var note: Note lateinit var note: Note
lateinit var view: ViewGroup lateinit var view: ViewGroup
lateinit var mDb: DBHelper lateinit var mDb: DBHelper

View File

@ -169,7 +169,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
updateNote(note.id, values) updateNote(note.id, values)
} }
fun updateNote(id: Int, values: ContentValues) { private fun updateNote(id: Int, values: ContentValues) {
val selection = "$COL_ID = ?" val selection = "$COL_ID = ?"
val selectionArgs = arrayOf(id.toString()) val selectionArgs = arrayOf(id.toString())
mDb.update(TABLE_NAME, values, selection, selectionArgs) mDb.update(TABLE_NAME, values, selection, selectionArgs)