-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
114 additions
and
23 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...util/simpletimetracker/feature_change_record/adapter/ChangeRecordSliderAdapterDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.example.util.simpletimetracker.feature_change_record.adapter | ||
|
||
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType | ||
import com.example.util.simpletimetracker.feature_base_adapter.createRecyclerBindingAdapterDelegate | ||
import com.example.util.simpletimetracker.feature_change_record.model.ChangeRecordActionsBlock | ||
import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordSliderViewData as ViewData | ||
import com.example.util.simpletimetracker.feature_change_record.databinding.ChangeRecordSliderItemBinding as Binding | ||
|
||
fun createChangeRecordSliderAdapterDelegate( | ||
onValueChanged: (ViewData, Float) -> Unit, | ||
) = createRecyclerBindingAdapterDelegate<ViewData, Binding>( | ||
Binding::inflate, | ||
) { binding, item, _ -> | ||
|
||
with(binding) { | ||
item as ViewData | ||
// To avoid illegal state exception. | ||
val actualMax = item.max.coerceAtLeast(item.min + 1) | ||
|
||
root.tag = item.block | ||
if (item.min != sliderChangeRecordItem.valueFrom) { | ||
sliderChangeRecordItem.valueFrom = item.min | ||
} | ||
if (item.max != sliderChangeRecordItem.valueTo) { | ||
sliderChangeRecordItem.valueTo = actualMax | ||
} | ||
if (item.value != sliderChangeRecordItem.value) { | ||
sliderChangeRecordItem.value = item.value | ||
} | ||
sliderChangeRecordItem.addOnChangeListener { _, value, fromUser -> | ||
if (fromUser) onValueChanged(item, value) | ||
} | ||
} | ||
} | ||
|
||
data class ChangeRecordSliderViewData( | ||
val block: ChangeRecordActionsBlock, | ||
val min: Float, | ||
val max: Float, | ||
val value: Float, | ||
) : ViewHolderType { | ||
|
||
override fun getUniqueId(): Long = block.ordinal.toLong() | ||
|
||
override fun isValidType(other: ViewHolderType): Boolean = | ||
other is ViewData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
features/feature_change_record/src/main/res/layout/change_record_slider_item.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.google.android.material.slider.Slider 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:id="@+id/sliderChangeRecordItem" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:labelBehavior="gone" | ||
tools:value="33" | ||
tools:valueFrom="0" | ||
tools:valueTo="100" /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters