mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
fix #31, allow renaming notes
This commit is contained in:
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user