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

View File

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