fix to always show polls dialog.

Sometimes the polls dialog seemed to not load the content.
This was caused by the showLoadingScreen logic using binding.root.post which overwrote the content depending on if the showResultsScreen or showVoteScreen already set the content. So it was a race conditions that sometimes it worked and sometimes not.
Additionally, calculating the height failed in showLoadingScreen, so in the end there was only the headline visible and even not loading spinner. This is now replaced by a fixed height.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-04-05 15:01:21 +02:00
parent cbc1eed336
commit eaa0743027
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 12 additions and 25 deletions

View File

@ -10,7 +10,6 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import autodagger.AutoInjector import autodagger.AutoInjector
import com.nextcloud.android.common.ui.theme.utils.ColorRole import com.nextcloud.android.common.ui.theme.utils.ColorRole
@ -27,34 +26,24 @@ class PollLoadingFragment : Fragment() {
@Inject @Inject
lateinit var viewThemeUtils: ViewThemeUtils lateinit var viewThemeUtils: ViewThemeUtils
var fragmentHeight = 0
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
fragmentHeight = arguments?.getInt(KEY_FRAGMENT_HEIGHT)!!
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = DialogPollLoadingBinding.inflate(inflater, container, false) binding = DialogPollLoadingBinding.inflate(inflater, container, false)
binding.root.layoutParams.height = fragmentHeight binding.root.layoutParams.height = HEIGHT
viewThemeUtils.platform.colorCircularProgressBar(binding.pollLoadingProgressbar, ColorRole.PRIMARY) viewThemeUtils.platform.colorCircularProgressBar(binding.pollLoadingProgressbar, ColorRole.PRIMARY)
return binding.root return binding.root
} }
companion object { companion object {
private val TAG = PollLoadingFragment::class.java.simpleName private const val HEIGHT = 300
private const val KEY_FRAGMENT_HEIGHT = "keyFragmentHeight"
@JvmStatic @JvmStatic
fun newInstance(fragmentHeight: Int): PollLoadingFragment { fun newInstance(): PollLoadingFragment {
val args = bundleOf( return PollLoadingFragment()
KEY_FRAGMENT_HEIGHT to fragmentHeight
)
val fragment = PollLoadingFragment()
fragment.arguments = args
return fragment
} }
} }
} }

View File

@ -90,32 +90,30 @@ class PollMainDialogFragment : DialogFragment() {
initVotersAmount(state.showVotersAmount, state.poll.numVoters, false) initVotersAmount(state.showVotersAmount, state.poll.numVoters, false)
showVoteScreen() showVoteScreen()
} }
is PollMainViewModel.PollResultState -> { is PollMainViewModel.PollResultState -> {
initVotersAmount(state.showVotersAmount, state.poll.numVoters, true) initVotersAmount(state.showVotersAmount, state.poll.numVoters, true)
showResultsScreen() showResultsScreen()
} }
is PollMainViewModel.LoadingState -> { is PollMainViewModel.LoadingState -> {
showLoadingScreen() showLoadingScreen()
} }
is PollMainViewModel.DismissDialogState -> { is PollMainViewModel.DismissDialogState -> {
dismiss() dismiss()
} }
else -> {} else -> {}
} }
} }
} }
private fun showLoadingScreen() { private fun showLoadingScreen() {
binding.root.post { val contentFragment = PollLoadingFragment.newInstance()
run { val transaction = childFragmentManager.beginTransaction()
val fragmentHeight = binding.messagePollContentFragment.measuredHeight transaction.replace(binding.messagePollContentFragment.id, contentFragment)
transaction.commit()
val contentFragment = PollLoadingFragment.newInstance(fragmentHeight)
val transaction = childFragmentManager.beginTransaction()
transaction.replace(binding.messagePollContentFragment.id, contentFragment)
transaction.commit()
}
}
} }
private fun showVoteScreen() { private fun showVoteScreen() {