Skip to content

Commit 84a1927

Browse files
committed
change color icon fields
1 parent f54d96c commit 84a1927

File tree

12 files changed

+437
-67
lines changed

12 files changed

+437
-67
lines changed

features/feature_change_activity_filter/src/main/java/com/example/util/simpletimetracker/feature_change_activity_filter/view/ChangeActivityFilterFragment.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.example.util.simpletimetracker.feature_change_activity_filter.view
22

33
import android.animation.ValueAnimator
4+
import android.graphics.drawable.GradientDrawable
45
import android.os.Bundle
56
import android.view.LayoutInflater
67
import android.view.ViewGroup
8+
import androidx.annotation.ColorInt
79
import androidx.core.view.isVisible
10+
import androidx.core.view.updateLayoutParams
811
import androidx.core.widget.doAfterTextChanged
912
import androidx.fragment.app.viewModels
1013
import com.example.util.simpletimetracker.core.base.BaseFragment
@@ -29,6 +32,7 @@ import com.example.util.simpletimetracker.feature_base_adapter.empty.createEmpty
2932
import com.example.util.simpletimetracker.feature_base_adapter.hint.createHintAdapterDelegate
3033
import com.example.util.simpletimetracker.feature_base_adapter.info.createInfoAdapterDelegate
3134
import com.example.util.simpletimetracker.feature_base_adapter.recordType.createRecordTypeAdapterDelegate
35+
import com.example.util.simpletimetracker.feature_change_activity_filter.R
3236
import com.example.util.simpletimetracker.feature_change_activity_filter.viewData.ChangeActivityFilterChooserState.Closed
3337
import com.example.util.simpletimetracker.feature_change_activity_filter.viewData.ChangeActivityFilterChooserState.Color
3438
import com.example.util.simpletimetracker.feature_change_activity_filter.viewData.ChangeActivityFilterChooserState.Type
@@ -76,6 +80,9 @@ class ChangeActivityFilterFragment :
7680
)
7781
}
7882
private var typeColorAnimator: ValueAnimator? = null
83+
private val colorPreviewGradient = GradientDrawable().apply {
84+
orientation = GradientDrawable.Orientation.LEFT_RIGHT
85+
}
7986

8087
private val params: ChangeActivityFilterParams by fragmentArgumentDelegate(
8188
key = ARGS_PARAMS, default = ChangeActivityFilterParams.New,
@@ -157,7 +164,7 @@ class ChangeActivityFilterFragment :
157164
itemName = it.name
158165
itemColor = it.color
159166

160-
binding.layoutChangeActivityFilterColorPreview.setCardBackgroundColor(it.color)
167+
updateColorPreview(it.color)
161168
binding.layoutChangeActivityFilterTypePreview.setCardBackgroundColor(it.color)
162169
}
163170
}
@@ -173,7 +180,7 @@ class ChangeActivityFilterFragment :
173180
to = item.color,
174181
doOnUpdate = { value ->
175182
itemColor = value
176-
binding.layoutChangeActivityFilterColorPreview.setCardBackgroundColor(value)
183+
updateColorPreview(value)
177184
},
178185
)
179186
with(binding) {
@@ -207,6 +214,12 @@ class ChangeActivityFilterFragment :
207214
// Chooser fields
208215
fieldChangeActivityFilterColor.isVisible = isClosed || state.current is Color
209216
fieldChangeActivityFilterType.isVisible = isClosed || state.current is Type
217+
218+
// Chooser size
219+
val sizeDefault = resources.getDimensionPixelSize(R.dimen.input_field_height)
220+
val sizeBig = resources.getDimensionPixelSize(R.dimen.input_field_height_big)
221+
val colorSize = if (state.current is Color) sizeDefault else sizeBig
222+
fieldChangeActivityFilterColor.updateLayoutParams { height = colorSize }
210223
}
211224

212225
private fun updateTypes(
@@ -217,6 +230,12 @@ class ChangeActivityFilterFragment :
217230
tvChangeActivityFilterTypePreview.text = data.selectedCount.toString()
218231
}
219232

233+
private fun updateColorPreview(@ColorInt color: Int) = with(binding) {
234+
colorPreviewGradient.colors = intArrayOf(android.graphics.Color.TRANSPARENT, color)
235+
layoutChangeActivityFilterColorPreview.setCardBackgroundColor(color)
236+
viewChangeActivityFilterColorPreviewLong.background = colorPreviewGradient
237+
}
238+
220239
companion object {
221240
private const val ARGS_PARAMS = "args_params"
222241

features/feature_change_activity_filter/src/main/res/layout/change_activity_filter_fragment.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
android:id="@+id/fieldChangeActivityFilterColor"
8484
style="@style/InputFieldCard"
8585
android:layout_width="0dp"
86-
android:layout_height="@dimen/input_field_height"
86+
android:layout_height="@dimen/input_field_height_big"
8787
android:layout_marginHorizontal="@dimen/edit_screen_field_margin_horizontal"
8888
android:layout_marginTop="3dp"
8989
app:layout_constraintEnd_toEndOf="parent"
@@ -96,6 +96,16 @@
9696
android:layout_height="match_parent"
9797
android:background="?appInputFieldBorder">
9898

99+
<View
100+
android:id="@+id/viewChangeActivityFilterColorPreviewLong"
101+
android:layout_width="0dp"
102+
android:layout_height="match_parent"
103+
android:alpha="0.25"
104+
app:layout_constraintEnd_toEndOf="parent"
105+
app:layout_constraintHorizontal_bias="1"
106+
app:layout_constraintStart_toStartOf="parent"
107+
app:layout_constraintWidth_percent="0.66" />
108+
99109
<com.google.android.material.card.MaterialCardView
100110
android:id="@+id/layoutChangeActivityFilterColorPreview"
101111
style="@style/EditScreenPreview"

features/feature_change_category/src/main/java/com/example/util/simpletimetracker/feature_change_category/view/ChangeCategoryFragment.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.example.util.simpletimetracker.feature_change_category.view
22

33
import android.animation.ValueAnimator
4+
import android.graphics.drawable.GradientDrawable
45
import android.os.Bundle
56
import android.view.LayoutInflater
67
import android.view.ViewGroup
8+
import androidx.annotation.ColorInt
79
import androidx.core.view.isInvisible
810
import androidx.core.view.isVisible
11+
import androidx.core.view.updateLayoutParams
912
import androidx.core.widget.doAfterTextChanged
1013
import androidx.fragment.app.viewModels
1114
import com.example.util.simpletimetracker.core.base.BaseFragment
@@ -31,6 +34,7 @@ import com.example.util.simpletimetracker.feature_base_adapter.empty.createEmpty
3134
import com.example.util.simpletimetracker.feature_base_adapter.hint.createHintAdapterDelegate
3235
import com.example.util.simpletimetracker.feature_base_adapter.info.createInfoAdapterDelegate
3336
import com.example.util.simpletimetracker.feature_base_adapter.recordType.createRecordTypeAdapterDelegate
37+
import com.example.util.simpletimetracker.feature_change_category.R
3438
import com.example.util.simpletimetracker.feature_change_category.viewData.ChangeCategoryChooserState.Closed
3539
import com.example.util.simpletimetracker.feature_change_category.viewData.ChangeCategoryChooserState.Color
3640
import com.example.util.simpletimetracker.feature_change_category.viewData.ChangeCategoryChooserState.GoalTime
@@ -88,6 +92,9 @@ class ChangeCategoryFragment :
8892
}
8993
private var typeColorAnimator: ValueAnimator? = null
9094
private var goalTextWatchers: GoalsViewDelegate.TextWatchers? = null
95+
private val colorPreviewGradient = GradientDrawable().apply {
96+
orientation = GradientDrawable.Orientation.LEFT_RIGHT
97+
}
9198

9299
private val params: ChangeTagData by fragmentArgumentDelegate(
93100
key = ARGS_PARAMS, default = ChangeTagData.New(),
@@ -215,7 +222,7 @@ class ChangeCategoryFragment :
215222
itemName = it.name
216223
itemColor = it.color
217224

218-
binding.layoutChangeCategoryColorPreview.setCardBackgroundColor(it.color)
225+
updateColorPreview(it.color)
219226
binding.layoutChangeCategoryTypePreview.setCardBackgroundColor(it.color)
220227
binding.layoutChangeCategoryGoalPreview.setCardBackgroundColor(it.color)
221228
}
@@ -232,7 +239,7 @@ class ChangeCategoryFragment :
232239
to = item.color,
233240
doOnUpdate = { value ->
234241
itemColor = value
235-
binding.layoutChangeCategoryColorPreview.setCardBackgroundColor(value)
242+
updateColorPreview(value)
236243
},
237244
)
238245
}
@@ -277,6 +284,12 @@ class ChangeCategoryFragment :
277284
fieldChangeCategoryColor.isVisible = isClosed || state.current is Color
278285
fieldChangeCategoryType.isVisible = isClosed || state.current is Type
279286
fieldChangeCategoryGoalTime.isVisible = isClosed || state.current is GoalTime
287+
288+
// Chooser size
289+
val sizeDefault = resources.getDimensionPixelSize(R.dimen.input_field_height)
290+
val sizeBig = resources.getDimensionPixelSize(R.dimen.input_field_height_big)
291+
val colorSize = if (state.current is Color) sizeDefault else sizeBig
292+
fieldChangeCategoryColor.updateLayoutParams { height = colorSize }
280293
}
281294

282295
private fun updateGoalsState(state: ChangeRecordTypeGoalsViewData) = with(binding) {
@@ -307,6 +320,12 @@ class ChangeCategoryFragment :
307320
}
308321
}
309322

323+
private fun updateColorPreview(@ColorInt color: Int) = with(binding) {
324+
colorPreviewGradient.colors = intArrayOf(android.graphics.Color.TRANSPARENT, color)
325+
layoutChangeCategoryColorPreview.setCardBackgroundColor(color)
326+
viewChangeCategoryColorPreviewLong.background = colorPreviewGradient
327+
}
328+
310329
companion object {
311330
private const val ARGS_PARAMS = "args_params"
312331

features/feature_change_category/src/main/res/layout/change_category_fragment.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
android:id="@+id/fieldChangeCategoryColor"
100100
style="@style/InputFieldCard"
101101
android:layout_width="0dp"
102-
android:layout_height="@dimen/input_field_height"
102+
android:layout_height="@dimen/input_field_height_big"
103103
android:layout_marginHorizontal="@dimen/edit_screen_field_margin_horizontal"
104104
android:layout_marginTop="3dp"
105105
app:layout_constraintEnd_toEndOf="parent"
@@ -112,6 +112,16 @@
112112
android:layout_height="match_parent"
113113
android:background="?appInputFieldBorder">
114114

115+
<View
116+
android:id="@+id/viewChangeCategoryColorPreviewLong"
117+
android:layout_width="0dp"
118+
android:layout_height="match_parent"
119+
android:alpha="0.25"
120+
app:layout_constraintEnd_toEndOf="parent"
121+
app:layout_constraintHorizontal_bias="1"
122+
app:layout_constraintStart_toStartOf="parent"
123+
app:layout_constraintWidth_percent="0.66" />
124+
115125
<com.google.android.material.card.MaterialCardView
116126
android:id="@+id/layoutChangeCategoryColorPreview"
117127
style="@style/EditScreenPreview"

features/feature_change_record_tag/src/main/java/com/example/util/simpletimetracker/feature_change_record_tag/view/ChangeRecordTagFragment.kt

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.example.util.simpletimetracker.feature_change_record_tag.view
22

33
import android.animation.ValueAnimator
4+
import android.graphics.drawable.GradientDrawable
45
import android.os.Bundle
56
import android.text.TextWatcher
67
import android.view.LayoutInflater
78
import android.view.ViewGroup
9+
import androidx.annotation.ColorInt
810
import androidx.core.view.isInvisible
911
import androidx.core.view.isVisible
1012
import androidx.core.view.setPadding
@@ -59,6 +61,7 @@ import com.example.util.simpletimetracker.feature_views.extension.dpToPx
5961
import com.example.util.simpletimetracker.feature_views.extension.setCompoundDrawableWithIntrinsicBounds
6062
import com.example.util.simpletimetracker.feature_views.extension.setOnClick
6163
import com.example.util.simpletimetracker.feature_views.extension.visible
64+
import com.example.util.simpletimetracker.feature_views.viewData.RecordTypeIcon
6265
import com.example.util.simpletimetracker.navigation.params.screen.ChangeRecordTagFromScreen
6366
import com.example.util.simpletimetracker.navigation.params.screen.ChangeTagData
6467
import com.google.android.flexbox.FlexDirection
@@ -133,6 +136,9 @@ class ChangeRecordTagFragment :
133136
private var iconsLayoutManager: GridLayoutManager? = null
134137
private var typeColorAnimator: ValueAnimator? = null
135138
private var iconTextWatcher: TextWatcher? = null
139+
private val colorPreviewGradient = GradientDrawable().apply {
140+
orientation = GradientDrawable.Orientation.LEFT_RIGHT
141+
}
136142

137143
private val params: ChangeTagData by fragmentArgumentDelegate(
138144
key = ARGS_PARAMS, default = ChangeTagData.New(),
@@ -286,15 +292,12 @@ class ChangeRecordTagFragment :
286292
if (icon != null) {
287293
itemIconVisible = true
288294
itemIcon = icon.toViewData()
289-
binding.layoutChangeRecordTagIconPreview.isVisible = true
290-
binding.iconChangeRecordTagIconPreview.itemIcon = icon.toViewData()
291295
} else {
292296
itemIconVisible = false
293-
binding.layoutChangeRecordTagIconPreview.isVisible = false
294297
}
295298

296-
binding.layoutChangeRecordTagColorPreview.setCardBackgroundColor(it.color)
297-
binding.layoutChangeRecordTagIconPreview.setCardBackgroundColor(it.color)
299+
updateColorPreview(it.color)
300+
updateIconPreview(icon?.toViewData(), it.color)
298301
binding.layoutChangeRecordTagTypesPreview.setCardBackgroundColor(it.color)
299302
binding.layoutChangeRecordTagDefaultTypePreview.setCardBackgroundColor(it.color)
300303
}
@@ -308,11 +311,8 @@ class ChangeRecordTagFragment :
308311
if (icon != null) {
309312
itemIconVisible = true
310313
itemIcon = icon
311-
binding.layoutChangeRecordTagIconPreview.isVisible = true
312-
binding.iconChangeRecordTagIconPreview.itemIcon = icon
313314
} else {
314315
itemIconVisible = false
315-
binding.layoutChangeRecordTagIconPreview.isVisible = false
316316
}
317317

318318
typeColorAnimator?.cancel()
@@ -321,12 +321,13 @@ class ChangeRecordTagFragment :
321321
to = item.color,
322322
doOnUpdate = { value ->
323323
itemColor = value
324-
binding.layoutChangeRecordTagColorPreview.setCardBackgroundColor(value)
324+
updateColorPreview(value)
325325
},
326326
)
327327
}
328+
328329
with(binding) {
329-
layoutChangeRecordTagIconPreview.setCardBackgroundColor(item.color)
330+
updateIconPreview(item.icon, item.color)
330331
layoutChangeRecordTagTypesPreview.setCardBackgroundColor(item.color)
331332
layoutChangeRecordTagDefaultTypePreview.setCardBackgroundColor(item.color)
332333
}
@@ -424,6 +425,29 @@ class ChangeRecordTagFragment :
424425
}
425426
}
426427

428+
private fun updateColorPreview(@ColorInt color: Int) = with(binding) {
429+
colorPreviewGradient.colors = intArrayOf(android.graphics.Color.TRANSPARENT, color)
430+
layoutChangeRecordTagColorPreview.setCardBackgroundColor(color)
431+
viewChangeRecordTagColorPreviewLong.background = colorPreviewGradient
432+
}
433+
434+
private fun updateIconPreview(
435+
iconId: RecordTypeIcon?,
436+
@ColorInt color: Int,
437+
) = with(binding) {
438+
if (iconId != null) {
439+
binding.layoutChangeRecordTagIconPreview.isVisible = true
440+
binding.viewChangeRecordTagIconPreviewLong.isVisible = true
441+
442+
layoutChangeRecordTagIconPreview.setCardBackgroundColor(color)
443+
iconChangeRecordTagIconPreview.itemIcon = iconId
444+
viewChangeRecordTagIconPreviewLong.setIcon(iconId)
445+
} else {
446+
binding.layoutChangeRecordTagIconPreview.isVisible = false
447+
binding.viewChangeRecordTagIconPreviewLong.isVisible = false
448+
}
449+
}
450+
427451
companion object {
428452
private const val ARGS_PARAMS = "args_params"
429453

0 commit comments

Comments
 (0)