diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt index 48815be1..e481fc86 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt @@ -19,6 +19,7 @@ import com.simplemobiletools.notes.TYPE_NOTE import com.simplemobiletools.notes.databases.DBHelper import com.simplemobiletools.notes.dialogs.NewNoteDialog import com.simplemobiletools.notes.dialogs.OpenNoteDialog +import com.simplemobiletools.notes.dialogs.RenameNoteDialog import com.simplemobiletools.notes.dialogs.WidgetNoteDialog import com.simplemobiletools.notes.extensions.getTextSize import com.simplemobiletools.notes.models.Note @@ -71,6 +72,7 @@ class MainActivity : SimpleActivity() { override fun onPrepareOptionsMenu(menu: Menu): Boolean { val shouldBeVisible = mNotes.size > 1 menu.apply { + findItem(R.id.rename_note).isVisible = shouldBeVisible findItem(R.id.open_note).isVisible = shouldBeVisible findItem(R.id.delete_note).isVisible = shouldBeVisible findItem(R.id.change_widget_note).isVisible = shouldBeVisible @@ -81,14 +83,14 @@ class MainActivity : SimpleActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { - R.id.delete_note -> { - displayDeleteNotePrompt() - true - } R.id.open_note -> { displayOpenNoteDialog() true } + R.id.rename_note -> { + displayRenameDialog() + true + } R.id.share -> { shareText() true @@ -97,6 +99,10 @@ class MainActivity : SimpleActivity() { showWidgetNotePicker() true } + R.id.delete_note -> { + displayDeleteNotePrompt() + true + } R.id.settings -> { startActivity(Intent(applicationContext, SettingsActivity::class.java)) true @@ -113,6 +119,13 @@ class MainActivity : SimpleActivity() { WidgetNoteDialog(this) } + private fun displayRenameDialog() { + RenameNoteDialog(this, mDb, mCurrentNote!!) { + mCurrentNote = it + current_note_title.text = it.title + } + } + private fun updateSelectedNote(id: Int) { saveText() mCurrentNote = mDb.getNote(id) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/databases/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/notes/databases/DBHelper.kt index 0fae7709..4a124a09 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/databases/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/databases/DBHelper.kt @@ -126,7 +126,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe fun updateNote(note: Note) { val values = fillContentValues(note) - val selection = COL_ID + " = ?" + val selection = "$COL_ID = ?" val selectionArgs = arrayOf(note.id.toString()) mDb.update(TABLE_NAME, values, selection, selectionArgs) } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt new file mode 100644 index 00000000..069be3e8 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/notes/dialogs/RenameNoteDialog.kt @@ -0,0 +1,43 @@ +package com.simplemobiletools.notes.dialogs + +import android.app.Activity +import android.app.AlertDialog +import android.view.LayoutInflater +import android.view.WindowManager +import com.simplemobiletools.filepicker.extensions.toast +import com.simplemobiletools.filepicker.extensions.value +import com.simplemobiletools.notes.R +import com.simplemobiletools.notes.databases.DBHelper +import com.simplemobiletools.notes.models.Note +import kotlinx.android.synthetic.main.new_note.view.* + +class RenameNoteDialog(val activity: Activity, val db: DBHelper, val note: Note, callback: (note: Note) -> Unit) { + + init { + val view = LayoutInflater.from(activity).inflate(R.layout.rename_note, null) + view.note_name.setText(note.title) + + AlertDialog.Builder(activity) + .setTitle(activity.resources.getString(R.string.rename_note)) + .setView(view) + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .create().apply { + window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) + show() + getButton(AlertDialog.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 + db.updateNote(note) + dismiss() + callback.invoke(note) + } + }) + } + } +} diff --git a/app/src/main/res/layout/rename_note.xml b/app/src/main/res/layout/rename_note.xml new file mode 100644 index 00000000..fcddaf46 --- /dev/null +++ b/app/src/main/res/layout/rename_note.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml index c08b68c9..b3051b81 100644 --- a/app/src/main/res/menu/menu.xml +++ b/app/src/main/res/menu/menu.xml @@ -7,15 +7,20 @@ android:title="@string/share" app:showAsAction="ifRoom"/> + android:id="@+id/rename_note" + android:icon="@mipmap/rename" + android:title="@string/rename" + app:showAsAction="ifRoom"/> + Aktuelle Notiz: Wechsel Notiz des Widgets Wähle Notiz für das Widget + Rename + Rename note Einstellungen diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index ba7e3b7b..39829045 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -21,6 +21,8 @@ Nota actual: Cambiar la nota del widget Seleccione una nota para el widget + Rename + Rename note Opciones diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 37d9d6d7..1bc81771 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -21,6 +21,8 @@ Current note: Change widget\'s note Pick a note for the widget + Rename + Rename note Impostazioni diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 453a3ba5..23f864e5 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -21,6 +21,8 @@ 現在のメモ: ウィジェットのメモを変更 ウィジェットのメモを選択 + Rename + Rename note 設定 diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 09b42718..b4e8429c 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -21,6 +21,8 @@ Nota atual: Alterar nota do widget Escolha uma nota para o widget + Rename + Rename note Definições diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 03040fd5..c371cc2b 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -21,6 +21,8 @@ Current note: Change widget\'s note Pick a note for the widget + Rename + Rename note Inställningar diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index afebcf44..cbc8746a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -21,6 +21,8 @@ Current note: Change widget\'s note Pick a note for the widget + Rename + Rename note Settings