mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-24 05:55:39 +03:00
fix InstantiationException for fragments
fragments must have a public, no-arg constructor. extra information must be passed as arguments. With a constructor that receives the data, the following error occurs: Fragment$InstantiationException: Unable to instantiate fragment ..... could not find Fragment constructor Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
3224ae1e1f
commit
1a000859bf
2 changed files with 42 additions and 14 deletions
|
@ -25,9 +25,9 @@ import com.nextcloud.talk.polls.viewmodels.PollCreateViewModel
|
|||
import javax.inject.Inject
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
class PollCreateDialogFragment(
|
||||
private val roomToken: String
|
||||
) : DialogFragment(), PollCreateOptionsItemListener {
|
||||
class PollCreateDialogFragment() : DialogFragment(), PollCreateOptionsItemListener {
|
||||
|
||||
lateinit var roomToken: String
|
||||
|
||||
@Inject
|
||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
@ -42,6 +42,8 @@ class PollCreateDialogFragment(
|
|||
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
||||
|
||||
viewModel = ViewModelProvider(this, viewModelFactory)[PollCreateViewModel::class.java]
|
||||
|
||||
roomToken = arguments?.getString(KEY_ROOM_TOKEN)!!
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
|
@ -150,10 +152,15 @@ class PollCreateDialogFragment(
|
|||
*/
|
||||
companion object {
|
||||
private val TAG = PollCreateDialogFragment::class.java.simpleName
|
||||
private const val KEY_ROOM_TOKEN = "keyRoomToken"
|
||||
|
||||
@JvmStatic
|
||||
fun newInstance(
|
||||
roomTokenParam: String
|
||||
): PollCreateDialogFragment = PollCreateDialogFragment(roomTokenParam)
|
||||
fun newInstance(roomTokenParam: String): PollCreateDialogFragment {
|
||||
val args = Bundle()
|
||||
args.putString(KEY_ROOM_TOKEN, roomTokenParam)
|
||||
val fragment = PollCreateDialogFragment()
|
||||
fragment.arguments = args
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ import com.nextcloud.talk.polls.viewmodels.PollMainViewModel
|
|||
import javax.inject.Inject
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
class PollMainDialogFragment(
|
||||
private val user: UserEntity,
|
||||
private val pollId: String,
|
||||
private val roomToken: String,
|
||||
private val pollTitle: String
|
||||
) : DialogFragment() {
|
||||
class PollMainDialogFragment() : DialogFragment() {
|
||||
|
||||
lateinit var user: UserEntity
|
||||
lateinit var roomToken: String
|
||||
lateinit var pollId: String
|
||||
lateinit var pollTitle: String
|
||||
|
||||
@Inject
|
||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
@ -37,6 +37,11 @@ class PollMainDialogFragment(
|
|||
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
||||
|
||||
viewModel = ViewModelProvider(this, viewModelFactory)[PollMainViewModel::class.java]
|
||||
|
||||
user = arguments?.getParcelable(KEY_USER_ENTITY)!!
|
||||
roomToken = arguments?.getString(KEY_ROOM_TOKEN)!!
|
||||
pollId = arguments?.getString(KEY_POLL_ID)!!
|
||||
pollTitle = arguments?.getString(KEY_POLL_TITLE)!!
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
|
@ -79,11 +84,13 @@ class PollMainDialogFragment(
|
|||
}
|
||||
|
||||
private fun showVoteScreen() {
|
||||
val contentFragment = PollVoteFragment(
|
||||
|
||||
val contentFragment = PollVoteFragment.newInstance(
|
||||
viewModel,
|
||||
roomToken,
|
||||
pollId
|
||||
)
|
||||
|
||||
val transaction = childFragmentManager.beginTransaction()
|
||||
transaction.replace(binding.messagePollContentFragment.id, contentFragment)
|
||||
transaction.commit()
|
||||
|
@ -113,12 +120,26 @@ class PollMainDialogFragment(
|
|||
* Fragment creator
|
||||
*/
|
||||
companion object {
|
||||
private const val KEY_USER_ENTITY = "keyUserEntity"
|
||||
private const val KEY_ROOM_TOKEN = "keyRoomToken"
|
||||
private const val KEY_POLL_ID = "keyPollId"
|
||||
private const val KEY_POLL_TITLE = "keyPollTitle"
|
||||
|
||||
@JvmStatic
|
||||
fun newInstance(
|
||||
user: UserEntity,
|
||||
roomTokenParam: String,
|
||||
pollId: String,
|
||||
name: String
|
||||
): PollMainDialogFragment = PollMainDialogFragment(user, pollId, roomTokenParam, name)
|
||||
): PollMainDialogFragment {
|
||||
val args = Bundle()
|
||||
args.putParcelable(KEY_USER_ENTITY, user)
|
||||
args.putString(KEY_ROOM_TOKEN, roomTokenParam)
|
||||
args.putString(KEY_POLL_ID, pollId)
|
||||
args.putString(KEY_POLL_TITLE, name)
|
||||
val fragment = PollMainDialogFragment()
|
||||
fragment.arguments = args
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue