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

DROID-99 App | Fix | Fix double clicks & crashes (#2762)

This commit is contained in:
Mikhail 2022-12-15 11:25:15 +03:00 committed by GitHub
parent 2ca05327fd
commit 0a04c4701b
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 61 additions and 39 deletions

View file

@ -257,7 +257,7 @@ class DashboardFragment :
is HomeDashboardViewModel.Alert.Delete -> {
val dialog = DeleteAlertFragment.new(alert.count)
dialog.onDeletionAccepted = { vm.onDeletionAccepted() }
dialog.show(childFragmentManager, null)
dialog.showChildFragment()
}
}
}

View file

@ -811,7 +811,7 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
vm.actions.collectLatest {
binding.blockActionToolbar.bind(it)
delay(DEFAULT_DELAY_BLOCK_ACTION_TOOLBAR)
binding.blockActionToolbar.post {
handler.post {
binding.blockActionToolbar.scrollToPosition(0, smooth = true)
}
}
@ -1695,7 +1695,7 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
if (minPosY <= cursorCoord) {
val scrollY = (parentBottom - minPosY) - (parentBottom - cursorCoord)
Timber.d("New scroll y: $scrollY")
binding.recycler.post {
handler.post {
binding.recycler.smoothScrollBy(0, scrollY)
}
}
@ -1725,7 +1725,7 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
if (minPosY <= cursorCoordinate) {
val scrollY = (parentBottom - minPosY) - (parentBottom - cursorCoordinate)
binding.recycler.addItemDecoration(footerMentionDecorator)
binding.recycler.post {
handler.post {
binding.recycler.smoothScrollBy(0, scrollY)
}
}
@ -1762,7 +1762,7 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
if (minPosY <= cursorCoordinate) {
val scrollY = (parentBottom - minPosY) - (parentBottom - cursorCoordinate)
binding.recycler.addItemDecoration(slashWidgetFooter)
binding.recycler.post {
handler.post {
binding.recycler.smoothScrollBy(
0,
scrollY,

View file

@ -146,7 +146,7 @@ abstract class ObjectMenuBaseFragment :
private fun openObjectLayout() {
val fr = ObjectLayoutFragment.new(ctx)
fr.show(childFragmentManager, null)
fr.showChildFragment()
}
private fun openObjectRelations() {
@ -187,7 +187,7 @@ abstract class ObjectMenuBaseFragment :
restoreBlock = null,
title = getString(R.string.link_to)
)
fr.show(childFragmentManager, null)
fr.showChildFragment()
}
private fun openSnackbar(command: ObjectMenuViewModelBase.Command.OpenSnackbar) {

View file

@ -162,7 +162,7 @@ class RelationAddToObjectFragment : RelationAddBaseFragment() {
ctx = ctx,
query = createFromScratchAdapter.query
)
.show(childFragmentManager, null)
.showChildFragment()
}
override fun injectDependencies() {
@ -206,7 +206,7 @@ class RelationAddToDataViewFragment : RelationAddBaseFragment() {
dv = dv,
query = createFromScratchAdapter.query
)
.show(childFragmentManager, null)
.showChildFragment()
}
override fun injectDependencies() {

View file

@ -97,7 +97,7 @@ open class RelationDateValueFragment : BaseBottomSheetFragment<FragmentRelationD
}
is DateValueCommand.OpenDatePicker -> {
DatePickerFragment.new(command.timeInSeconds)
.show(childFragmentManager, null)
.showChildFragment()
}
}
}

View file

@ -91,7 +91,7 @@ open class RelationListFragment : BaseBottomSheetFragment<FragmentRelationListBi
}
binding.btnPlus.setOnClickListener {
if (!isLocked) {
RelationAddToObjectFragment.new(ctx).show(childFragmentManager, null)
RelationAddToObjectFragment.new(ctx).showChildFragment()
} else {
toast(getString(R.string.unlock_your_object_to_add_new_relation))
}
@ -109,7 +109,7 @@ open class RelationListFragment : BaseBottomSheetFragment<FragmentRelationListBi
objectId = command.target,
isLocked = command.isLocked
)
fr.show(childFragmentManager, null)
fr.showChildFragment()
}
is Command.EditDateRelationValue -> {
val fr = RelationDateValueFragment.new(
@ -118,7 +118,7 @@ open class RelationListFragment : BaseBottomSheetFragment<FragmentRelationListBi
relationKey = command.relationKey,
objectId = command.target
)
fr.show(childFragmentManager, null)
fr.showChildFragment()
}
is Command.EditRelationValue -> {
val fr = RelationValueFragment.new(
@ -129,7 +129,7 @@ open class RelationListFragment : BaseBottomSheetFragment<FragmentRelationListBi
targetObjectTypes = command.targetObjectTypes,
isLocked = command.isLocked
)
fr.show(childFragmentManager, null)
fr.showChildFragment()
}
is Command.SetRelationKey -> {
withParent<OnFragmentInteractionListener> {

View file

@ -504,7 +504,7 @@ open class RelationValueDVFragment : RelationValueBaseFragment() {
types = types,
flow = fragmentFlow
)
fr.show(childFragmentManager, null)
fr.showChildFragment()
}
RelationValueBaseViewModel.ObjectRelationValueCommand.ShowAddStatusOrTagScreen -> {
val fr = AddOptionsRelationDVFragment.new(
@ -515,7 +515,7 @@ open class RelationValueDVFragment : RelationValueBaseFragment() {
dataview = dataview,
viewer = viewer
)
fr.show(childFragmentManager, null)
fr.showChildFragment()
}
RelationValueBaseViewModel.ObjectRelationValueCommand.ShowAddFileScreen -> {
val fr = AddFileRelationFragment.new(
@ -525,11 +525,11 @@ open class RelationValueDVFragment : RelationValueBaseFragment() {
flow = AddFileRelationFragment.FLOW_DATAVIEW,
relationKey = relationKey
)
fr.show(childFragmentManager, null)
fr.showChildFragment()
}
RelationValueBaseViewModel.ObjectRelationValueCommand.ShowFileValueActionScreen -> {
//turn off for now https://app.clickup.com/t/h59z1j
//FileActionsFragment().show(childFragmentManager, null)
//FileActionsFragment().showChildFragment()
openFilePicker()
}
}
@ -629,7 +629,7 @@ class RelationValueFragment : RelationValueBaseFragment() {
objectId = target,
types = types
)
fr.show(childFragmentManager, null)
fr.showChildFragment()
}
RelationValueBaseViewModel.ObjectRelationValueCommand.ShowAddStatusOrTagScreen -> {
val fr = AddOptionsRelationFragment.new(
@ -638,7 +638,7 @@ class RelationValueFragment : RelationValueBaseFragment() {
relationId = relationId,
relationKey = relationKey
)
fr.show(childFragmentManager, null)
fr.showChildFragment()
}
RelationValueBaseViewModel.ObjectRelationValueCommand.ShowAddFileScreen -> {
val fr = AddFileRelationFragment.new(
@ -648,11 +648,11 @@ class RelationValueFragment : RelationValueBaseFragment() {
objectId = target,
flow = AddFileRelationFragment.FLOW_DEFAULT
)
fr.show(childFragmentManager, null)
fr.showChildFragment()
}
RelationValueBaseViewModel.ObjectRelationValueCommand.ShowFileValueActionScreen -> {
//turn off for now https://app.clickup.com/t/h59z1j
//FileActionsFragment().show(childFragmentManager, null)
//FileActionsFragment().showChildFragment()
openFilePicker()
}
}

View file

@ -123,7 +123,7 @@ open class ViewerFilterFragment : BaseBottomSheetFragment<FragmentFilterBinding>
relation = command.relation,
index = command.filterIndex
)
fr.show(childFragmentManager, fr.javaClass.canonicalName)
fr.showChildFragment(fr.javaClass.canonicalName)
}
is ViewerFilterCommand.Modal.UpdateSelectValueFilter -> {
val fr = ModifyFilterFromSelectedValueFragment.new(
@ -131,7 +131,7 @@ open class ViewerFilterFragment : BaseBottomSheetFragment<FragmentFilterBinding>
relation = command.relation,
index = command.filterIndex
)
fr.show(childFragmentManager, fr.javaClass.canonicalName)
fr.showChildFragment(fr.javaClass.canonicalName)
}
}
}

View file

@ -78,14 +78,14 @@ class ViewerSortByFragment : BaseBottomSheetFragment<FragmentSortingBinding>() {
selected = command.old,
relations = command.relations,
sorts = command.sortingExpression
).show(childFragmentManager, null)
).showChildFragment()
}
is ViewerSortByCommand.Modal.ShowSortingTypeList -> {
PickSortingTypeFragment.new(
key = command.key,
type = command.selected
)
.show(childFragmentManager, null)
.showChildFragment()
}
is ViewerSortByCommand.Apply -> dispatchResultAndDismiss(command)
is ViewerSortByCommand.BackToCustomize -> exitToCustomizeScreen()

View file

@ -137,7 +137,7 @@ class ObjectSetSettingsFragment : BaseBottomSheetFragment<FragmentViewerRelation
ctx = ctx,
dv = dv,
viewer = viewer
).show(childFragmentManager, null)
).showChildFragment()
}
}
}

View file

@ -58,7 +58,7 @@ class CreateFilterFromInputFieldValueFragment :
mode = PickFilterConditionFragment.MODE_CREATE,
type = commands.type,
index = commands.index
).show(childFragmentManager, null)
).showChildFragment()
}
FilterViewModel.Commands.HideInput -> {
binding.enterTextValueInputField.gone()

View file

@ -145,7 +145,7 @@ open class CreateFilterFromSelectedValueFragment :
when (commands) {
is FilterViewModel.Commands.OpenDatePicker -> {
DatePickerFragment.new(commands.timeInSeconds)
.show(childFragmentManager, null)
.showChildFragment()
}
is FilterViewModel.Commands.OpenConditionPicker -> {
PickFilterConditionFragment.new(
@ -153,7 +153,7 @@ open class CreateFilterFromSelectedValueFragment :
mode = PickFilterConditionFragment.MODE_CREATE,
type = commands.type,
index = commands.index
).show(childFragmentManager, null)
).showChildFragment()
}
FilterViewModel.Commands.ShowCount -> binding.tvOptionCount.visible()
FilterViewModel.Commands.HideCount -> binding.tvOptionCount.gone()

View file

@ -81,7 +81,7 @@ open class ModifyFilterFromInputFieldValueFragment :
mode = PickFilterConditionFragment.MODE_MODIFY,
type = commands.type,
index = commands.index
).show(childFragmentManager, null)
).showChildFragment()
}
FilterViewModel.Commands.HideInput -> {
binding.enterTextValueInputField.gone()

View file

@ -123,7 +123,7 @@ open class ModifyFilterFromSelectedValueFragment :
when (commands) {
is FilterViewModel.Commands.OpenDatePicker -> {
DatePickerFragment.new(commands.timeInSeconds)
.show(childFragmentManager, null)
.showChildFragment()
}
is FilterViewModel.Commands.OpenConditionPicker -> {
PickFilterConditionFragment.new(
@ -132,7 +132,7 @@ open class ModifyFilterFromSelectedValueFragment :
type = commands.type,
index = commands.index
)
.show(childFragmentManager, null)
.showChildFragment()
}
FilterViewModel.Commands.ShowCount -> binding.tvOptionCount.visible()
FilterViewModel.Commands.HideCount -> binding.tvOptionCount.gone()

View file

@ -79,7 +79,7 @@ class AccountAndDataFragment : BaseBottomSheetComposeFragment() {
vm.onClearCacheButtonClicked()
val dialog = ClearCacheAlertFragment.new()
dialog.onClearAccepted = { vm.onClearFileCacheAccepted() }
dialog.show(childFragmentManager, null)
dialog.showChildFragment()
}
private fun proceedWithAccountDeletion() {
@ -88,7 +88,7 @@ class AccountAndDataFragment : BaseBottomSheetComposeFragment() {
dialog.dismiss()
vm.onDeleteAccountClicked()
}
dialog.show(childFragmentManager, null)
dialog.showChildFragment()
}
override fun injectDependencies() {

View file

@ -5,6 +5,7 @@ import androidx.fragment.app.Fragment
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@ -41,4 +42,4 @@ fun <T : Parcelable> Fragment.argList(key: String): ArrayList<T> {
}
fun <T> CoroutineScope.subscribe(flow: Flow<T>, body: suspend (T) -> Unit): Job =
flow.onEach { body(it) }.launchIn(this)
flow.cancellable().onEach { body(it) }.launchIn(this)

View file

@ -3,6 +3,7 @@ package com.anytypeio.anytype.core_utils.ui
import android.os.Bundle
import android.view.View
import androidx.annotation.IdRes
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
@ -13,6 +14,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
@ -54,6 +56,17 @@ abstract class BaseBottomSheetComposeFragment : BottomSheetDialogFragment() {
}
}
protected fun DialogFragment.showChildFragment(tag: String? = null) {
jobs += this@BaseBottomSheetComposeFragment.lifecycleScope.launch {
throttleFlow.emit {
show(
this@BaseBottomSheetComposeFragment.childFragmentManager,
tag
)
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
injectDependencies()
@ -76,5 +89,5 @@ abstract class BaseBottomSheetComposeFragment : BottomSheetDialogFragment() {
fun Fragment.getNavigationId() = findNavController().currentDestination?.id
fun <T> BaseBottomSheetComposeFragment.proceed(flow: Flow<T>, body: suspend (T) -> Unit) {
jobs += flow.onEach { body(it) }.launchIn(lifecycleScope)
jobs += flow.cancellable().onEach { body(it) }.launchIn(lifecycleScope)
}

View file

@ -16,6 +16,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
@ -109,5 +110,5 @@ abstract class BaseBottomSheetFragment<T : ViewBinding>(
}
fun <T> BaseBottomSheetFragment<*>.proceed(flow: Flow<T>, body: suspend (T) -> Unit) {
jobs += flow.onEach { body(it) }.launchIn(lifecycleScope)
jobs += flow.cancellable().onEach { body(it) }.launchIn(lifecycleScope)
}

View file

@ -2,6 +2,8 @@ package com.anytypeio.anytype.core_utils.ui
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -19,9 +21,12 @@ import com.anytypeio.anytype.core_utils.insets.RootViewDeferringInsetsCallback
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
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 BaseFragment<T : ViewBinding>(
@LayoutRes private val layout: Int,
@ -29,6 +34,7 @@ abstract class BaseFragment<T : ViewBinding>(
) : Fragment(layout) {
var applyWindowRootInsets: Boolean = true
protected val handler = Handler(Looper.getMainLooper())
private var _binding: T? = null
val binding: T get() = _binding!!
@ -56,6 +62,7 @@ abstract class BaseFragment<T : ViewBinding>(
override fun onStop() {
super.onStop()
handler.removeCallbacksAndMessages(null)
jobs.apply {
forEach { it.cancel() }
clear()
@ -109,5 +116,5 @@ abstract class BaseFragment<T : ViewBinding>(
}
fun <T> BaseFragment<*>.proceed(flow: Flow<T>, body: suspend (T) -> Unit) {
jobs += flow.onEach { body(it) }.launchIn(lifecycleScope)
jobs += flow.cancellable().onEach { body(it) }.launchIn(lifecycleScope)
}