mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3105 Widgets | Tech | Using field parser to get object name (#1873)
This commit is contained in:
parent
c84dad4e6f
commit
d976b7321f
16 changed files with 130 additions and 113 deletions
|
@ -1,6 +1,6 @@
|
|||
package com.anytypeio.anytype.device.providers
|
||||
|
||||
import com.anytypeio.anytype.core_models.DEFAULT_TIME_STYLE
|
||||
import com.anytypeio.anytype.core_models.DEFAULT_DATE_FORMAT_STYLE
|
||||
import com.anytypeio.anytype.core_models.FALLBACK_DATE_PATTERN
|
||||
import com.anytypeio.anytype.domain.misc.LocaleProvider
|
||||
import java.text.DateFormat
|
||||
|
@ -34,7 +34,7 @@ class AppDefaultDateFormatProviderImpl @Inject constructor(
|
|||
override fun provide(): String {
|
||||
return try {
|
||||
val locale = localeProvider.locale()
|
||||
val dateFormat = DateFormat.getDateInstance(DEFAULT_TIME_STYLE, locale)
|
||||
val dateFormat = DateFormat.getDateInstance(DEFAULT_DATE_FORMAT_STYLE, locale)
|
||||
if (dateFormat is SimpleDateFormat) {
|
||||
dateFormat.toPattern()
|
||||
} else {
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
package com.anytypeio.anytype.device.providers
|
||||
|
||||
import android.text.format.DateUtils
|
||||
import com.anytypeio.anytype.core_models.FALLBACK_DATE_PATTERN
|
||||
import com.anytypeio.anytype.core_models.RelativeDate
|
||||
import com.anytypeio.anytype.core_models.TimeInMillis
|
||||
import com.anytypeio.anytype.core_models.TimeInSeconds
|
||||
import com.anytypeio.anytype.domain.misc.DateProvider
|
||||
import com.anytypeio.anytype.domain.misc.DateType
|
||||
import com.anytypeio.anytype.domain.misc.LocaleProvider
|
||||
import com.anytypeio.anytype.domain.vault.ObserveVaultSettings
|
||||
import java.text.DateFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.time.Instant
|
||||
|
@ -20,27 +18,15 @@ import java.time.temporal.ChronoUnit
|
|||
import java.util.Date
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
class DateProviderImpl @Inject constructor(
|
||||
private val defaultZoneId: ZoneId,
|
||||
private val localeProvider: LocaleProvider,
|
||||
private val vaultSettings: ObserveVaultSettings,
|
||||
scope: CoroutineScope
|
||||
private val appDefaultDateFormatProvider: AppDefaultDateFormatProvider
|
||||
) : DateProvider {
|
||||
|
||||
private val defaultDateFormat = MutableStateFlow(FALLBACK_DATE_PATTERN)
|
||||
|
||||
init {
|
||||
scope.launch {
|
||||
vaultSettings.flow().collect { settings ->
|
||||
defaultDateFormat.value = settings.dateFormat
|
||||
}
|
||||
}
|
||||
}
|
||||
private val defaultDateFormat get() = appDefaultDateFormatProvider.provide()
|
||||
|
||||
override fun calculateDateType(date: TimeInSeconds): DateType {
|
||||
val dateInstant = Instant.ofEpochSecond(date)
|
||||
|
@ -172,10 +158,9 @@ class DateProviderImpl @Inject constructor(
|
|||
timestamp: TimeInMillis,
|
||||
timeStyle: Int
|
||||
): Pair<String, String> {
|
||||
Timber.d("Formatting timestamp [$timestamp] to date and time")
|
||||
return try {
|
||||
val locale = localeProvider.locale()
|
||||
val datePattern = defaultDateFormat.value
|
||||
val datePattern = defaultDateFormat
|
||||
val timePattern =
|
||||
(DateFormat.getTimeInstance(timeStyle, locale) as SimpleDateFormat).toPattern()
|
||||
val dateFormatter = SimpleDateFormat(datePattern, locale)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.anytypeio.anytype
|
||||
|
||||
import com.anytypeio.anytype.device.providers.AppDefaultDateFormatProvider
|
||||
import com.anytypeio.anytype.device.providers.AppDefaultDateFormatProviderImpl
|
||||
import com.anytypeio.anytype.device.providers.DateProviderImpl
|
||||
import com.anytypeio.anytype.domain.misc.DateProvider
|
||||
import com.anytypeio.anytype.domain.misc.LocaleProvider
|
||||
|
@ -27,9 +29,12 @@ class DateProviderImplTest {
|
|||
|
||||
lateinit var dateProviderImpl: DateProvider
|
||||
|
||||
lateinit var appDefaultDateFormatProvider: AppDefaultDateFormatProvider
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
appDefaultDateFormatProvider = AppDefaultDateFormatProviderImpl(localeProvider)
|
||||
Mockito.`when`(localeProvider.locale()).thenReturn(Locale.getDefault())
|
||||
Mockito.`when`(localeProvider.language()).thenReturn("en")
|
||||
}
|
||||
|
@ -72,8 +77,7 @@ class DateProviderImplTest {
|
|||
dateProviderImpl = DateProviderImpl(
|
||||
defaultZoneId = zoneId,
|
||||
localeProvider = localeProvider,
|
||||
vaultSettings = observeVaultSettings,
|
||||
scope = backgroundScope
|
||||
appDefaultDateFormatProvider = appDefaultDateFormatProvider,
|
||||
)
|
||||
val startOfDayInLocalZone =
|
||||
dateProviderImpl.adjustFromStartOfDayInUserTimeZoneToUTC(
|
||||
|
@ -122,8 +126,7 @@ class DateProviderImplTest {
|
|||
dateProviderImpl = DateProviderImpl(
|
||||
defaultZoneId = zoneId,
|
||||
localeProvider = localeProvider,
|
||||
vaultSettings = observeVaultSettings,
|
||||
scope = backgroundScope
|
||||
appDefaultDateFormatProvider = appDefaultDateFormatProvider,
|
||||
)
|
||||
val startOfDayInLocalZone =
|
||||
dateProviderImpl.adjustFromStartOfDayInUserTimeZoneToUTC(utcTimestamp * 1000)
|
||||
|
@ -169,8 +172,7 @@ class DateProviderImplTest {
|
|||
dateProviderImpl = DateProviderImpl(
|
||||
defaultZoneId = zoneId,
|
||||
localeProvider = localeProvider,
|
||||
vaultSettings = observeVaultSettings,
|
||||
scope = backgroundScope
|
||||
appDefaultDateFormatProvider = appDefaultDateFormatProvider,
|
||||
)
|
||||
val startOfDayInLocalZone =
|
||||
dateProviderImpl.adjustFromStartOfDayInUserTimeZoneToUTC(utcTimestamp * 1000)
|
||||
|
@ -215,8 +217,7 @@ class DateProviderImplTest {
|
|||
dateProviderImpl = DateProviderImpl(
|
||||
defaultZoneId = zoneId,
|
||||
localeProvider = localeProvider,
|
||||
vaultSettings = observeVaultSettings,
|
||||
scope = backgroundScope
|
||||
appDefaultDateFormatProvider = appDefaultDateFormatProvider,
|
||||
)
|
||||
val startOfDayInLocalZone =
|
||||
dateProviderImpl.adjustFromStartOfDayInUserTimeZoneToUTC(utcTimestamp * 1000)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue