minor code style and strings update

This commit is contained in:
tibbi
2017-09-22 22:52:49 +02:00
parent 5b3040ee9e
commit 1ee9524a15
17 changed files with 80 additions and 106 deletions

View File

@ -139,7 +139,6 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun getCurrentWidgetNoteTitle(currentNoteId: Int, notes: List<Note>): String {
return notes.firstOrNull { it.id == currentNoteId }?.title ?: ""
}
private fun getCurrentWidgetNoteTitle(currentNoteId: Int, notes: List<Note>) =
notes.firstOrNull { it.id == currentNoteId }?.title ?: ""
}

View File

@ -23,13 +23,13 @@ class NewNoteDialog(val activity: Activity, val db: DBHelper, callback: (title:
activity.setupDialogStuff(view, this, R.string.new_note)
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.note_name.value
if (title.isEmpty()) {
activity.toast(R.string.no_title)
} else if (db.doesTitleExist(title)) {
activity.toast(R.string.title_taken)
} else {
callback(title)
dismiss()
when {
title.isEmpty() -> activity.toast(R.string.no_title)
db.doesTitleExist(title) -> activity.toast(R.string.title_taken)
else -> {
callback(title)
dismiss()
}
}
}
}

View File

@ -25,39 +25,39 @@ class RenameNoteDialog(val activity: SimpleActivity, val db: DBHelper, val note:
activity.setupDialogStuff(view, this, R.string.rename_note)
getButton(BUTTON_POSITIVE).setOnClickListener({
val title = view.note_name.value
if (title.isEmpty()) {
activity.toast(R.string.no_title)
} else if (db.doesTitleExist(title)) {
activity.toast(R.string.title_taken)
} else {
note.title = title
val path = note.path
if (path.isNotEmpty()) {
if (title.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty)
return@setOnClickListener
}
when {
title.isEmpty() -> activity.toast(R.string.no_title)
db.doesTitleExist(title) -> activity.toast(R.string.title_taken)
else -> {
note.title = title
val path = note.path
if (path.isNotEmpty()) {
if (title.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty)
return@setOnClickListener
}
val file = File(path)
val newFile = File(file.parent, title)
if (!newFile.name.isAValidFilename()) {
activity.toast(R.string.invalid_name)
return@setOnClickListener
}
val file = File(path)
val newFile = File(file.parent, title)
if (!newFile.name.isAValidFilename()) {
activity.toast(R.string.invalid_name)
return@setOnClickListener
}
activity.renameFile(file, newFile) {
if (it) {
note.path = newFile.absolutePath
db.updateNotePath(note)
} else {
activity.toast(R.string.rename_file_error)
return@renameFile
activity.renameFile(file, newFile) {
if (it) {
note.path = newFile.absolutePath
db.updateNotePath(note)
} else {
activity.toast(R.string.rename_file_error)
return@renameFile
}
}
}
db.updateNoteTitle(note)
dismiss()
callback(note)
}
db.updateNoteTitle(note)
dismiss()
callback(note)
}
})
}

View File

@ -45,12 +45,10 @@ class MyWidgetProvider : AppWidgetProvider() {
super.onUpdate(context, appWidgetManager, appWidgetIds)
}
private fun getProperTextView(context: Context): Int {
return when (context.config.gravity) {
GRAVITY_CENTER -> R.id.notes_view_center
GRAVITY_RIGHT -> R.id.notes_view_right
else -> R.id.notes_view_left
}
private fun getProperTextView(context: Context) = when (context.config.gravity) {
GRAVITY_CENTER -> R.id.notes_view_center
GRAVITY_RIGHT -> R.id.notes_view_right
else -> R.id.notes_view_left
}
private fun initVariables(context: Context) {