diff --git a/app/src/main/java/com/nextcloud/talk/polls/ui/PollMainDialogFragment.kt b/app/src/main/java/com/nextcloud/talk/polls/ui/PollMainDialogFragment.kt index d1b523ddd..e94cc4403 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/ui/PollMainDialogFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/ui/PollMainDialogFragment.kt @@ -106,10 +106,7 @@ class PollMainDialogFragment : DialogFragment() { } private fun showVoteScreen() { - val contentFragment = PollVoteFragment.newInstance( - viewModel.roomToken, - viewModel.pollId - ) + val contentFragment = PollVoteFragment.newInstance() val transaction = childFragmentManager.beginTransaction() transaction.replace(binding.messagePollContentFragment.id, contentFragment) @@ -117,9 +114,7 @@ class PollMainDialogFragment : DialogFragment() { } private fun showResultsScreen() { - val contentFragment = PollResultsFragment.newInstance( - viewModel.user - ) + val contentFragment = PollResultsFragment.newInstance() val transaction = childFragmentManager.beginTransaction() transaction.replace(binding.messagePollContentFragment.id, contentFragment) diff --git a/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt b/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt index 468f26d86..2c48644bd 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt @@ -33,7 +33,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import autodagger.AutoInjector import com.nextcloud.talk.R import com.nextcloud.talk.application.NextcloudTalkApplication -import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.DialogPollResultsBinding import com.nextcloud.talk.polls.adapters.PollResultHeaderItem import com.nextcloud.talk.polls.adapters.PollResultItemClickListener @@ -51,8 +50,6 @@ class PollResultsFragment : Fragment(), PollResultItemClickListener { private lateinit var parentViewModel: PollMainViewModel lateinit var viewModel: PollResultsViewModel - lateinit var user: User - lateinit var binding: DialogPollResultsBinding private var adapter: PollResultsAdapter? = null @@ -61,12 +58,7 @@ class PollResultsFragment : Fragment(), PollResultItemClickListener { super.onCreate(savedInstanceState) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) viewModel = ViewModelProvider(this, viewModelFactory)[PollResultsViewModel::class.java] - parentViewModel = ViewModelProvider(requireParentFragment(), viewModelFactory)[ - PollMainViewModel::class - .java - ] - - user = arguments?.getParcelable(KEY_USER_ENTITY)!! + parentViewModel = ViewModelProvider(requireParentFragment(), viewModelFactory)[PollMainViewModel::class.java] } override fun onCreateView( @@ -91,7 +83,7 @@ class PollResultsFragment : Fragment(), PollResultItemClickListener { } viewModel.items.observe(viewLifecycleOwner) { - val adapter = PollResultsAdapter(user, this).apply { + val adapter = PollResultsAdapter(parentViewModel.user, this).apply { if (it != null) { list = it } @@ -101,7 +93,7 @@ class PollResultsFragment : Fragment(), PollResultItemClickListener { } private fun initAdapter() { - adapter = PollResultsAdapter(user, this) + adapter = PollResultsAdapter(parentViewModel.user, this) binding.pollResultsList.adapter = adapter binding.pollResultsList.layoutManager = LinearLayoutManager(context) } @@ -140,17 +132,9 @@ class PollResultsFragment : Fragment(), PollResultItemClickListener { } companion object { - private const val KEY_USER_ENTITY = "keyUserEntity" - @JvmStatic - fun newInstance( - user: User - ): PollResultsFragment { - val args = Bundle() - args.putParcelable(KEY_USER_ENTITY, user) - val fragment = PollResultsFragment() - fragment.arguments = args - return fragment + fun newInstance(): PollResultsFragment { + return PollResultsFragment() } } } diff --git a/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt b/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt index 2da51b177..32688f97c 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt @@ -47,10 +47,6 @@ import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) class PollVoteFragment : Fragment() { - lateinit var roomToken: String - - lateinit var pollId: String - @Inject lateinit var viewModelFactory: ViewModelProvider.Factory @@ -64,13 +60,7 @@ class PollVoteFragment : Fragment() { NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) viewModel = ViewModelProvider(this, viewModelFactory)[PollVoteViewModel::class.java] - parentViewModel = ViewModelProvider(requireParentFragment(), viewModelFactory)[ - PollMainViewModel::class - .java - ] - - roomToken = arguments?.getString(KEY_ROOM_TOKEN)!! - pollId = arguments?.getString(KEY_POLL_ID)!! + parentViewModel = ViewModelProvider(requireParentFragment(), viewModelFactory)[PollMainViewModel::class.java] } override fun onCreateView( @@ -120,7 +110,7 @@ class PollVoteFragment : Fragment() { } binding.pollVoteSubmitButton.setOnClickListener { - viewModel.vote(roomToken, pollId) + viewModel.vote(parentViewModel.roomToken, parentViewModel.pollId) } binding.pollVoteEditDismiss.setOnClickListener { @@ -209,20 +199,9 @@ class PollVoteFragment : Fragment() { private val TAG = PollVoteFragment::class.java.simpleName private const val UNLIMITED_VOTES = 0 - private const val KEY_ROOM_TOKEN = "keyRoomToken" - private const val KEY_POLL_ID = "keyPollId" - @JvmStatic - fun newInstance( - roomTokenParam: String, - pollId: String - ): PollVoteFragment { - val args = Bundle() - args.putString(KEY_ROOM_TOKEN, roomTokenParam) - args.putString(KEY_POLL_ID, pollId) - val fragment = PollVoteFragment() - fragment.arguments = args - return fragment + fun newInstance(): PollVoteFragment { + return PollVoteFragment() } } } diff --git a/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollMainViewModel.kt b/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollMainViewModel.kt index f9480d6d5..e7d89fc6c 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollMainViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/viewmodels/PollMainViewModel.kt @@ -34,17 +34,6 @@ import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers import javax.inject.Inject -/** - * @startuml - * hide empty description - * [*] --> InitialState - * InitialState --> PollOpenState - * note left - * Open second viewmodel for child fragment - * end note - * InitialState --> PollClosedState - * @enduml - */ class PollMainViewModel @Inject constructor(private val repository: PollRepository) : ViewModel() { @Inject @@ -190,10 +179,6 @@ class PollMainViewModel @Inject constructor(private val repository: PollReposito return userUtils.currentUser?.userId == poll.actorId } - fun setIsOwnerOrModerator(ownerOrModerator: Boolean) { - isOwnerOrModerator = ownerOrModerator - } - companion object { private val TAG = PollMainViewModel::class.java.simpleName }