Skip to content

Commit

Permalink
add name trim
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Jan 11, 2025
1 parent 8c18ff2 commit a1de6f4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package com.example.util.simpletimetracker.core.extension
import android.content.BroadcastReceiver
import android.graphics.Rect
import android.os.StrictMode
import android.text.Spanned
import android.view.View
import androidx.core.text.HtmlCompat
import androidx.lifecycle.LifecycleOwner
import androidx.viewpager2.widget.ViewPager2
import com.example.util.simpletimetracker.core.utils.getLifecycleObserverAdapter
Expand Down Expand Up @@ -134,7 +132,3 @@ fun View.getCoordinates(): Coordinates {
bottom = rect.bottom,
)
}

fun String.fromHtml(): Spanned {
return HtmlCompat.fromHtml(this, HtmlCompat.FROM_HTML_MODE_LEGACY)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.util.simpletimetracker.core.extension

import android.text.Spanned
import androidx.core.text.HtmlCompat

fun String.fromHtml(): Spanned {
return HtmlCompat.fromHtml(this, HtmlCompat.FROM_HTML_MODE_LEGACY)
}

fun String.trimIfNotBlank(): String {
return if (this.isNotBlank()) return this.trim() else this
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.example.util.simpletimetracker.core.delegates.colorSelection.ColorSel
import com.example.util.simpletimetracker.core.delegates.colorSelection.ColorSelectionViewModelDelegateImpl
import com.example.util.simpletimetracker.domain.extension.addOrRemove
import com.example.util.simpletimetracker.core.extension.set
import com.example.util.simpletimetracker.core.extension.trimIfNotBlank
import com.example.util.simpletimetracker.core.interactor.SnackBarMessageNavigationInteractor
import com.example.util.simpletimetracker.core.mapper.ActivityFilterViewDataMapper
import com.example.util.simpletimetracker.core.view.ViewChooserStateDelegate
Expand Down Expand Up @@ -171,7 +172,7 @@ class ChangeActivityFilterViewModel @Inject constructor(
id = filterId,
selectedIds = newSelectedIds,
type = newType,
name = newName,
name = newName.trimIfNotBlank(),
color = colorSelectionViewModelDelegateImpl.newColor,
selected = wasSelected,
).let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.example.util.simpletimetracker.core.base.ViewModelDelegate
import com.example.util.simpletimetracker.core.delegates.colorSelection.ColorSelectionViewModelDelegate
import com.example.util.simpletimetracker.core.delegates.colorSelection.ColorSelectionViewModelDelegateImpl
import com.example.util.simpletimetracker.core.extension.set
import com.example.util.simpletimetracker.core.extension.trimIfNotBlank
import com.example.util.simpletimetracker.core.interactor.SnackBarMessageNavigationInteractor
import com.example.util.simpletimetracker.core.interactor.StatisticsDetailNavigationInteractor
import com.example.util.simpletimetracker.core.mapper.CategoryViewDataMapper
Expand Down Expand Up @@ -202,7 +203,7 @@ class ChangeCategoryViewModel @Inject constructor(
// Zero id creates new record
Category(
id = categoryId,
name = newName,
name = newName.trimIfNotBlank(),
color = colorSelectionViewModelDelegateImpl.newColor,
note = newNote,
).let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.example.util.simpletimetracker.core.delegates.colorSelection.ColorSel
import com.example.util.simpletimetracker.core.delegates.iconSelection.viewModelDelegate.IconSelectionViewModelDelegate
import com.example.util.simpletimetracker.core.delegates.iconSelection.viewModelDelegate.IconSelectionViewModelDelegateImpl
import com.example.util.simpletimetracker.core.extension.set
import com.example.util.simpletimetracker.core.extension.trimIfNotBlank
import com.example.util.simpletimetracker.core.interactor.SnackBarMessageNavigationInteractor
import com.example.util.simpletimetracker.core.interactor.StatisticsDetailNavigationInteractor
import com.example.util.simpletimetracker.core.mapper.CategoryViewDataMapper
Expand Down Expand Up @@ -272,7 +273,7 @@ class ChangeRecordTagViewModel @Inject constructor(
// Zero id creates new record
RecordTag(
id = recordTagId,
name = newName,
name = newName.trimIfNotBlank(),
icon = iconSelectionViewModelDelegateImpl.newIcon,
color = colorSelectionViewModelDelegateImpl.newColor,
iconColorSource = newIconColorSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.example.util.simpletimetracker.core.delegates.colorSelection.ColorSel
import com.example.util.simpletimetracker.core.delegates.iconSelection.viewModelDelegate.IconSelectionViewModelDelegate
import com.example.util.simpletimetracker.core.delegates.iconSelection.viewModelDelegate.IconSelectionViewModelDelegateImpl
import com.example.util.simpletimetracker.core.extension.set
import com.example.util.simpletimetracker.core.extension.trimIfNotBlank
import com.example.util.simpletimetracker.core.interactor.SnackBarMessageNavigationInteractor
import com.example.util.simpletimetracker.core.interactor.StatisticsDetailNavigationInteractor
import com.example.util.simpletimetracker.core.mapper.RecordTypeViewDataMapper
Expand All @@ -19,7 +20,6 @@ import com.example.util.simpletimetracker.core.view.ViewChooserStateDelegate
import com.example.util.simpletimetracker.domain.extension.addOrRemove
import com.example.util.simpletimetracker.domain.extension.orZero
import com.example.util.simpletimetracker.domain.activityFilter.interactor.ActivityFilterInteractor
import com.example.util.simpletimetracker.domain.notifications.interactor.NotificationTypeInteractor
import com.example.util.simpletimetracker.domain.prefs.interactor.PrefsInteractor
import com.example.util.simpletimetracker.domain.category.interactor.RecordTypeCategoryInteractor
import com.example.util.simpletimetracker.domain.recordType.interactor.RecordTypeInteractor
Expand All @@ -28,7 +28,6 @@ import com.example.util.simpletimetracker.domain.record.interactor.RemoveRunning
import com.example.util.simpletimetracker.domain.record.interactor.RunningRecordInteractor
import com.example.util.simpletimetracker.domain.notifications.interactor.UpdateExternalViewsInteractor
import com.example.util.simpletimetracker.domain.color.model.AppColor
import com.example.util.simpletimetracker.domain.wear.WearInteractor
import com.example.util.simpletimetracker.domain.statistics.model.ChartFilterType
import com.example.util.simpletimetracker.domain.recordType.model.RecordType
import com.example.util.simpletimetracker.domain.recordType.model.RecordTypeGoal
Expand Down Expand Up @@ -62,8 +61,6 @@ class ChangeRecordTypeViewModel @Inject constructor(
private val viewDataInteractor: ChangeRecordTypeViewDataInteractor,
private val recordTypeCategoryInteractor: RecordTypeCategoryInteractor,
private val activityFilterInteractor: ActivityFilterInteractor,
private val wearInteractor: WearInteractor,
private val notificationTypeInteractor: NotificationTypeInteractor,
private val externalViewsInteractor: UpdateExternalViewsInteractor,
private val prefsInteractor: PrefsInteractor,
private val recordTypeViewDataMapper: RecordTypeViewDataMapper,
Expand Down Expand Up @@ -398,7 +395,7 @@ class ChangeRecordTypeViewModel @Inject constructor(
private suspend fun saveRecordType(): Long {
val recordType = RecordType(
id = recordTypeId,
name = newName,
name = newName.trimIfNotBlank(),
icon = iconSelectionViewModelDelegateImpl.newIcon,
color = colorSelectionViewModelDelegateImpl.newColor,
defaultDuration = newDefaultDuration,
Expand Down

0 comments on commit a1de6f4

Please sign in to comment.