1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-10 10:00:44 +09:00

fix the issue

This commit is contained in:
E. Kozlov 2021-11-09 19:38:58 +03:00
parent 7b5fb2bd85
commit f06a1ebddb
3 changed files with 53 additions and 28 deletions

View file

@ -16,6 +16,7 @@
### Fixes & tech 🚒
* Sets | Fix | Status value missing due to incorrect value parsing (#1911)
* Sets | Fix | App crashes when opening url from relation in a browser and returning back to the app (#1911)
## Version 0.3.3

View file

@ -81,6 +81,11 @@ open class RelationTextValueFragment : BaseBottomSheetFragment() {
vm.onStart(relationId = relationId, recordId = objectId)
}
override fun onStop() {
super.onStop()
vm.onStop()
}
private fun handleActions(action: EditGridCellAction) {
when (action) {
is EditGridCellAction.Url -> {

View file

@ -2,12 +2,19 @@ package com.anytypeio.anytype.presentation.sets
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.core_utils.ext.cancel
import com.anytypeio.anytype.presentation.relations.NumberParser
import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider
import com.anytypeio.anytype.presentation.relations.providers.ObjectValueProvider
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
import timber.log.Timber
class RelationTextValueViewModel(
private val relations: ObjectRelationProvider,
@ -17,36 +24,48 @@ class RelationTextValueViewModel(
val views = MutableStateFlow<List<RelationTextValueView>>(emptyList())
val title = MutableStateFlow("")
private val jobs = mutableListOf<Job>()
fun onStart(relationId: Id, recordId: String) {
val relation = relations.get(relationId)
val values = values.get(recordId)
title.value = relation.name
views.value = listOf(
when (relation.format) {
Relation.Format.SHORT_TEXT -> {
RelationTextValueView.TextShort(value = values[relationId] as? String)
}
Relation.Format.LONG_TEXT -> {
RelationTextValueView.Text(value = values[relationId] as? String)
}
Relation.Format.NUMBER -> {
val value = values[relationId]
RelationTextValueView.Number(
value = NumberParser.parse(value)
)
}
Relation.Format.URL -> {
RelationTextValueView.Url(value = values[relationId] as? String)
}
Relation.Format.EMAIL -> {
RelationTextValueView.Email(value = values[relationId] as? String)
}
Relation.Format.PHONE -> {
RelationTextValueView.Phone(value = values[relationId] as? String)
}
else -> throw IllegalArgumentException("Wrong format:${relation.format}")
jobs += viewModelScope.launch {
val pipeline = combine(
relations.subscribe(relationId),
values.subscribe(recordId)
) { relation, values ->
title.value = relation.name
views.value = listOf(
when (relation.format) {
Relation.Format.SHORT_TEXT -> {
RelationTextValueView.TextShort(value = values[relationId] as? String)
}
Relation.Format.LONG_TEXT -> {
RelationTextValueView.Text(value = values[relationId] as? String)
}
Relation.Format.NUMBER -> {
val value = values[relationId]
RelationTextValueView.Number(
value = NumberParser.parse(value)
)
}
Relation.Format.URL -> {
RelationTextValueView.Url(value = values[relationId] as? String)
}
Relation.Format.EMAIL -> {
RelationTextValueView.Email(value = values[relationId] as? String)
}
Relation.Format.PHONE -> {
RelationTextValueView.Phone(value = values[relationId] as? String)
}
else -> throw IllegalArgumentException("Wrong format:${relation.format}")
}
)
}
)
pipeline.collect()
}
}
fun onStop() {
jobs.cancel()
}
class Factory(