Extract fragmentBase class
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package me.zobrist.tichucounter.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
||||
abstract class FragmentBase<VB : ViewBinding> : Fragment() {
|
||||
|
||||
private var _binding: VB? = null
|
||||
abstract val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> VB
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
protected val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = bindingInflater.invoke(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@@ -4,38 +4,16 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import me.zobrist.tichucounter.databinding.FragmentHistoryListBinding
|
||||
|
||||
class HistoryList : Fragment() {
|
||||
class HistoryList : FragmentBase<FragmentHistoryListBinding>() {
|
||||
|
||||
private var _binding: FragmentHistoryListBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
companion object {
|
||||
fun newInstance() = HistoryList()
|
||||
}
|
||||
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> FragmentHistoryListBinding
|
||||
get() = FragmentHistoryListBinding::inflate
|
||||
|
||||
private val viewModel: HistoryListViewModel by activityViewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentHistoryListBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
|
||||
@@ -8,39 +8,18 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import me.zobrist.tichucounter.databinding.FragmentKeyboardBinding
|
||||
|
||||
class Keyboard : Fragment() {
|
||||
class Keyboard : FragmentBase<FragmentKeyboardBinding>() {
|
||||
|
||||
private var _binding: FragmentKeyboardBinding? = null
|
||||
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> FragmentKeyboardBinding
|
||||
get() = FragmentKeyboardBinding::inflate
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
private var unhandledNegation: Boolean = false
|
||||
|
||||
companion object {
|
||||
fun newInstance() = Keyboard()
|
||||
}
|
||||
|
||||
private val viewModel: KeyboardViewModel by activityViewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = FragmentKeyboardBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
|
||||
@@ -4,38 +4,16 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import me.zobrist.tichucounter.databinding.FragmentTeamNamesBinding
|
||||
|
||||
class TeamNames : Fragment() {
|
||||
class TeamNames : FragmentBase<FragmentTeamNamesBinding>() {
|
||||
|
||||
private var _binding: FragmentTeamNamesBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
companion object {
|
||||
fun newInstance() = TeamNames()
|
||||
}
|
||||
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> FragmentTeamNamesBinding
|
||||
get() = FragmentTeamNamesBinding::inflate
|
||||
|
||||
private val viewModel: TeamNamesViewModel by activityViewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = FragmentTeamNamesBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
|
||||
@@ -4,38 +4,16 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import me.zobrist.tichucounter.databinding.FragmentTeamScoresBinding
|
||||
|
||||
class TeamScores : Fragment() {
|
||||
class TeamScores : FragmentBase<FragmentTeamScoresBinding>() {
|
||||
|
||||
private var _binding: FragmentTeamScoresBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
companion object {
|
||||
fun newInstance() = TeamScores()
|
||||
}
|
||||
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> FragmentTeamScoresBinding
|
||||
get() = FragmentTeamScoresBinding::inflate
|
||||
|
||||
private val viewModel: TeamScoresViewModel by activityViewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = FragmentTeamScoresBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user