mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3131 Date fields | Open date object on locked values (#1877)
This commit is contained in:
parent
979d67b59c
commit
9b1e9bb23c
55 changed files with 465 additions and 427 deletions
|
@ -9,7 +9,6 @@ import com.anytypeio.anytype.domain.misc.DateProvider
|
|||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
|
||||
import com.anytypeio.anytype.domain.`object`.GetObject
|
||||
import com.anytypeio.anytype.domain.objects.GetDateObjectByTimestamp
|
||||
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
|
||||
import com.anytypeio.anytype.domain.objects.StoreOfRelations
|
||||
import com.anytypeio.anytype.domain.page.CreateObject
|
||||
|
@ -29,7 +28,6 @@ class DateObjectVMFactory @Inject constructor(
|
|||
private val storeOfRelations: StoreOfRelations,
|
||||
private val storeOfObjectTypes: StoreOfObjectTypes,
|
||||
private val storelessSubscriptionContainer: StorelessSubscriptionContainer,
|
||||
private val getDateObjectByTimestamp: GetDateObjectByTimestamp,
|
||||
private val dateProvider: DateProvider,
|
||||
private val spaceSyncAndP2PStatusProvider: SpaceSyncAndP2PStatusProvider,
|
||||
private val createObject: CreateObject,
|
||||
|
@ -49,7 +47,6 @@ class DateObjectVMFactory @Inject constructor(
|
|||
storeOfRelations = storeOfRelations,
|
||||
storeOfObjectTypes = storeOfObjectTypes,
|
||||
storelessSubscriptionContainer = storelessSubscriptionContainer,
|
||||
getDateObjectByTimestamp = getDateObjectByTimestamp,
|
||||
dateProvider = dateProvider,
|
||||
spaceSyncAndP2PStatusProvider = spaceSyncAndP2PStatusProvider,
|
||||
createObject = createObject,
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.anytypeio.anytype.core_models.DVSortType
|
|||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.core_models.Struct
|
||||
import com.anytypeio.anytype.core_models.TimeInSeconds
|
||||
import com.anytypeio.anytype.core_models.getSingleValue
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
|
@ -22,7 +21,6 @@ import com.anytypeio.anytype.domain.misc.DateProvider
|
|||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
|
||||
import com.anytypeio.anytype.domain.`object`.GetObject
|
||||
import com.anytypeio.anytype.domain.objects.GetDateObjectByTimestamp
|
||||
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
|
||||
import com.anytypeio.anytype.domain.objects.StoreOfRelations
|
||||
import com.anytypeio.anytype.domain.page.CreateObject
|
||||
|
@ -81,7 +79,6 @@ class DateObjectViewModel(
|
|||
private val storeOfRelations: StoreOfRelations,
|
||||
private val storeOfObjectTypes: StoreOfObjectTypes,
|
||||
private val storelessSubscriptionContainer: StorelessSubscriptionContainer,
|
||||
private val getDateObjectByTimestamp: GetDateObjectByTimestamp,
|
||||
private val dateProvider: DateProvider,
|
||||
private val spaceSyncAndP2PStatusProvider: SpaceSyncAndP2PStatusProvider,
|
||||
private val createObject: CreateObject,
|
||||
|
@ -176,16 +173,18 @@ class DateObjectViewModel(
|
|||
resetLimit()
|
||||
}
|
||||
|
||||
private fun proceedWithReopenDateObjectByTimestamp(timestamp: TimeInSeconds) {
|
||||
proceedWithGettingDateByTimestamp(
|
||||
timestamp = timestamp
|
||||
) { dateObject ->
|
||||
val id = dateObject?.getSingleValue<String>(Relations.ID)
|
||||
if (id != null) {
|
||||
reopenDateObject(id)
|
||||
} else {
|
||||
Timber.e("GettingDateByTimestamp error, object has no id")
|
||||
}
|
||||
private fun proceedWithReopenDateObjectByTimestamp(timeInSeconds: TimeInSeconds) {
|
||||
viewModelScope.launch {
|
||||
fieldParser.getDateObjectByTimeInSeconds(
|
||||
timeInSeconds = timeInSeconds,
|
||||
spaceId = vmParams.spaceId,
|
||||
actionSuccess = { obj ->
|
||||
reopenDateObject(obj.id)
|
||||
},
|
||||
actionFailure = {
|
||||
Timber.e("GettingDateByTimestamp error, object has no id")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,23 +321,6 @@ class DateObjectViewModel(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun proceedWithGettingDateByTimestamp(timestamp: Long, action: (Struct?) -> Unit) {
|
||||
val params = GetDateObjectByTimestamp.Params(
|
||||
space = vmParams.spaceId,
|
||||
timestamp = timestamp
|
||||
)
|
||||
Timber.d("Start ObjectDateByTimestamp with params: [$params]")
|
||||
viewModelScope.launch {
|
||||
getDateObjectByTimestamp.async(params).fold(
|
||||
onSuccess = { dateObject ->
|
||||
Timber.d("ObjectDateByTimestamp Success, dateObject: [$dateObject]")
|
||||
action(dateObject)
|
||||
},
|
||||
onFailure = { e -> Timber.e(e, "ObjectDateByTimestamp Error") }
|
||||
)
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region Subscription
|
||||
|
@ -532,7 +514,7 @@ class DateObjectViewModel(
|
|||
|
||||
if (isValid) {
|
||||
proceedWithReopenDateObjectByTimestamp(
|
||||
timestamp = newTimestamp
|
||||
timeInSeconds = newTimestamp
|
||||
)
|
||||
} else {
|
||||
showDateOutOfRangeError()
|
||||
|
@ -727,7 +709,7 @@ class DateObjectViewModel(
|
|||
Timber.d("Selected date in millis: [$timeInMillis]")
|
||||
if (timeInMillis == null) return
|
||||
proceedWithReopenDateObjectByTimestamp(
|
||||
timestamp = dateProvider.adjustFromStartOfDayInUserTimeZoneToUTC(
|
||||
timeInSeconds = dateProvider.adjustFromStartOfDayInUserTimeZoneToUTC(
|
||||
timeInMillis = timeInMillis
|
||||
)
|
||||
)
|
||||
|
@ -740,14 +722,14 @@ class DateObjectViewModel(
|
|||
DateEvent.Calendar.OnTodayClick -> {
|
||||
uiCalendarState.value = UiCalendarState.Hidden
|
||||
proceedWithReopenDateObjectByTimestamp(
|
||||
timestamp = dateProvider.getTimestampForTodayAtStartOfDay()
|
||||
timeInSeconds = dateProvider.getTimestampForTodayAtStartOfDay()
|
||||
)
|
||||
}
|
||||
|
||||
DateEvent.Calendar.OnTomorrowClick -> {
|
||||
uiCalendarState.value = UiCalendarState.Hidden
|
||||
proceedWithReopenDateObjectByTimestamp(
|
||||
timestamp = dateProvider.getTimestampForTomorrowAtStartOfDay()
|
||||
timeInSeconds = dateProvider.getTimestampForTomorrowAtStartOfDay()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue