1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-25 20:42:34 +01:00

Use view binding in FeedGroupReorderDialog.

This commit is contained in:
Isira Seneviratne 2020-11-03 14:17:24 +05:30
parent 5994cd8ea2
commit f04b5fd42f

View File

@ -16,10 +16,9 @@ import com.xwray.groupie.TouchCallback
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
import icepick.Icepick
import icepick.State
import kotlinx.android.synthetic.main.dialog_feed_group_reorder.confirm_button
import kotlinx.android.synthetic.main.dialog_feed_group_reorder.feed_groups_list
import org.schabi.newpipe.R
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
import org.schabi.newpipe.databinding.DialogFeedGroupReorderBinding
import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialogViewModel.DialogEvent.ProcessingEvent
import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialogViewModel.DialogEvent.SuccessEvent
import org.schabi.newpipe.local.subscription.item.FeedGroupReorderItem
@ -27,6 +26,9 @@ import org.schabi.newpipe.util.ThemeHelper
import java.util.Collections
class FeedGroupReorderDialog : DialogFragment() {
private var _binding: DialogFeedGroupReorderBinding? = null
private val binding get() = _binding!!
private lateinit var viewModel: FeedGroupReorderDialogViewModel
@State
@ -48,6 +50,7 @@ class FeedGroupReorderDialog : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
_binding = DialogFeedGroupReorderBinding.bind(view)
viewModel = ViewModelProvider(this).get(FeedGroupReorderDialogViewModel::class.java)
viewModel.groupsLiveData.observe(viewLifecycleOwner, Observer(::handleGroups))
@ -61,15 +64,20 @@ class FeedGroupReorderDialog : DialogFragment() {
}
)
feed_groups_list.layoutManager = LinearLayoutManager(requireContext())
feed_groups_list.adapter = groupAdapter
itemTouchHelper.attachToRecyclerView(feed_groups_list)
binding.feedGroupsList.layoutManager = LinearLayoutManager(requireContext())
binding.feedGroupsList.adapter = groupAdapter
itemTouchHelper.attachToRecyclerView(binding.feedGroupsList)
confirm_button.setOnClickListener {
binding.confirmButton.setOnClickListener {
viewModel.updateOrder(groupOrderedIdList)
}
}
override fun onDestroyView() {
_binding = null
super.onDestroyView()
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
Icepick.saveInstanceState(this, outState)
@ -89,7 +97,7 @@ class FeedGroupReorderDialog : DialogFragment() {
}
private fun disableInput() {
confirm_button?.isEnabled = false
_binding?.confirmButton?.isEnabled = false
isCancelable = false
}