Skip to content

Commit

Permalink
add select all and select nothing to records filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Sep 1, 2024
1 parent dc6f5f6 commit a433128
Show file tree
Hide file tree
Showing 13 changed files with 756 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ fun Long.toDuration(): String {

fun String.padDuration(): String {
return this.padStart(2, '0')
}

@Suppress("UNCHECKED_CAST")
fun <T> Any.tryCast(): T? {
return this as? T
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.util.simpletimetracker.feature_base_adapter.emptySpace

import com.example.util.simpletimetracker.domain.extension.tryCast
import com.example.util.simpletimetracker.feature_base_adapter.createRecyclerBindingAdapterDelegate
import com.example.util.simpletimetracker.feature_views.extension.dpToPx
import com.google.android.flexbox.FlexboxLayoutManager
import com.example.util.simpletimetracker.feature_base_adapter.databinding.ItemEmptySpaceLayoutBinding as Binding
import com.example.util.simpletimetracker.feature_base_adapter.emptySpace.EmptySpaceViewData as ViewData

fun createEmptySpaceAdapterDelegate() = createRecyclerBindingAdapterDelegate<ViewData, Binding>(
Binding::inflate,
) { binding, item, _ ->

with(binding.root) {
item as ViewData

layoutParams
.tryCast<FlexboxLayoutManager.LayoutParams>()
?.apply {
width = item.widthDp.dpToPx()
height = item.heightDp.dpToPx()
isWrapBefore = item.wrapBefore
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.util.simpletimetracker.feature_base_adapter.emptySpace

import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType

data class EmptySpaceViewData(
val id: Long,
val widthDp: Int = 0,
val heightDp: Int = 0,
val wrapBefore: Boolean = false,
) : ViewHolderType {

override fun getUniqueId(): Long = id

override fun isValidType(other: ViewHolderType): Boolean =
other is EmptySpaceViewData
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.util.simpletimetracker.feature_base_adapter.selectionButton

import com.example.util.simpletimetracker.feature_base_adapter.createRecyclerBindingAdapterDelegate
import com.example.util.simpletimetracker.feature_views.extension.setOnClickWith
import com.example.util.simpletimetracker.feature_base_adapter.databinding.ItemSelectionButtonLayoutBinding as Binding
import com.example.util.simpletimetracker.feature_base_adapter.selectionButton.SelectionButtonViewData as ViewData

fun createSelectionButtonAdapterDelegate(
onItemClick: ((ViewData) -> Unit),
) = createRecyclerBindingAdapterDelegate<ViewData, Binding>(
Binding::inflate,
) { binding, item, _ ->

with(binding) {
item as ViewData

root.setCardBackgroundColor(item.color)
tvSelectionButtonItemName.text = item.name
root.setOnClickWith(item, onItemClick)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.util.simpletimetracker.feature_base_adapter.selectionButton

import androidx.annotation.ColorInt
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType

class SelectionButtonViewData(
val type: Type,
val name: String,
@ColorInt val color: Int,
) : ViewHolderType {

// Only one add item on screen
override fun getUniqueId(): Long = 1L

override fun isValidType(other: ViewHolderType): Boolean =
other is SelectionButtonViewData && other.type == type

interface Type
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewEmptySpaceItem"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/black"
app:cardCornerRadius="@dimen/record_type_card_corner_radius"
app:cardElevation="@dimen/record_type_card_elevation"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:paddingHorizontal="4dp">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvSelectionButtonItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:paddingVertical="12dp"
android:textColor="?appLightTextColor"
android:textStyle="bold"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Item name" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>
Loading

0 comments on commit a433128

Please sign in to comment.