mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +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
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication::class)
|
@AutoInjector(NextcloudTalkApplication::class)
|
||||||
class PollCreateDialogFragment() : DialogFragment(), PollCreateOptionsItemListener {
|
class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener {
|
||||||
|
|
||||||
lateinit var roomToken: String
|
lateinit var roomToken: String
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import com.nextcloud.talk.polls.viewmodels.PollMainViewModel
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication::class)
|
@AutoInjector(NextcloudTalkApplication::class)
|
||||||
class PollMainDialogFragment() : DialogFragment() {
|
class PollMainDialogFragment : DialogFragment() {
|
||||||
|
|
||||||
lateinit var user: UserEntity
|
lateinit var user: UserEntity
|
||||||
lateinit var roomToken: String
|
lateinit var roomToken: String
|
||||||
@ -63,7 +63,6 @@ class PollMainDialogFragment() : DialogFragment() {
|
|||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
viewModel.viewState.observe(viewLifecycleOwner) { state ->
|
viewModel.viewState.observe(viewLifecycleOwner) { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
PollMainViewModel.InitialState -> {}
|
PollMainViewModel.InitialState -> {}
|
||||||
@ -84,8 +83,8 @@ class PollMainDialogFragment() : DialogFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showVoteScreen() {
|
private fun showVoteScreen() {
|
||||||
val contentFragment = PollVoteFragment(
|
|
||||||
viewModel,
|
val contentFragment = PollVoteFragment.newInstance(
|
||||||
roomToken,
|
roomToken,
|
||||||
pollId
|
pollId
|
||||||
)
|
)
|
||||||
@ -98,10 +97,10 @@ class PollMainDialogFragment() : DialogFragment() {
|
|||||||
private fun showResultsScreen(poll: Poll) {
|
private fun showResultsScreen(poll: Poll) {
|
||||||
initVotersAmount(poll.numVoters)
|
initVotersAmount(poll.numVoters)
|
||||||
|
|
||||||
val contentFragment = PollResultsFragment(
|
val contentFragment = PollResultsFragment.newInstance(
|
||||||
user,
|
user
|
||||||
viewModel
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val transaction = childFragmentManager.beginTransaction()
|
val transaction = childFragmentManager.beginTransaction()
|
||||||
transaction.replace(binding.messagePollContentFragment.id, contentFragment)
|
transaction.replace(binding.messagePollContentFragment.id, contentFragment)
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
|
@ -42,16 +42,16 @@ import com.nextcloud.talk.polls.viewmodels.PollResultsViewModel
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication::class)
|
@AutoInjector(NextcloudTalkApplication::class)
|
||||||
class PollResultsFragment(
|
class PollResultsFragment : Fragment(), PollResultItemClickListener {
|
||||||
private val user: UserEntity,
|
|
||||||
private val parentViewModel: PollMainViewModel
|
|
||||||
) : Fragment(), PollResultItemClickListener {
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||||
|
|
||||||
|
private lateinit var parentViewModel: PollMainViewModel
|
||||||
lateinit var viewModel: PollResultsViewModel
|
lateinit var viewModel: PollResultsViewModel
|
||||||
|
|
||||||
|
lateinit var user: UserEntity
|
||||||
|
|
||||||
lateinit var binding: DialogPollResultsBinding
|
lateinit var binding: DialogPollResultsBinding
|
||||||
|
|
||||||
private var adapter: PollResultsAdapter? = null
|
private var adapter: PollResultsAdapter? = null
|
||||||
@ -60,6 +60,10 @@ class PollResultsFragment(
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
||||||
viewModel = ViewModelProvider(this, viewModelFactory)[PollResultsViewModel::class.java]
|
viewModel = ViewModelProvider(this, viewModelFactory)[PollResultsViewModel::class.java]
|
||||||
|
parentViewModel = ViewModelProvider(requireParentFragment(), viewModelFactory)[PollMainViewModel::class
|
||||||
|
.java]
|
||||||
|
|
||||||
|
user = arguments?.getParcelable(KEY_USER_ENTITY)!!
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
@ -129,4 +133,19 @@ class PollResultsFragment(
|
|||||||
override fun onClick(pollResultHeaderItem: PollResultHeaderItem) {
|
override fun onClick(pollResultHeaderItem: PollResultHeaderItem) {
|
||||||
viewModel.filterItems()
|
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
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication::class)
|
@AutoInjector(NextcloudTalkApplication::class)
|
||||||
class PollVoteFragment(
|
class PollVoteFragment : Fragment() {
|
||||||
private val parentViewModel: PollMainViewModel,
|
|
||||||
private val roomToken: String,
|
lateinit var roomToken: String
|
||||||
private val pollId: String
|
|
||||||
) : Fragment() {
|
lateinit var pollId: String
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||||
|
|
||||||
|
private lateinit var parentViewModel: PollMainViewModel
|
||||||
lateinit var viewModel: PollVoteViewModel
|
lateinit var viewModel: PollVoteViewModel
|
||||||
|
|
||||||
private lateinit var binding: DialogPollVoteBinding
|
private lateinit var binding: DialogPollVoteBinding
|
||||||
@ -61,6 +62,12 @@ class PollVoteFragment(
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
||||||
viewModel = ViewModelProvider(this, viewModelFactory)[PollVoteViewModel::class.java]
|
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(
|
override fun onCreateView(
|
||||||
@ -187,5 +194,21 @@ class PollVoteFragment(
|
|||||||
companion object {
|
companion object {
|
||||||
private val TAG = PollVoteFragment::class.java.simpleName
|
private val TAG = PollVoteFragment::class.java.simpleName
|
||||||
private const val UNLIMITED_VOTES = 0
|
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