fix #249, allow renaming checklist items

This commit is contained in:
tibbi 2018-12-26 23:34:04 +01:00
parent aedf7b7d79
commit 02c73cdec0
4 changed files with 70 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.dialogs.RenameChecklistItemDialog
import com.simplemobiletools.notes.pro.helpers.DONE_CHECKLIST_ITEM_ALPHA
import com.simplemobiletools.notes.pro.interfaces.ChecklistItemsListener
import com.simplemobiletools.notes.pro.models.ChecklistItem
@ -77,7 +78,14 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
}
private fun renameChecklistItem() {
val item = getSelectedItems().first()
RenameChecklistItemDialog(activity, item.title) {
val position = getSelectedItemPositions().first()
item.title = it
listener?.saveChecklist()
notifyItemChanged(position)
finishActMode()
}
}
private fun deleteSelection() {

View File

@ -23,7 +23,7 @@ class NewChecklistItemDialog(val activity: Activity, callback: (title: String) -
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.checklist_item_title.value
when {
title.isEmpty() -> activity.toast(R.string.no_title)
title.isEmpty() -> activity.toast(R.string.empty_name)
else -> {
callback(title)
dismiss()

View File

@ -0,0 +1,38 @@
package com.simplemobiletools.notes.pro.dialogs
import android.app.Activity
import android.content.DialogInterface.BUTTON_POSITIVE
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.showKeyboard
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.notes.pro.R
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.*
class RenameChecklistItemDialog(val activity: Activity, val oldTitle: String, callback: (newTitle: String) -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_checklist_item, null).apply {
checklist_item_title.setText(oldTitle)
}
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this) {
showKeyboard(view.checklist_item_title)
getButton(BUTTON_POSITIVE).setOnClickListener {
val newTitle = view.checklist_item_title.value
when {
newTitle.isEmpty() -> activity.toast(R.string.empty_name)
else -> {
callback(newTitle)
dismiss()
}
}
}
}
}
}
}

View File

@ -0,0 +1,22 @@
<?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:paddingLeft="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/checklist_item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/small_margin"
android:layout_marginBottom="@dimen/small_margin"
android:inputType="textCapSentences"
android:textCursorDrawable="@null"
android:textSize="@dimen/bigger_text_size"/>
</LinearLayout>