mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-03 10:27:44 +01:00
fix #31, allow renaming notes
This commit is contained in:
parent
fa02e14b9a
commit
80dbf7b300
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
18
app/src/main/res/layout/rename_note.xml
Normal file
18
app/src/main/res/layout/rename_note.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/dialog_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/note_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:inputType="textCapSentences"
|
||||
android:singleLine="true"/>
|
||||
|
||||
</LinearLayout>
|
@ -7,15 +7,20 @@
|
||||
android:title="@string/share"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/delete_note"
|
||||
android:icon="@mipmap/delete"
|
||||
android:title="@string/delete_note"
|
||||
app:showAsAction="never"/>
|
||||
android:id="@+id/rename_note"
|
||||
android:icon="@mipmap/rename"
|
||||
android:title="@string/rename"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/share"
|
||||
android:icon="@mipmap/share"
|
||||
android:title="@string/share"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/delete_note"
|
||||
android:icon="@mipmap/delete"
|
||||
android:title="@string/delete_note"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/change_widget_note"
|
||||
android:title="@string/change_widget_note"
|
||||
|
BIN
app/src/main/res/mipmap-hdpi/rename.png
Normal file
BIN
app/src/main/res/mipmap-hdpi/rename.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 214 B |
BIN
app/src/main/res/mipmap-mdpi/rename.png
Normal file
BIN
app/src/main/res/mipmap-mdpi/rename.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 165 B |
BIN
app/src/main/res/mipmap-xhdpi/rename.png
Normal file
BIN
app/src/main/res/mipmap-xhdpi/rename.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 239 B |
BIN
app/src/main/res/mipmap-xxhdpi/rename.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/rename.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 302 B |
BIN
app/src/main/res/mipmap-xxxhdpi/rename.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/rename.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 355 B |
@ -21,6 +21,8 @@
|
||||
<string name="current_note">Aktuelle Notiz:</string>
|
||||
<string name="change_widget_note">Wechsel Notiz des Widgets</string>
|
||||
<string name="pick_a_note_for_widget">Wähle Notiz für das Widget</string>
|
||||
<string name="rename">Rename</string>
|
||||
<string name="rename_note">Rename note</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Einstellungen</string>
|
||||
|
@ -21,6 +21,8 @@
|
||||
<string name="current_note">Nota actual:</string>
|
||||
<string name="change_widget_note">Cambiar la nota del widget</string>
|
||||
<string name="pick_a_note_for_widget">Seleccione una nota para el widget</string>
|
||||
<string name="rename">Rename</string>
|
||||
<string name="rename_note">Rename note</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Opciones</string>
|
||||
|
@ -21,6 +21,8 @@
|
||||
<string name="current_note">Current note:</string>
|
||||
<string name="change_widget_note">Change widget\'s note</string>
|
||||
<string name="pick_a_note_for_widget">Pick a note for the widget</string>
|
||||
<string name="rename">Rename</string>
|
||||
<string name="rename_note">Rename note</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Impostazioni</string>
|
||||
|
@ -21,6 +21,8 @@
|
||||
<string name="current_note">現在のメモ:</string>
|
||||
<string name="change_widget_note">ウィジェットのメモを変更</string>
|
||||
<string name="pick_a_note_for_widget">ウィジェットのメモを選択</string>
|
||||
<string name="rename">Rename</string>
|
||||
<string name="rename_note">Rename note</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">設定</string>
|
||||
|
@ -21,6 +21,8 @@
|
||||
<string name="current_note">Nota atual:</string>
|
||||
<string name="change_widget_note">Alterar nota do widget</string>
|
||||
<string name="pick_a_note_for_widget">Escolha uma nota para o widget</string>
|
||||
<string name="rename">Rename</string>
|
||||
<string name="rename_note">Rename note</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Definições</string>
|
||||
|
@ -21,6 +21,8 @@
|
||||
<string name="current_note">Current note:</string>
|
||||
<string name="change_widget_note">Change widget\'s note</string>
|
||||
<string name="pick_a_note_for_widget">Pick a note for the widget</string>
|
||||
<string name="rename">Rename</string>
|
||||
<string name="rename_note">Rename note</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Inställningar</string>
|
||||
|
@ -21,6 +21,8 @@
|
||||
<string name="current_note">Current note:</string>
|
||||
<string name="change_widget_note">Change widget\'s note</string>
|
||||
<string name="pick_a_note_for_widget">Pick a note for the widget</string>
|
||||
<string name="rename">Rename</string>
|
||||
<string name="rename_note">Rename note</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Settings</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user