Skip to content

Commit

Permalink
add comment to tag selection dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Oct 20, 2024
1 parent eeed1f1 commit fee6ed3
Show file tree
Hide file tree
Showing 52 changed files with 435 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import com.example.util.simpletimetracker.core.mapper.TimeMapper
import com.example.util.simpletimetracker.core.viewData.ChangeRecordDateTimeState
import com.example.util.simpletimetracker.domain.model.Range
import com.example.util.simpletimetracker.domain.model.RangeLength
import com.example.util.simpletimetracker.domain.model.RecordDataSelectionDialogResult
import com.example.util.simpletimetracker.domain.model.RecordsFilter
import com.example.util.simpletimetracker.feature_base_adapter.runningRecord.GoalTimeViewData
import com.example.util.simpletimetracker.feature_views.viewData.RecordTypeIcon
import com.example.util.simpletimetracker.navigation.params.screen.ChangeRecordDateTimeStateParams
import com.example.util.simpletimetracker.navigation.params.screen.ChangeRunningRecordParams
import com.example.util.simpletimetracker.navigation.params.screen.RangeLengthParams
import com.example.util.simpletimetracker.navigation.params.screen.RangeParams
import com.example.util.simpletimetracker.navigation.params.screen.RecordTagSelectionParams
import com.example.util.simpletimetracker.navigation.params.screen.RecordTypeIconParams
import com.example.util.simpletimetracker.navigation.params.screen.RecordsFilterParam

Expand Down Expand Up @@ -203,3 +205,12 @@ fun RangeLength.toParams(): RangeLengthParams {
)
}
}

fun RecordDataSelectionDialogResult.toParams(): List<RecordTagSelectionParams.Field> {
return fields.map {
when (it) {
is RecordDataSelectionDialogResult.Field.Tags -> RecordTagSelectionParams.Field.Tags
is RecordDataSelectionDialogResult.Field.Comment -> RecordTagSelectionParams.Field.Comment
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ class PrefsRepoImpl @Inject constructor(
KEY_SHOW_RECORD_TAG_SELECTION_EXCLUDE_ACTIVITIES, emptySet(),
)

override var showCommentInput: Boolean by prefs.delegate(
KEY_SHOW_COMMENT_INPUT, false,
)

override var commentInputExcludeActivities: Set<String> by prefs.delegate(
KEY_SHOW_COMMENT_INPUT_EXCLUDE_ACTIVITIES, emptySet(),
)

override var autostartPomodoroActivities: Set<String> by prefs.delegate(
KEY_AUTOSTART_POMODORO_ACTIVITIES, emptySet(),
)
Expand Down Expand Up @@ -597,6 +605,8 @@ class PrefsRepoImpl @Inject constructor(
const val KEY_KEEP_SCREEN_ON = "keepScreenOn"
const val KEY_SHOW_RECORD_TAG_SELECTION = "showRecordTagSelection"
const val KEY_SHOW_RECORD_TAG_SELECTION_EXCLUDE_ACTIVITIES = "showRecordTagSelectionExcludeActivities"
const val KEY_SHOW_COMMENT_INPUT = "showCommentInput"
const val KEY_SHOW_COMMENT_INPUT_EXCLUDE_ACTIVITIES = "showCommentInputExcludeActivities"
const val KEY_AUTOSTART_POMODORO_ACTIVITIES = "autostartPomodoroActivities"
const val KEY_RECORD_TAG_SELECTION_CLOSE_AFTER_ONE = "recordTagSelectionCloseAfterOne"
const val KEY_AUTOMATED_TRACKING_SEND_EVENTS = "automatedTrackingSendEvents"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companio
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_REVERSE_ORDER_IN_CALENDAR
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_ACTIVITY_FILTERS
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_CALENDAR_BUTTON_ON_RECORDS_TAB
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_COMMENT_INPUT
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_COMMENT_INPUT_EXCLUDE_ACTIVITIES
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_GOALS_SEPARATELY
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_NOTIFICATIONS
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_NOTIFICATIONS_CONTROLS
Expand Down Expand Up @@ -202,6 +204,8 @@ class BackupPrefsRepo @Inject constructor(
PrefsProcessor(KEY_SHOW_RECORD_TAG_SELECTION, ::showRecordTagSelection),
PrefsProcessor(KEY_RECORD_TAG_SELECTION_CLOSE_AFTER_ONE, ::recordTagSelectionCloseAfterOne),
PrefsProcessor(KEY_SHOW_RECORD_TAG_SELECTION_EXCLUDE_ACTIVITIES, ::recordTagSelectionExcludeActivities),
PrefsProcessor(KEY_SHOW_COMMENT_INPUT, ::showCommentInput),
PrefsProcessor(KEY_SHOW_COMMENT_INPUT_EXCLUDE_ACTIVITIES, ::commentInputExcludeActivities),
PrefsProcessor(KEY_AUTOSTART_POMODORO_ACTIVITIES, ::autostartPomodoroActivities),
PrefsProcessor(KEY_AUTOMATED_TRACKING_SEND_EVENTS, ::automatedTrackingSendEvents),
PrefsProcessor(KEY_REPEAT_BUTTON_TYPE, ::repeatButtonType),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.util.simpletimetracker.domain.interactor

import com.example.util.simpletimetracker.domain.model.Range
import com.example.util.simpletimetracker.domain.model.Record
import com.example.util.simpletimetracker.domain.model.RecordDataSelectionDialogResult
import com.example.util.simpletimetracker.domain.model.RecordType
import com.example.util.simpletimetracker.domain.model.ResultContainer
import com.example.util.simpletimetracker.domain.model.RunningRecord
Expand All @@ -18,7 +19,7 @@ class AddRunningRecordMediator @Inject constructor(
private val recordTypeToDefaultTagInteractor: RecordTypeToDefaultTagInteractor,
private val notificationGoalCountInteractor: NotificationGoalCountInteractor,
private val activityStartedStoppedBroadcastInteractor: ActivityStartedStoppedBroadcastInteractor,
private val shouldShowTagSelectionInteractor: ShouldShowTagSelectionInteractor,
private val shouldShowRecordDataSelectionInteractor: ShouldShowRecordDataSelectionInteractor,
private val pomodoroStartInteractor: PomodoroStartInteractor,
private val complexRuleProcessActionInteractor: ComplexRuleProcessActionInteractor,
private val updateExternalViewsInteractor: UpdateExternalViewsInteractor,
Expand All @@ -30,13 +31,18 @@ class AddRunningRecordMediator @Inject constructor(
suspend fun tryStartTimer(
typeId: Long,
updateNotificationSwitch: Boolean = true,
onNeedToShowTagSelection: suspend () -> Unit,
commentInputAvailable: Boolean = true,
onNeedToShowTagSelection: suspend (RecordDataSelectionDialogResult) -> Unit,
): Boolean {
// Already running
if (runningRecordInteractor.get(typeId) != null) return false

return if (shouldShowTagSelectionInteractor.execute(typeId)) {
onNeedToShowTagSelection()
val shouldShowTagSelectionResult = shouldShowRecordDataSelectionInteractor.execute(
typeId = typeId,
commentInputAvailable = commentInputAvailable,
)
return if (shouldShowTagSelectionResult.fields.isNotEmpty()) {
onNeedToShowTagSelection(shouldShowTagSelectionResult)
false
} else {
startTimer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,24 @@ class PrefsInteractor @Inject constructor(
.map(Long::toString).toSet()
}

suspend fun getShowCommentInput(): Boolean = withContext(Dispatchers.IO) {
prefsRepo.showCommentInput
}

suspend fun setShowCommentInput(value: Boolean) = withContext(Dispatchers.IO) {
prefsRepo.showCommentInput = value
}

suspend fun getCommentInputExcludeActivities(): List<Long> = withContext(Dispatchers.IO) {
prefsRepo.commentInputExcludeActivities
.mapNotNull(String::toLongOrNull)
}

suspend fun setCommentInputExcludeActivities(value: List<Long>) = withContext(Dispatchers.IO) {
prefsRepo.commentInputExcludeActivities = value
.map(Long::toString).toSet()
}

suspend fun getAutostartPomodoroActivities(): List<Long> = withContext(Dispatchers.IO) {
prefsRepo.autostartPomodoroActivities
.mapNotNull(String::toLongOrNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class RecordTypeInteractor @Inject constructor(
prefsInteractor.getRecordTagSelectionExcludeActivities().toMutableList()
.apply { remove(id) }
.let { prefsInteractor.setRecordTagSelectionExcludeActivities(it) }
prefsInteractor.getCommentInputExcludeActivities().toMutableList()
.apply { remove(id) }
.let { prefsInteractor.setCommentInputExcludeActivities(it) }
recordRepo.removeByType(id)
runningRecordRepo.remove(id)
recordTypeCategoryRepo.removeAllByType(id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.util.simpletimetracker.domain.interactor

import com.example.util.simpletimetracker.domain.model.RecordDataSelectionDialogResult
import javax.inject.Inject

class ShouldShowRecordDataSelectionInteractor @Inject constructor(
private val prefsInteractor: PrefsInteractor,
private val getSelectableTagsInteractor: GetSelectableTagsInteractor,
) {

suspend fun execute(
typeId: Long,
commentInputAvailable: Boolean,
): RecordDataSelectionDialogResult {
val fields = mutableListOf<RecordDataSelectionDialogResult.Field>()
if (needToShowTags(typeId)) {
fields += RecordDataSelectionDialogResult.Field.Tags
}
if (needToShowComment(typeId, commentInputAvailable)) {
fields += RecordDataSelectionDialogResult.Field.Comment
}
return RecordDataSelectionDialogResult(fields)
}

private suspend fun needToShowTags(typeId: Long): Boolean {
if (!prefsInteractor.getShowRecordTagSelection()) return false

val excludedActivities = prefsInteractor.getRecordTagSelectionExcludeActivities()

// Check if activity is excluded from tag dialog.
return if (typeId !in excludedActivities) {
// Check if activity has tags.
val assignableTags = getSelectableTagsInteractor.execute(typeId)
.filterNot { it.archived }
assignableTags.isNotEmpty()
} else {
false
}
}

private suspend fun needToShowComment(
typeId: Long,
commentInputAvailable: Boolean,
): Boolean {
if (!commentInputAvailable) return false
if (!prefsInteractor.getShowCommentInput()) return false

val excludedActivities = prefsInteractor.getCommentInputExcludeActivities()

// Check if activity is excluded from comment input.
return typeId !in excludedActivities
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.util.simpletimetracker.domain.model

data class RecordDataSelectionDialogResult(
val fields: List<Field>,
) {
sealed interface Field {
object Tags : Field
object Comment : Field
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ interface PrefsRepo {

var recordTagSelectionExcludeActivities: Set<String>

var showCommentInput: Boolean

var commentInputExcludeActivities: Set<String>

var autostartPomodoroActivities: Set<String>

var automatedTrackingSendEvents: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RecordTagSelectionDialogFragment :
lateinit var screenFactory: ScreenFactory

private val params: RecordTagSelectionParams by fragmentArgumentDelegate(
key = ARGS_PARAMS, default = RecordTagSelectionParams(),
key = ARGS_PARAMS, default = RecordTagSelectionParams.Empty,
)

override fun onTagSelected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class ActivityStartStopFromBroadcastInteractor @Inject constructor(
val started = addRunningRecordMediator.tryStartTimer(
typeId = selectedTypeId,
updateNotificationSwitch = updateNotificationSwitch,
commentInputAvailable = false, // TODO open activity?
) {
// Update to show tag selection.
update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor
import com.example.util.simpletimetracker.domain.interactor.RemoveRunningRecordMediator
import com.example.util.simpletimetracker.domain.interactor.RunningRecordInteractor
import com.example.util.simpletimetracker.domain.interactor.UpdateRunningRecordFromChangeScreenInteractor
import com.example.util.simpletimetracker.domain.model.RecordDataSelectionDialogResult
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType
import com.example.util.simpletimetracker.feature_base_adapter.activityFilter.ActivityFilterViewData
import com.example.util.simpletimetracker.feature_base_adapter.loader.LoaderViewData
Expand Down Expand Up @@ -85,7 +86,7 @@ class RunningRecordsViewModel @Inject constructor(
// Start running record
val wasStarted = addRunningRecordMediator.tryStartTimer(
typeId = item.id,
onNeedToShowTagSelection = { showTagSelection(item.id) },
onNeedToShowTagSelection = { showTagSelection(item.id, it) },
)
if (wasStarted) {
onRecordTypeWithDefaultDurationClick(item.id)
Expand Down Expand Up @@ -244,8 +245,11 @@ class RunningRecordsViewModel @Inject constructor(
}
}

private fun showTagSelection(typeId: Long) {
router.navigate(RecordTagSelectionParams(typeId))
private fun showTagSelection(
typeId: Long,
result: RecordDataSelectionDialogResult,
) {
router.navigate(RecordTagSelectionParams(typeId, result.toParams()))
}

private fun subscribeToUpdates() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ enum class SettingsBlock {
AdditionalShowTagSelection,
AdditionalTagSelectionExcludeActivities,
AdditionalCloseAfterOneTag,
AdditionalShowCommentInput,
AdditionalCommentInputExcludeActivities,
AdditionalKeepStatisticsRange,
AdditionalRetroactiveTrackingMode,
AdditionalKeepScreenOn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ class SettingsAdditionalViewDataInteractor @Inject constructor(
)
}

val showCommentInput = prefsInteractor.getShowCommentInput()
result += SettingsCheckboxWithButtonViewData(
data = SettingsCheckboxViewData(
block = SettingsBlock.AdditionalShowCommentInput,
title = resourceRepo.getString(R.string.settings_show_comment_input),
subtitle = resourceRepo.getString(R.string.settings_show_comment_input_hint),
isChecked = showCommentInput,
bottomSpaceIsVisible = true,
dividerIsVisible = true,
),
buttonBlock = SettingsBlock.AdditionalCommentInputExcludeActivities,
isButtonVisible = showCommentInput,
)

result += SettingsCheckboxViewData(
block = SettingsBlock.AdditionalKeepStatisticsRange,
title = resourceRepo.getString(R.string.settings_keep_statistics_range),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ class SettingsViewModel @Inject constructor(
const val UNTRACKED_RANGE_START_DIALOG_TAG = "untracked_range_start_dialog_tag"
const val UNTRACKED_RANGE_END_DIALOG_TAG = "untracked_range_end_dialog_tag"
const val START_OF_DAY_DIALOG_TAG = "start_of_day_dialog_tag"
const val EXCLUDE_ACTIVITIES_TYPES_SELECTION = "exclude_activities_types_selection"
const val TAG_EXCLUDE_ACTIVITIES_TYPES_SELECTION = "tag_exclude_activities_types_selection"
const val COMMENT_EXCLUDE_ACTIVITIES_TYPES_SELECTION = "comment_exclude_activities_types_selection"
const val SELECT_ACTIVITIES_TO_AUTOSTART_POMODORO = "select_activities_to_autostart_pomodoro"
}
}
Loading

0 comments on commit fee6ed3

Please sign in to comment.