mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-28 09:38:14 +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
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication::class)
|
@AutoInjector(NextcloudTalkApplication::class)
|
||||||
class PollCreateDialogFragment(
|
class PollCreateDialogFragment() : DialogFragment(), PollCreateOptionsItemListener {
|
||||||
private val roomToken: String
|
|
||||||
) : DialogFragment(), PollCreateOptionsItemListener {
|
lateinit var roomToken: String
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||||
|
@ -42,6 +42,8 @@ class PollCreateDialogFragment(
|
||||||
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
||||||
|
|
||||||
viewModel = ViewModelProvider(this, viewModelFactory)[PollCreateViewModel::class.java]
|
viewModel = ViewModelProvider(this, viewModelFactory)[PollCreateViewModel::class.java]
|
||||||
|
|
||||||
|
roomToken = arguments?.getString(KEY_ROOM_TOKEN)!!
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
|
@ -150,10 +152,15 @@ class PollCreateDialogFragment(
|
||||||
*/
|
*/
|
||||||
companion object {
|
companion object {
|
||||||
private val TAG = PollCreateDialogFragment::class.java.simpleName
|
private val TAG = PollCreateDialogFragment::class.java.simpleName
|
||||||
|
private const val KEY_ROOM_TOKEN = "keyRoomToken"
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun newInstance(
|
fun newInstance(roomTokenParam: String): PollCreateDialogFragment {
|
||||||
roomTokenParam: String
|
val args = Bundle()
|
||||||
): PollCreateDialogFragment = PollCreateDialogFragment(roomTokenParam)
|
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
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication::class)
|
@AutoInjector(NextcloudTalkApplication::class)
|
||||||
class PollMainDialogFragment(
|
class PollMainDialogFragment() : DialogFragment() {
|
||||||
private val user: UserEntity,
|
|
||||||
private val pollId: String,
|
lateinit var user: UserEntity
|
||||||
private val roomToken: String,
|
lateinit var roomToken: String
|
||||||
private val pollTitle: String
|
lateinit var pollId: String
|
||||||
) : DialogFragment() {
|
lateinit var pollTitle: String
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||||
|
@ -37,6 +37,11 @@ class PollMainDialogFragment(
|
||||||
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
||||||
|
|
||||||
viewModel = ViewModelProvider(this, viewModelFactory)[PollMainViewModel::class.java]
|
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")
|
@SuppressLint("InflateParams")
|
||||||
|
@ -79,11 +84,13 @@ class PollMainDialogFragment(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showVoteScreen() {
|
private fun showVoteScreen() {
|
||||||
val contentFragment = PollVoteFragment(
|
|
||||||
|
val contentFragment = PollVoteFragment.newInstance(
|
||||||
viewModel,
|
viewModel,
|
||||||
roomToken,
|
roomToken,
|
||||||
pollId
|
pollId
|
||||||
)
|
)
|
||||||
|
|
||||||
val transaction = childFragmentManager.beginTransaction()
|
val transaction = childFragmentManager.beginTransaction()
|
||||||
transaction.replace(binding.messagePollContentFragment.id, contentFragment)
|
transaction.replace(binding.messagePollContentFragment.id, contentFragment)
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
|
@ -113,12 +120,26 @@ class PollMainDialogFragment(
|
||||||
* Fragment creator
|
* Fragment creator
|
||||||
*/
|
*/
|
||||||
companion object {
|
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
|
@JvmStatic
|
||||||
fun newInstance(
|
fun newInstance(
|
||||||
user: UserEntity,
|
user: UserEntity,
|
||||||
roomTokenParam: String,
|
roomTokenParam: String,
|
||||||
pollId: String,
|
pollId: String,
|
||||||
name: 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