Use checkboxes in checklists

This commit is contained in:
Naveen
2024-04-12 16:46:42 +05:30
parent 2c20460388
commit 9dda3d71f4
4 changed files with 32 additions and 31 deletions

View File

@@ -2,7 +2,6 @@ package org.fossify.notes.adapters
import android.annotation.SuppressLint
import android.graphics.Paint
import android.graphics.drawable.Drawable
import android.util.TypedValue
import android.view.Menu
import android.view.MotionEvent
@@ -14,7 +13,6 @@ import org.fossify.commons.activities.BaseSimpleActivity
import org.fossify.commons.adapters.MyRecyclerViewAdapter
import org.fossify.commons.extensions.applyColorFilter
import org.fossify.commons.extensions.beVisibleIf
import org.fossify.commons.extensions.getColoredDrawableWithColor
import org.fossify.commons.extensions.removeBit
import org.fossify.commons.helpers.SORT_BY_CUSTOM
import org.fossify.commons.interfaces.ItemMoveCallback
@@ -40,14 +38,11 @@ class ChecklistAdapter(
itemClick: (Any) -> Unit,
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick), ItemTouchHelperContract {
private lateinit var crossDrawable: Drawable
private lateinit var checkDrawable: Drawable
private var touchHelper: ItemTouchHelper? = null
private var startReorderDragListener: StartReorderDragListener
init {
setupDragListener(true)
initDrawables()
touchHelper = ItemTouchHelper(ItemMoveCallback(this))
touchHelper!!.attachToRecyclerView(recyclerView)
@@ -116,18 +111,6 @@ class ChecklistAdapter(
override fun getItemCount() = items.size
private fun initDrawables() {
val res = activity.resources
crossDrawable = res.getColoredDrawableWithColor(
org.fossify.commons.R.drawable.ic_cross_vector,
res.getColor(org.fossify.commons.R.color.md_red_700)
)
checkDrawable = res.getColoredDrawableWithColor(
org.fossify.commons.R.drawable.ic_check_vector,
res.getColor(org.fossify.commons.R.color.md_green_700)
)
}
private fun renameChecklistItem() {
val item = getSelectedItems().first()
RenameChecklistItemDialog(activity, item.title) {
@@ -222,13 +205,14 @@ class ChecklistAdapter(
}
}
checklistImage.setImageDrawable(if (checklistItem.isDone) checkDrawable else crossDrawable)
checklistImage.beVisibleIf(showIcons && selectedKeys.isEmpty())
checklistCross.applyColorFilter(textColor)
checklistCross.beVisibleIf(showIcons && selectedKeys.isEmpty())
checklistCheckbox.isChecked = checklistItem.isDone
checklistHolder.isSelected = isSelected
checklistDragHandle.beVisibleIf(selectedKeys.isNotEmpty())
checklistDragHandle.applyColorFilter(textColor)
checklistDragHandle.setOnTouchListener { v, event ->
checklistDragHandle.setOnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
startReorderDragListener.requestDrag(holder)
}

View File

@@ -61,6 +61,7 @@
android:layout_height="match_parent"
android:clipToPadding="false"
android:overScrollMode="never"
android:paddingTop="@dimen/small_margin"
android:paddingBottom="@dimen/secondary_fab_bottom_margin"
android:visibility="gone"
app:layoutManager="org.fossify.commons.views.MyLinearLayoutManager" />

View File

@@ -9,26 +9,41 @@
android:clickable="true"
android:focusable="true"
android:foreground="@drawable/selector"
android:paddingEnd="@dimen/normal_margin">
android:minHeight="@dimen/checklist_height"
android:paddingStart="@dimen/normal_margin"
android:paddingEnd="@dimen/small_margin">
<org.fossify.commons.views.MyAppCompatCheckbox
android:id="@+id/checklist_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/tiny_margin"
android:background="@null"
android:clickable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<org.fossify.commons.views.MyTextView
android:id="@+id/checklist_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingStart="@dimen/activity_margin"
android:textSize="@dimen/bigger_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/checklist_image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/checklist_cross"
app:layout_constraintStart_toEndOf="@id/checklist_checkbox"
app:layout_constraintTop_toTopOf="parent"
tools:text="Butter" />
tools:text="Apples 🍎" />
<ImageView
android:id="@+id/checklist_image"
android:id="@+id/checklist_cross"
android:layout_width="@dimen/checklist_image_size"
android:layout_height="@dimen/checklist_image_size"
android:paddingTop="@dimen/normal_margin"
android:paddingBottom="@dimen/normal_margin"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/delete"
android:focusable="true"
android:padding="@dimen/normal_margin"
android:src="@drawable/ic_cross_vector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/checklist_drag_handle"
@@ -38,8 +53,8 @@
android:id="@+id/checklist_drag_handle"
android:layout_width="@dimen/checklist_image_size"
android:layout_height="@dimen/checklist_image_size"
android:paddingTop="@dimen/normal_margin"
android:paddingBottom="@dimen/normal_margin"
android:contentDescription="@string/move"
android:padding="@dimen/normal_margin"
android:src="@drawable/ic_drag_handle_vector"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"

View File

@@ -1,5 +1,6 @@
<resources>
<dimen name="checklist_image_size">56dp</dimen>
<dimen name="checklist_height">56dp</dimen>
<dimen name="checklist_image_size">48dp</dimen>
<dimen name="grid_note_item_width">150dp</dimen>
<dimen name="grid_note_item_max_height">150dp</dimen>
<dimen name="max_open_note_popup_height">500dp</dimen>