Skip to content

Commit

Permalink
add file name saving for export
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Oct 5, 2024
1 parent 6f42b31 commit b82e5e9
Show file tree
Hide file tree
Showing 36 changed files with 376 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,9 @@ class ChangeCategoryViewModel @Inject constructor(
}

fun onNoteChange(note: String) {
viewModelScope.launch {
if (note != newNote) {
newNote = note
updateNoteState()
}
if (note != newNote) {
newNote = note
updateNoteState()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,9 @@ class ChangeRecordTagViewModel @Inject constructor(
}

fun onNoteChange(note: String) {
viewModelScope.launch {
if (note != newNote) {
newNote = note
updateNoteState()
}
if (note != newNote) {
newNote = note
updateNoteState()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,9 @@ class ChangeRecordTypeViewModel @Inject constructor(
}

fun onNoteChange(note: String) {
viewModelScope.launch {
if (note != newNote) {
newNote = note
updateNoteState()
}
if (note != newNote) {
newNote = note
updateNoteState()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.util.simpletimetracker.feature_dialogs.csvExportSettings.interactor

import androidx.annotation.ColorInt
import com.example.util.simpletimetracker.core.mapper.ColorMapper
import com.example.util.simpletimetracker.core.mapper.RangeViewDataMapper
import com.example.util.simpletimetracker.core.mapper.TimeMapper
Expand All @@ -13,6 +14,7 @@ import com.example.util.simpletimetracker.feature_base_adapter.recordFilter.Filt
import com.example.util.simpletimetracker.feature_dialogs.R
import com.example.util.simpletimetracker.feature_dialogs.csvExportSettings.model.CsvExportSettingsFilterType
import com.example.util.simpletimetracker.feature_dialogs.csvExportSettings.viewData.CsvExportSettingsViewData
import com.example.util.simpletimetracker.navigation.params.screen.DataExportSettingDialogParams
import javax.inject.Inject

class CsvExportSettingsViewDataInteractor @Inject constructor(
Expand All @@ -24,13 +26,27 @@ class CsvExportSettingsViewDataInteractor @Inject constructor(
) {

suspend fun getViewData(
extra: DataExportSettingDialogParams,
customFileName: String,
rangeLength: RangeLength,
range: Range,
): CsvExportSettingsViewData {
val useMilitaryTime = prefsInteractor.getUseMilitaryTimeFormat()
val isDarkTheme = prefsInteractor.getDarkMode()
val fileName = customFileName.ifBlank { extra.defaultFileName }
val isCustomFileNameSelected = fileName != extra.defaultFileName

return CsvExportSettingsViewData(
fileName = fileName,
fileNameTextColor = mapTextColor(
isActive = isCustomFileNameSelected,
isDarkTheme = isDarkTheme,
),
fileNameHint = if (isCustomFileNameSelected) {
resourceRepo.getString(R.string.change_record_type_name_hint)
} else {
resourceRepo.getString(R.string.csv_export_settings_filename_default)
},
rangeStartString = timeMapper.formatDateTimeYear(
time = range.timeStarted,
useMilitaryTime = useMilitaryTime,
Expand All @@ -39,13 +55,10 @@ class CsvExportSettingsViewDataInteractor @Inject constructor(
time = range.timeEnded,
useMilitaryTime = useMilitaryTime,
),
textColor = if (rangeLength is RangeLength.Custom) {
R.attr.appTextPrimaryColor
} else {
R.attr.appTextHintColor
}.let {
resourceRepo.getThemedAttr(it, isDarkTheme)
},
textColor = mapTextColor(
isActive = rangeLength is RangeLength.Custom,
isDarkTheme = isDarkTheme,
),
filters = getDateFiltersViewData(
currentRange = rangeLength,
),
Expand Down Expand Up @@ -107,4 +120,18 @@ class CsvExportSettingsViewDataInteractor @Inject constructor(
removeBtnVisible = false,
)
}

@ColorInt
private fun mapTextColor(
isActive: Boolean,
isDarkTheme: Boolean,
): Int {
return if (isActive) {
R.attr.appTextPrimaryColor
} else {
R.attr.appTextHintColor
}.let {
resourceRepo.getThemedAttr(it, isDarkTheme)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.viewModels
import com.example.util.simpletimetracker.core.base.BaseBottomSheetFragment
import com.example.util.simpletimetracker.core.dialog.DataExportSettingsDialogListener
Expand Down Expand Up @@ -45,7 +46,7 @@ class CsvExportSettingsDialogFragment :
)
}
private val params: DataExportSettingDialogParams by fragmentArgumentDelegate(
key = ARGS_PARAMS, default = DataExportSettingDialogParams(),
key = ARGS_PARAMS, default = DataExportSettingDialogParams.Empty,
)

private var dialogListener: DataExportSettingsDialogListener? = null
Expand All @@ -71,6 +72,7 @@ class CsvExportSettingsDialogFragment :
}

override fun initUx(): Unit = with(binding) {
etChangeRecordTypeName.doAfterTextChanged { viewModel.onNameChange(it.toString()) }
fieldCsvExportSettingsTimeStarted.setOnClick(viewModel::onRangeStartClick)
fieldCsvExportSettingsTimeEnded.setOnClick(viewModel::onRangeEndClick)
btnCsvExportSettingsRange.setOnClick(viewModel::onExportClick)
Expand All @@ -89,6 +91,11 @@ class CsvExportSettingsDialogFragment :
private fun updateViewDataState(
viewData: CsvExportSettingsViewData,
) = with(binding) {
if (etChangeRecordTypeName.text.toString() != viewData.fileName) {
etChangeRecordTypeName.setText(viewData.fileName)
}
inputCsvExportSettingsFileName.hint = viewData.fileNameHint
etChangeRecordTypeName.setTextColor(viewData.fileNameTextColor)
filterSelectionAdapter.replace(viewData.filters)
tvCsvExportSettingsTimeStarted.text = viewData.rangeStartString
tvCsvExportSettingsTimeStarted.setTextColor(viewData.textColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import androidx.annotation.ColorInt
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType

data class CsvExportSettingsViewData(
val fileName: String,
@ColorInt val fileNameTextColor: Int,
val fileNameHint: String,
val rangeStartString: String,
val rangeEndString: String,
@ColorInt val textColor: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.viewModelScope
import com.example.util.simpletimetracker.core.base.BaseViewModel
import com.example.util.simpletimetracker.core.extension.lazySuspend
import com.example.util.simpletimetracker.core.extension.set
import com.example.util.simpletimetracker.core.extension.toModel
import com.example.util.simpletimetracker.core.extension.toParams
import com.example.util.simpletimetracker.core.mapper.TimeMapper
import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor
Expand Down Expand Up @@ -41,8 +42,18 @@ class CsvExportSettingsViewModel @Inject constructor(
val dataExportSettingsResult: LiveData<DataExportSettingsResult> =
MutableLiveData()

private var customFileName: String = ""
private var rangeLength: RangeLength = RangeLength.All

fun onNameChange(name: String) {
viewModelScope.launch {
if (name != customFileName) {
customFileName = name
updateViewData()
}
}
}

fun onFilterClick(item: FilterViewData) = viewModelScope.launch {
val itemType = item.type as? CsvExportSettingsFilterType ?: return@launch
onNewRangeSelected(itemType.rangeLength)
Expand Down Expand Up @@ -84,7 +95,8 @@ class CsvExportSettingsViewModel @Inject constructor(

fun onExportClick() = viewModelScope.launch {
DataExportSettingsResult(
tag = extra.tag.orEmpty(),
tag = extra.tag,
customFileName = customFileName,
range = rangeLength.toParams(),
).let(dataExportSettingsResult::set)
}
Expand Down Expand Up @@ -129,8 +141,9 @@ class CsvExportSettingsViewModel @Inject constructor(
}
}

private suspend fun initialize() {
rangeLength = prefsInteractor.getFileExportRange()
private fun initialize() {
rangeLength = extra.selectedRange.toModel()
customFileName = extra.customFileName
}

private suspend fun updateViewData() {
Expand All @@ -139,6 +152,8 @@ class CsvExportSettingsViewModel @Inject constructor(

private suspend fun loadViewData(): CsvExportSettingsViewData {
return viewDataInteractor.getViewData(
extra = extra,
customFileName = customFileName,
rangeLength = rangeLength,
range = getRange(),
)
Expand Down
Loading

0 comments on commit b82e5e9

Please sign in to comment.