Skip to content

Commit

Permalink
change timer stop to long click
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Nov 9, 2024
1 parent e4e36ef commit 5c85c19
Show file tree
Hide file tree
Showing 37 changed files with 137 additions and 32 deletions.
9 changes: 9 additions & 0 deletions core/src/main/res/drawable/action_stop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M 9 12 v 3 h 6 v -6 L 9 9 z M 12 2 C 6.48 2 2 6.48 2 12 s 4.48 10 10 10 s 10 -4.48 10 -10 S 17.52 2 12 2 z M 12 20 c -4.41 0 -8 -3.59 -8 -8 s 3.59 -8 8 -8 s 8 3.59 8 8 s -3.59 8 -8 8 z" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class ChangeRecordCore(
containerChangeRecordTimeStartedAdjust.listener = viewModel::onAdjustTimeStartedItemClick
containerChangeRecordTimeEndedAdjust.listener = viewModel::onAdjustTimeEndedItemClick
btnChangeRecordSave.setOnClick(viewModel::onSaveClick)
btnChangeRecordStop.setOnClick(viewModel::onStopClick)
fragment.addOnBackPressedListener(action = viewModel::onBackPressed)
}

Expand All @@ -206,6 +207,10 @@ class ChangeRecordCore(
owner = viewLifecycleOwner,
observer = { setTimeEndedVisibility(it, binding) },
)
stopButtonVisibility.observeOnce(
owner = viewLifecycleOwner,
observer = btnChangeRecordStop::visible::set,
)
types.observe(typesAdapter::replace)
categories.observe { updateCategories(it, binding) }
saveButtonEnabled.observe { enableModifyingButtons(it, binding) }
Expand Down Expand Up @@ -318,6 +323,7 @@ class ChangeRecordCore(
binding: ChangeRecordCoreLayoutBinding,
) = with(binding) {
btnChangeRecordSave.isEnabled = isEnabled
btnChangeRecordStop.isEnabled = isEnabled
}

private fun setActionsViewData(data: List<ViewHolderType>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ abstract class ChangeRecordBaseViewModel(
val timeEndedVisibility: LiveData<Boolean> by lazy { MutableLiveData(isTimeEndedAvailable) }
val deleteIconVisibility: LiveData<Boolean> by lazy { MutableLiveData(isDeleteButtonVisible) }
val statsIconVisibility: LiveData<Boolean> by lazy { MutableLiveData(isStatisticsButtonVisible) }
val stopButtonVisibility: LiveData<Boolean> by lazy { MutableLiveData(isStopButtonVisible) }

protected var newTypeId: Long = 0
protected var newTimeEnded: Long = 0
Expand All @@ -133,6 +134,7 @@ abstract class ChangeRecordBaseViewModel(
protected abstract suspend fun updatePreview()
protected abstract fun getChangeCategoryParams(data: ChangeTagData): ChangeRecordTagFromScreen
protected abstract suspend fun onSaveClickDelegate(doAfter: suspend () -> Unit = {})
protected open suspend fun onStopClickDelegate() {}
protected open suspend fun sendPreviewUpdate(fullUpdate: Boolean) {}
protected abstract val forceSecondsInDurationDialog: Boolean
protected abstract val mergeAvailable: Boolean
Expand All @@ -144,6 +146,7 @@ abstract class ChangeRecordBaseViewModel(
protected abstract val adjustNextRecordAvailable: Boolean
protected abstract val isTimeEndedAvailable: Boolean
protected abstract val isAdditionalActionsAvailable: Boolean
protected abstract val isStopButtonVisible: Boolean
protected abstract val isDeleteButtonVisible: Boolean
protected abstract val isStatisticsButtonVisible: Boolean

Expand Down Expand Up @@ -280,6 +283,12 @@ abstract class ChangeRecordBaseViewModel(
)
}

fun onStopClick() {
onRecordChangeButtonClick(
onProceed = ::onStopClickDelegate,
)
}

fun onItemButtonClick(viewData: ChangeRecordButtonViewData) {
changeRecordActionsDelegate.onItemButtonClick(viewData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ChangeRecordViewModel @Inject constructor(
override val adjustNextRecordAvailable: Boolean get() = true
override val isTimeEndedAvailable: Boolean get() = true
override val isAdditionalActionsAvailable: Boolean get() = true
override val isStopButtonVisible: Boolean get() = false
override val isDeleteButtonVisible: Boolean get() = recordId.orZero() != 0L
override val isStatisticsButtonVisible: Boolean
get() = extra is ChangeRecordParams.Tracked ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,24 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/btnChangeRecordSave"
style="@style/AppButtonActive"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_marginHorizontal="@dimen/edit_screen_margin_horizontal"
android:layout_marginTop="8dp"
android:text="@string/change_record_save"
app:layout_constraintBottom_toBottomOf="parent" />
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/btnChangeRecordStop"
app:layout_constraintStart_toStartOf="parent" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btnChangeRecordStop"
style="@style/AppButtonActive"
android:layout_width="wrap_content"
android:layout_marginHorizontal="@dimen/edit_screen_margin_horizontal"
android:layout_marginTop="8dp"
android:text="@string/notification_record_type_stop"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:visibility="visible" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class ChangeRunningRecordViewModel @Inject constructor(
override val showTimeEndedOnAdjustPreview: Boolean get() = false
override val isTimeEndedAvailable: Boolean get() = false
override val isAdditionalActionsAvailable: Boolean get() = false
override val isStopButtonVisible: Boolean get() = true
override val isDeleteButtonVisible: Boolean get() = true
override val isStatisticsButtonVisible: Boolean get() = true

Expand Down Expand Up @@ -143,6 +144,12 @@ class ChangeRunningRecordViewModel @Inject constructor(
router.back()
}

override suspend fun onStopClickDelegate() {
runningRecordInteractor.get(extra.id)
?.let { removeRunningRecordMediator.removeWithRecordAdd(it) }
router.back()
}

override suspend fun sendPreviewUpdate(fullUpdate: Boolean) {
val recordPreview = record.value?.recordPreview ?: return
val update = changeRunningRecordMapper.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ data class RecordQuickActionsState(
data class Merge(
override val wrapBefore: Boolean,
) : Button

data class Stop(
override val wrapBefore: Boolean,
) : Button
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class RecordQuickActionsDialogFragment : BaseBottomSheetFragment<Binding>() {
btnRecordQuickActionsRepeat.setOnClick(viewModel::onRepeatClicked)
btnRecordQuickActionsDuplicate.setOnClick(viewModel::onDuplicateClicked)
btnRecordQuickActionsMerge.setOnClick(viewModel::onMergeClicked)
btnRecordQuickActionsStop.setOnClick(viewModel::onStopClick)
}

override fun initViewModel(): Unit = with(viewModel) {
Expand Down Expand Up @@ -114,6 +115,7 @@ class RecordQuickActionsDialogFragment : BaseBottomSheetFragment<Binding>() {
btnRecordQuickActionsRepeat to RecordQuickActionsState.Button.Repeat::class.java,
btnRecordQuickActionsDuplicate to RecordQuickActionsState.Button.Duplicate::class.java,
btnRecordQuickActionsMerge to RecordQuickActionsState.Button.Merge::class.java,
btnRecordQuickActionsStop to RecordQuickActionsState.Button.Stop::class.java,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.example.util.simpletimetracker.domain.interactor.RecordActionMergeMed
import com.example.util.simpletimetracker.domain.interactor.RecordActionRepeatMediator
import com.example.util.simpletimetracker.domain.interactor.RecordInteractor
import com.example.util.simpletimetracker.domain.interactor.RemoveRunningRecordMediator
import com.example.util.simpletimetracker.domain.interactor.RunningRecordInteractor
import com.example.util.simpletimetracker.domain.model.ChartFilterType
import com.example.util.simpletimetracker.domain.model.Record
import com.example.util.simpletimetracker.feature_dialogs.R
Expand All @@ -42,6 +43,7 @@ class RecordQuickActionsViewModel @Inject constructor(
private val recordActionContinueMediator: RecordActionContinueMediator,
private val recordActionMergeMediator: RecordActionMergeMediator,
private val removeRunningRecordMediator: RemoveRunningRecordMediator,
private val runningRecordInteractor: RunningRecordInteractor,
) : BaseViewModel() {

lateinit var extra: RecordQuickActionsParams
Expand Down Expand Up @@ -74,6 +76,10 @@ class RecordQuickActionsViewModel @Inject constructor(
onButtonClick(onProceed = ::onMerge)
}

fun onStopClick() {
onButtonClick(onProceed = ::onStop)
}

private suspend fun goToStatistics() {
val params = extra.type ?: return
val preview = extra.preview ?: return
Expand Down Expand Up @@ -161,8 +167,7 @@ class RecordQuickActionsViewModel @Inject constructor(
}

private suspend fun onMerge() {
val record = extra.type as? Type.RecordUntracked
?: return
val record = extra.type as? Type.RecordUntracked ?: return
val prevRecord = recordInteractor.getPrev(timeStarted = record.timeStarted).firstOrNull()
recordActionMergeMediator.execute(
prevRecord = prevRecord,
Expand All @@ -171,6 +176,13 @@ class RecordQuickActionsViewModel @Inject constructor(
)
}

private suspend fun onStop() {
val record = extra.type as? Type.RecordRunning ?: return
runningRecordInteractor.get(record.id)
?.let { removeRunningRecordMediator.removeWithRecordAdd(it) }
exit()
}

private suspend fun getTrackedRecord(): Record? {
val recordId = (extra.type as? Type.RecordTracked)?.id
?: return null
Expand Down Expand Up @@ -222,6 +234,7 @@ class RecordQuickActionsViewModel @Inject constructor(
is Type.RecordRunning -> listOf(
RecordQuickActionsState.Button.Statistics(false),
RecordQuickActionsState.Button.Delete(false),
RecordQuickActionsState.Button.Stop(true)
)
null -> emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,42 @@

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:id="@+id/btnRecordQuickActionsStop"
style="@style/RecordQuickActionButton"
android:layout_width="0dp"
app:layout_flexGrow="1"
tools:layout_wrapBefore="true">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="16dp">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/ivRecordQuickActionsStop"
style="@style/RecordQuickActionButtonImage"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/action_stop"
app:layout_constraintEnd_toStartOf="@id/tvRecordQuickActionsStop"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="ContentDescription" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvRecordQuickActionsStop"
style="@style/RecordQuickActionButtonText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/notification_record_type_stop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ivRecordQuickActionsStop" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

</com.google.android.flexbox.FlexboxLayout>

</androidx.appcompat.widget.LinearLayoutCompat>
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class RunningRecordsFragment :
}
}

override fun initViewModel() = with(binding) {
override fun initViewModel() {
with(viewModel) {
runningRecords.observe(runningRecordsAdapter::replace)
resetScreen.observe { resetScreen() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,20 @@ class RunningRecordsViewModel @Inject constructor(
}
}

// TODO change strings
@Suppress("UNUSED_PARAMETER")
fun onRunningRecordClick(item: RunningRecordViewData, sharedElements: Pair<Any, String>) {
fun onRunningRecordLongClick(
item: RunningRecordViewData,
sharedElements: Pair<Any, String>,
) {
viewModelScope.launch {
runningRecordInteractor.get(item.id)
?.let { removeRunningRecordMediator.removeWithRecordAdd(it) }
updateRunningRecords()
}
}

fun onRunningRecordLongClick(
fun onRunningRecordClick(
item: RunningRecordViewData,
sharedElements: Pair<Any, String>,
) = viewModelScope.launch {
Expand Down
2 changes: 1 addition & 1 deletion resources/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<!-- Running records -->
<string name="running_records_types_empty">لبدء التتبع ، أضف الأنشطة بالنقر فوق الزر %s أو استخدم الإعدادات المسبقة الافتراضية بالنقر فوق الزر %s</string>
<string name="running_records_empty">انقر على النشاط لبدء التتبع</string>
<string name="running_records_has_timers">انقر على البطاقة لإيقاف التتبع</string>
<string name="running_records_has_timers">انقر لفترة طويلة لإيقاف التتبع</string>
<string name="running_records_empty_hint">انقر طويلا للتعديل</string>
<string name="running_records_add_type">يضيف</string>
<string name="running_records_add_filter">أضف عامل تصفية</string>
Expand Down
2 changes: 1 addition & 1 deletion resources/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<!-- Running records -->
<string name="running_records_types_empty">Per començar el seguiment, afegiu activitats fent clic al botó %s o utilitzeu els valors predeterminats fent clic al botó %s</string>
<string name="running_records_empty">Feu clic en una activitat per a començar a enregistrar</string>
<string name="running_records_has_timers">Feu clic en una targeta per aturar l\'enregistrament</string>
<string name="running_records_has_timers">Feu clic llarg per aturar l\'enregistrament</string>
<string name="running_records_empty_hint">Mantingueu premut per editar</string>
<string name="running_records_add_type">Afegeix</string>
<string name="running_records_add_filter">Afegeix filtre</string>
Expand Down
2 changes: 1 addition & 1 deletion resources/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<!-- Running records -->
<string name="running_records_types_empty">Um mit der Verfolgung zu beginnen, fügen Sie Aktivitäten hinzu, indem Sie auf die Schaltfläche %s klicken, oder verwenden Sie Standardvoreinstellungen, indem Sie auf die Schaltfläche %s klicken</string>
<string name="running_records_empty">Klicke auf Aktivität, um die Erfassung zu starten</string>
<string name="running_records_has_timers">Klicken Sie auf die Karte, um die Verfolgung zu beenden</string>
<string name="running_records_has_timers">Klicken Sie lange, um die Verfolgung zu beenden</string>
<string name="running_records_empty_hint">Zum Bearbeiten lange klicken</string>
<string name="running_records_add_type">Hinz.</string>
<string name="running_records_add_filter">Filter hinzufügen</string>
Expand Down
2 changes: 1 addition & 1 deletion resources/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<!-- Running records -->
<string name="running_records_types_empty">Para comenzar a rastrear, agregue actividades haciendo clic en el botón %s o use los ajustes preestablecidos predeterminados haciendo clic en el botón %s</string>
<string name="running_records_empty">Haga clic en una actividad para iniciar el temporizador</string>
<string name="running_records_has_timers">Haga clic en la tarjeta para detener el seguimiento</string>
<string name="running_records_has_timers">Haga clic largo para detener el seguimiento</string>
<string name="running_records_empty_hint">Mantenga pulsado para editar</string>
<string name="running_records_add_type">Añadir</string>
<string name="running_records_add_filter">Añadir filtro</string>
Expand Down
2 changes: 1 addition & 1 deletion resources/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<!-- Running records -->
<string name="running_records_types_empty">برای شروع ردیابی، با کلیک بر روی دکمه %s فعالیت ها را اضافه کنید یا با کلیک بر روی دکمه %s از تنظیمات پیش فرض استفاده کنید</string>
<string name="running_records_empty">فعالیت را برای شروع اندازه گیری لمس کنید</string>
<string name="running_records_has_timers">برای توقف اندازه گیری کارت را لمس کنید</string>
<string name="running_records_has_timers">برای توقف ردیابی کلیک طولانی کنید</string>
<string name="running_records_empty_hint">برای ویرایش لمس کنید و نگه دارید</string>
<string name="running_records_add_type">اضافه کردن</string>
<string name="running_records_add_filter">اضافه کردن فیلتر</string>
Expand Down
2 changes: 1 addition & 1 deletion resources/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<!-- Running records -->
<string name="running_records_types_empty">Pour commencer le suivi, ajoutez des activités en cliquant sur le bouton %s ou utilisez les préréglages par défaut en cliquant sur le bouton %s</string>
<string name="running_records_empty">Cliquez longuement pour éditer</string>
<string name="running_records_has_timers">Cliquez sur la carte pour arrêter le suivi</string>
<string name="running_records_has_timers">Cliquez longuement pour arrêter le suivi</string>
<string name="running_records_empty_hint">Cliquez longuement pour éditer</string>
<string name="running_records_add_type">Ajouter</string>
<string name="running_records_add_filter">Ajouter un filtre</string>
Expand Down
2 changes: 1 addition & 1 deletion resources/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<!-- Running records -->
<string name="running_records_types_empty">ट्रैकिंग शुरू करने के लिए, %s बटन पर क्लिक करके गतिविधियाँ जोड़ें या %s बटन पर क्लिक करके डिफ़ॉल्ट प्रीसेट का उपयोग करें</string>
<string name="running_records_empty">ट्रैकिंग शुरू करने के लिए गतिविधि पर क्लिक करें</string>
<string name="running_records_has_timers">ट्रैकिंग बंद करने के लिए कार्ड पर क्लिक करें</string>
<string name="running_records_has_timers">ट्रैकिंग रोकने के लिए लंबा क्लिक करें</string>
<string name="running_records_empty_hint">संपादित करने के लिए लंबी क्लिक करें</string>
<string name="running_records_add_type">जोड़ें</string>
<string name="running_records_add_filter">फ़िल्टर जोड़ें</string>
Expand Down
2 changes: 1 addition & 1 deletion resources/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<!-- Running records -->
<string name="running_records_types_empty">Untuk memulai pelacakan, tambahkan aktivitas dengan mengklik tombol %s atau gunakan preset default dengan mengklik tombol %s</string>
<string name="running_records_empty">Ketuk pada kegiatan untuk mulai melacak</string>
<string name="running_records_has_timers">Klik pada kartu untuk menghentikan pelacakan</string>
<string name="running_records_has_timers">Klik panjang untuk menghentikan pelacakan</string>
<string name="running_records_empty_hint">Ketuk lama untuk menyunting</string>
<string name="running_records_add_type">Tambah</string>
<string name="running_records_add_filter">Tambahkan filter</string>
Expand Down
Loading

0 comments on commit 5c85c19

Please sign in to comment.