add loading screen

this also avoids to doubleclick on end poll button

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-07-22 19:04:21 +02:00 committed by Andy Scherzinger (Rebase PR Action)
parent 06d9b6f886
commit 8dfb6ca5aa
4 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,74 @@
/*
* Nextcloud Talk application
*
* @author Marcel Hibbe
* Copyright (C) 2022 Marcel Hibbe <dev@mhibbe.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.polls.ui
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.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.databinding.DialogPollLoadingBinding
@AutoInjector(NextcloudTalkApplication::class)
class PollLoadingFragment : Fragment() {
private lateinit var binding: DialogPollLoadingBinding
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
return binding.root
}
companion object {
private val TAG = PollLoadingFragment::class.java.simpleName
private const val KEY_FRAGMENT_HEIGHT = "keyFragmentHeight"
@JvmStatic
fun newInstance(
fragmentHeight: Int
): PollLoadingFragment {
val args = bundleOf(
KEY_FRAGMENT_HEIGHT to fragmentHeight,
)
val fragment = PollLoadingFragment()
fragment.arguments = args
return fragment
}
}
}

View File

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

View File

@ -50,6 +50,8 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
sealed interface ViewState
object InitialState : ViewState
object DismissDialogState : ViewState
object LoadingState : ViewState
open class PollVoteState(
val poll: Poll,
val showVotersAmount: Boolean,
@ -94,6 +96,7 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
}
private fun loadPoll() {
_viewState.value = LoadingState
repository.getPoll(roomToken, pollId)
.doOnSubscribe { disposable = it }
?.subscribeOn(Schedulers.io())
@ -102,6 +105,7 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito
}
fun endPoll() {
_viewState.value = LoadingState
repository.closePoll(roomToken, pollId)
.doOnSubscribe { disposable = it }
?.subscribeOn(Schedulers.io())

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Nextcloud Talk application
~
~ @author Marcel Hibbe
~ Copyright (C) 2022 Marcel Hibbe <dev@mhibbe.de>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:background="@color/white">
<ProgressBar
android:layout_width="25dp"
android:layout_height="25dp">
</ProgressBar>
</LinearLayout>