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

DROID-1504 App | Stability | Fix or try/catch sentry crashes from 0.23.14 (#245)

This commit is contained in:
Evgenii Kozlov 2023-07-25 13:17:22 +02:00 committed by uburoiubu
parent ec3fe786b8
commit bdc1f26400
No known key found for this signature in database
GPG key ID: C8FB80E0A595FBB6
4 changed files with 68 additions and 43 deletions

View file

@ -53,23 +53,26 @@ abstract class SelectCoverGalleryFragment :
)
}
val getContent = registerForActivityResult(GetImageContract()) { uri: Uri? ->
if (uri != null) {
try {
val path = uri.parseImagePath(requireContext())
vm.onImagePicked(ctx, path)
} catch (e: Exception) {
toast("Error while parsing path for cover image")
Timber.d(e, "Error while parsing path for cover image")
}
} else {
toast("Error while upload cover image, URI is null")
Timber.e("Error while upload cover image, URI is null")
}
private val getContent = try { getContentLauncher() } catch (e: Exception) {
null
}
private val permissionReadStorage =
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { grantResults ->
private fun getContentLauncher() = registerForActivityResult(GetImageContract()) { uri: Uri? ->
if (uri != null) {
try {
val path = uri.parseImagePath(requireContext())
vm.onImagePicked(ctx, path)
} catch (e: Exception) {
toast("Error while parsing path for cover image")
Timber.d(e, "Error while parsing path for cover image")
}
} else {
toast("Error while upload cover image, URI is null")
Timber.e("Error while upload cover image, URI is null")
}
}
private val permissionReadStorage = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { grantResults ->
val readResult = grantResults[Manifest.permission.READ_EXTERNAL_STORAGE]
if (readResult == true) {
openGallery()
@ -159,7 +162,12 @@ abstract class SelectCoverGalleryFragment :
}
private fun openGallery() {
getContent.launch(SELECT_IMAGE_CODE)
try {
getContent?.launch(SELECT_IMAGE_CODE)
} catch (e: Exception) {
Timber.e(e, "Error while opening gallery")
toast("Error while opening gallery: ${e.message}")
}
}
private fun hasReadStoragePermission(): Boolean = ContextCompat.checkSelfPermission(

View file

@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import timber.log.Timber
abstract class BaseBottomSheetComposeFragment : BottomSheetDialogFragment() {
@ -28,6 +29,7 @@ abstract class BaseBottomSheetComposeFragment : BottomSheetDialogFragment() {
private val currentNavigationId by lazy { getNavigationId() }
private val throttleFlow = MutableSharedFlow<() -> Unit>(0)
@Deprecated("Not safe enough.")
protected fun safeNavigate(
@IdRes id: Int,
args: Bundle? = null
@ -35,7 +37,11 @@ abstract class BaseBottomSheetComposeFragment : BottomSheetDialogFragment() {
jobs += this.lifecycleScope.launch {
throttleFlow.emit {
if (currentNavigationId == getNavigationId()) {
findNavController().navigate(id, args)
try {
findNavController().navigate(id, args)
} catch (e: Exception) {
Timber.e(e, "safeNavigateMethod is not safe!")
}
}
}
}

View file

@ -3478,18 +3478,23 @@ class EditorViewModel(
}
}
fun onCopy(
range: IntRange?
) {
fun onCopy(range: IntRange?) {
Timber.d("onCopy, ")
viewModelScope.launch {
orchestrator.proxies.intents.send(
Intent.Clipboard.Copy(
context = context,
range = range,
blocks = listOf(blocks.first { it.id == focus.value })
val target = blocks.find { it.id == focus.value }
if (target != null) {
orchestrator.proxies.intents.send(
Intent.Clipboard.Copy(
context = context,
range = range,
blocks = listOf(target)
)
)
)
} else {
Timber.e("Error while copying: target not found").also {
sendToast("Something went wrong. Please try again.")
}
}
}
}

View file

@ -115,23 +115,29 @@ open class FilterViewModel(
private fun initStates() {
jobs += viewModelScope.launch {
objectState.filterIsInstance<ObjectState.DataView>().collect { state ->
val viewer = state.viewerById(session.currentViewerId.value) ?: return@collect
val key = relationKey
if (key != null) {
val relation = storeOfRelations.getByKey(key)
if (relation != null) {
this@FilterViewModel.relation = relation
setRelationState(
viewer = viewer,
relation = relation
)
setConditionState(viewer, relation, filterIndex)
setValueStates(
condition = conditionState.value?.condition,
index = filterIndex
)
} else {
Timber.e("Couldn't find relation in StoreOfRelations by relationKey:[$relationKey]")
try {
val viewer = state.viewerById(session.currentViewerId.value) ?: return@collect
val key = relationKey
if (key != null) {
val relation = storeOfRelations.getByKey(key)
if (relation != null) {
this@FilterViewModel.relation = relation
setRelationState(
viewer = viewer,
relation = relation
)
setConditionState(viewer, relation, filterIndex)
setValueStates(
condition = conditionState.value?.condition,
index = filterIndex
)
} else {
Timber.e("Couldn't find relation in StoreOfRelations by relationKey:[$relationKey]")
}
}
} catch (e: Exception) {
Timber.e(e, "Error in the filter flow").also {
commands.emit(Commands.Toast("Something went wrong. Please try again"))
}
}
}