mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 03:59:35 +01:00
fix InstantiationException for more fragments
followup to a12692ec + get parentViewModel by ViewModelProvider Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
38256fc25d
commit
23bf072326
@ -25,7 +25,7 @@ import com.nextcloud.talk.polls.viewmodels.PollCreateViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
class PollCreateDialogFragment() : DialogFragment(), PollCreateOptionsItemListener {
|
||||
class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener {
|
||||
|
||||
lateinit var roomToken: String
|
||||
|
||||
|
@ -19,7 +19,7 @@ import com.nextcloud.talk.polls.viewmodels.PollMainViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
class PollMainDialogFragment() : DialogFragment() {
|
||||
class PollMainDialogFragment : DialogFragment() {
|
||||
|
||||
lateinit var user: UserEntity
|
||||
lateinit var roomToken: String
|
||||
@ -63,7 +63,6 @@ class PollMainDialogFragment() : DialogFragment() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel.viewState.observe(viewLifecycleOwner) { state ->
|
||||
when (state) {
|
||||
PollMainViewModel.InitialState -> {}
|
||||
@ -84,8 +83,8 @@ class PollMainDialogFragment() : DialogFragment() {
|
||||
}
|
||||
|
||||
private fun showVoteScreen() {
|
||||
val contentFragment = PollVoteFragment(
|
||||
viewModel,
|
||||
|
||||
val contentFragment = PollVoteFragment.newInstance(
|
||||
roomToken,
|
||||
pollId
|
||||
)
|
||||
@ -98,10 +97,10 @@ class PollMainDialogFragment() : DialogFragment() {
|
||||
private fun showResultsScreen(poll: Poll) {
|
||||
initVotersAmount(poll.numVoters)
|
||||
|
||||
val contentFragment = PollResultsFragment(
|
||||
user,
|
||||
viewModel
|
||||
val contentFragment = PollResultsFragment.newInstance(
|
||||
user
|
||||
)
|
||||
|
||||
val transaction = childFragmentManager.beginTransaction()
|
||||
transaction.replace(binding.messagePollContentFragment.id, contentFragment)
|
||||
transaction.commit()
|
||||
|
@ -42,16 +42,16 @@ import com.nextcloud.talk.polls.viewmodels.PollResultsViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
class PollResultsFragment(
|
||||
private val user: UserEntity,
|
||||
private val parentViewModel: PollMainViewModel
|
||||
) : Fragment(), PollResultItemClickListener {
|
||||
class PollResultsFragment : Fragment(), PollResultItemClickListener {
|
||||
|
||||
@Inject
|
||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
private lateinit var parentViewModel: PollMainViewModel
|
||||
lateinit var viewModel: PollResultsViewModel
|
||||
|
||||
lateinit var user: UserEntity
|
||||
|
||||
lateinit var binding: DialogPollResultsBinding
|
||||
|
||||
private var adapter: PollResultsAdapter? = null
|
||||
@ -60,6 +60,10 @@ class PollResultsFragment(
|
||||
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)!!
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
@ -129,4 +133,19 @@ class PollResultsFragment(
|
||||
override fun onClick(pollResultHeaderItem: PollResultHeaderItem) {
|
||||
viewModel.filterItems()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KEY_USER_ENTITY = "keyUserEntity"
|
||||
|
||||
@JvmStatic
|
||||
fun newInstance(
|
||||
user: UserEntity
|
||||
): PollResultsFragment {
|
||||
val args = Bundle()
|
||||
args.putParcelable(KEY_USER_ENTITY, user)
|
||||
val fragment = PollResultsFragment()
|
||||
fragment.arguments = args
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,15 +44,16 @@ import com.nextcloud.talk.polls.viewmodels.PollVoteViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
class PollVoteFragment(
|
||||
private val parentViewModel: PollMainViewModel,
|
||||
private val roomToken: String,
|
||||
private val pollId: String
|
||||
) : Fragment() {
|
||||
class PollVoteFragment : Fragment() {
|
||||
|
||||
lateinit var roomToken: String
|
||||
|
||||
lateinit var pollId: String
|
||||
|
||||
@Inject
|
||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
private lateinit var parentViewModel: PollMainViewModel
|
||||
lateinit var viewModel: PollVoteViewModel
|
||||
|
||||
private lateinit var binding: DialogPollVoteBinding
|
||||
@ -61,6 +62,12 @@ class PollVoteFragment(
|
||||
super.onCreate(savedInstanceState)
|
||||
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)!!
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
@ -187,5 +194,21 @@ class PollVoteFragment(
|
||||
companion object {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user