A fork of Simple Time Tracker with WearOS support. (Now integrated upstream)
0

Configure Feed

Select the types of activity you want to include in your feed.

change duration dialog

razeeman (Jan 20, 2024, 4:54 PM +0300) 0acb04c9 772e9284

+90 -40
+2 -14
features/feature_dialogs/src/main/res/layout/duration_dialog_fragment.xml
··· 21 21 android:layout_height="0dp" 22 22 android:layout_marginVertical="8dp" 23 23 android:layout_marginStart="8dp" 24 - android:layout_marginEnd="16dp" 24 + android:layout_marginEnd="8dp" 25 25 app:durationLegendPadding="4dp" 26 26 app:durationLegendTextColor="?appTextHintColor" 27 27 app:durationLegendTextSize="32sp" 28 28 app:durationTextColor="?appTextPrimaryColor" 29 29 app:layout_constraintBottom_toTopOf="@id/guidelineDurationPicker" 30 - app:layout_constraintEnd_toStartOf="@id/ivDurationPickerDelete" 30 + app:layout_constraintEnd_toEndOf="parent" 31 31 app:layout_constraintStart_toStartOf="parent" 32 32 app:layout_constraintTop_toBottomOf="@id/arrowDurationPicker" /> 33 - 34 - <androidx.appcompat.widget.AppCompatImageView 35 - android:id="@+id/ivDurationPickerDelete" 36 - android:layout_width="32dp" 37 - android:layout_height="32dp" 38 - android:layout_marginEnd="16dp" 39 - android:background="?selectableItemBackgroundBorderless" 40 - android:src="@drawable/backspace" 41 - android:tint="?appTextPrimaryColor" 42 - app:layout_constraintBottom_toBottomOf="@id/viewDurationPickerValue" 43 - app:layout_constraintEnd_toEndOf="parent" 44 - app:layout_constraintTop_toTopOf="@id/viewDurationPickerValue" /> 45 33 46 34 <androidx.constraintlayout.widget.Guideline 47 35 android:id="@+id/guidelineDurationPicker"
+43 -4
features/feature_dialogs/src/main/res/layout/number_keyboard_layout.xml
··· 110 110 android:gravity="center" 111 111 android:text="7" 112 112 android:textStyle="bold" 113 - app:layout_constraintBottom_toTopOf="@id/tvNumberKeyboard0" 113 + app:layout_constraintBottom_toTopOf="@id/tvNumberKeyboard00" 114 114 app:layout_constraintEnd_toStartOf="@id/tvNumberKeyboard8" 115 115 app:layout_constraintStart_toStartOf="parent" 116 116 app:layout_constraintTop_toBottomOf="@id/tvNumberKeyboard4" ··· 142 142 android:gravity="center" 143 143 android:text="9" 144 144 android:textStyle="bold" 145 - app:layout_constraintBottom_toTopOf="@id/tvNumberKeyboard0" 145 + app:layout_constraintBottom_toTopOf="@id/btnNumberKeyboardDelete" 146 146 app:layout_constraintEnd_toEndOf="parent" 147 147 app:layout_constraintStart_toEndOf="@id/tvNumberKeyboard8" 148 148 app:layout_constraintTop_toBottomOf="@id/tvNumberKeyboard6" 149 + tools:ignore="HardcodedText" 150 + tools:textColor="@color/black" 151 + tools:textSize="32sp" /> 152 + 153 + <androidx.appcompat.widget.AppCompatTextView 154 + android:id="@+id/tvNumberKeyboard00" 155 + android:layout_width="0dp" 156 + android:layout_height="0dp" 157 + android:background="?selectableItemBackgroundBorderless" 158 + android:gravity="center" 159 + android:text="00" 160 + android:textStyle="bold" 161 + app:layout_constraintBottom_toBottomOf="parent" 162 + app:layout_constraintEnd_toStartOf="@id/tvNumberKeyboard0" 163 + app:layout_constraintStart_toStartOf="parent" 164 + app:layout_constraintTop_toBottomOf="@id/tvNumberKeyboard7" 149 165 tools:ignore="HardcodedText" 150 166 tools:textColor="@color/black" 151 167 tools:textSize="32sp" /> ··· 159 175 android:text="0" 160 176 android:textStyle="bold" 161 177 app:layout_constraintBottom_toBottomOf="parent" 162 - app:layout_constraintEnd_toStartOf="@id/tvNumberKeyboard9" 163 - app:layout_constraintStart_toEndOf="@id/tvNumberKeyboard7" 178 + app:layout_constraintEnd_toStartOf="@id/btnNumberKeyboardDelete" 179 + app:layout_constraintStart_toEndOf="@id/tvNumberKeyboard00" 164 180 app:layout_constraintTop_toBottomOf="@id/tvNumberKeyboard8" 165 181 tools:ignore="HardcodedText" 166 182 tools:textColor="@color/black" 167 183 tools:textSize="32sp" /> 184 + 185 + <androidx.constraintlayout.widget.ConstraintLayout 186 + android:id="@+id/btnNumberKeyboardDelete" 187 + android:layout_width="0dp" 188 + android:layout_height="0dp" 189 + android:background="?selectableItemBackgroundBorderless" 190 + app:layout_constraintBottom_toBottomOf="parent" 191 + app:layout_constraintEnd_toEndOf="parent" 192 + app:layout_constraintStart_toEndOf="@id/tvNumberKeyboard0" 193 + app:layout_constraintTop_toBottomOf="@id/tvNumberKeyboard9"> 194 + 195 + <androidx.appcompat.widget.AppCompatImageView 196 + android:id="@+id/ivNumberKeyboardDelete" 197 + android:layout_width="32dp" 198 + android:layout_height="32dp" 199 + app:layout_constraintBottom_toBottomOf="parent" 200 + app:layout_constraintEnd_toEndOf="parent" 201 + app:layout_constraintStart_toStartOf="parent" 202 + app:layout_constraintTop_toTopOf="parent" 203 + app:srcCompat="@drawable/backspace" 204 + tools:tint="@color/black" /> 205 + 206 + </androidx.constraintlayout.widget.ConstraintLayout> 168 207 169 208 </merge>
+30 -18
features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/duration/customView/NumberKeyboardView.kt
··· 1 1 package com.example.util.simpletimetracker.feature_dialogs.duration.customView 2 2 3 3 import android.content.Context 4 + import android.content.res.ColorStateList 4 5 import android.graphics.Color 5 6 import android.util.AttributeSet 6 7 import android.util.TypedValue ··· 13 14 class NumberKeyboardView @JvmOverloads constructor( 14 15 context: Context, 15 16 attrs: AttributeSet? = null, 16 - defStyleAttr: Int = 0 17 + defStyleAttr: Int = 0, 17 18 ) : ConstraintLayout( 18 19 context, 19 20 attrs, 20 - defStyleAttr 21 + defStyleAttr, 21 22 ) { 22 23 23 - var listener: ((Int) -> Unit)? = null 24 + var listener: ((Button) -> Unit)? = null 24 25 25 26 private val binding: NumberKeyboardLayoutBinding = NumberKeyboardLayoutBinding 26 27 .inflate(LayoutInflater.from(context), this) 27 28 28 29 private val textViews by lazy { 29 30 with(binding) { 30 - listOf( 31 - tvNumberKeyboard0, 32 - tvNumberKeyboard1, 33 - tvNumberKeyboard2, 34 - tvNumberKeyboard3, 35 - tvNumberKeyboard4, 36 - tvNumberKeyboard5, 37 - tvNumberKeyboard6, 38 - tvNumberKeyboard7, 39 - tvNumberKeyboard8, 40 - tvNumberKeyboard9 31 + mapOf( 32 + 0 to tvNumberKeyboard0, 33 + 1 to tvNumberKeyboard1, 34 + 2 to tvNumberKeyboard2, 35 + 3 to tvNumberKeyboard3, 36 + 4 to tvNumberKeyboard4, 37 + 5 to tvNumberKeyboard5, 38 + 6 to tvNumberKeyboard6, 39 + 7 to tvNumberKeyboard7, 40 + 8 to tvNumberKeyboard8, 41 + 9 to tvNumberKeyboard9, 41 42 ) 42 43 } 43 44 } ··· 53 54 recycle() 54 55 } 55 56 56 - textViews.forEachIndexed { index, view -> 57 - view.setOnClick { listener?.invoke(index) } 57 + textViews.forEach { (value, view) -> 58 + view.setOnClick { listener?.invoke(Button.Number(value)) } 58 59 } 60 + binding.tvNumberKeyboard00.setOnClick { listener?.invoke(Button.DoubleZero) } 61 + binding.btnNumberKeyboardDelete.setOnClick { listener?.invoke(Button.Delete) } 59 62 } 60 63 61 64 private fun setTextColor(textColor: Int) { 62 - textViews.forEach { it.setTextColor(textColor) } 65 + textViews.values.forEach { it.setTextColor(textColor) } 66 + binding.tvNumberKeyboard00.setTextColor(textColor) 67 + binding.ivNumberKeyboardDelete.imageTintList = ColorStateList.valueOf(textColor) 63 68 } 64 69 65 70 private fun setTextSize(textSize: Float) { 66 - textViews.forEach { it.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize) } 71 + textViews.values.forEach { it.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize) } 72 + binding.tvNumberKeyboard00.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize) 73 + } 74 + 75 + sealed interface Button { 76 + data class Number(val value: Int) : Button 77 + object DoubleZero : Button 78 + object Delete : Button 67 79 } 68 80 }
+1 -2
features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/duration/view/DurationDialogFragment.kt
··· 61 61 override fun initUx(): Unit = with(binding) { 62 62 btnDurationPickerSave.setOnClick(::onSaveClick) 63 63 btnDurationPickerDisable.setOnClick(::onDisableClick) 64 - viewDurationPickerNumberKeyboard.listener = viewModel::onNumberPressed 65 - ivDurationPickerDelete.setOnClick(viewModel::onNumberDelete) 64 + viewDurationPickerNumberKeyboard.listener = viewModel::onButtonPressed 66 65 } 67 66 68 67 override fun initViewModel(): Unit = with(viewModel) {
+14 -2
features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/duration/viewModel/DurationPickerViewModel.kt
··· 7 7 import com.example.util.simpletimetracker.core.extension.set 8 8 import com.example.util.simpletimetracker.domain.extension.orZero 9 9 import com.example.util.simpletimetracker.feature_dialogs.duration.customView.DurationView 10 + import com.example.util.simpletimetracker.feature_dialogs.duration.customView.NumberKeyboardView 10 11 import com.example.util.simpletimetracker.feature_dialogs.duration.extra.DurationPickerExtra 11 12 import dagger.hilt.android.lifecycle.HiltViewModel 12 13 import kotlinx.coroutines.launch ··· 30 31 31 32 private var reformattedDuration: Long = 0 32 33 33 - fun onNumberPressed(number: Int) { 34 + fun onButtonPressed(button: NumberKeyboardView.Button) { 35 + when (button) { 36 + is NumberKeyboardView.Button.Number -> onNumberPressed(button.value) 37 + is NumberKeyboardView.Button.Delete -> onNumberDelete() 38 + is NumberKeyboardView.Button.DoubleZero -> { 39 + onNumberPressed(0) 40 + onNumberPressed(0) 41 + } 42 + } 43 + } 44 + 45 + private fun onNumberPressed(number: Int) { 34 46 if (reformattedDuration <= 999_99_99) { 35 47 reformattedDuration = reformattedDuration * 10 + number 36 48 updateDurationViewData() 37 49 } 38 50 } 39 51 40 - fun onNumberDelete() { 52 + private fun onNumberDelete() { 41 53 reformattedDuration /= 10 42 54 updateDurationViewData() 43 55 }