Skip to content
Permalink
Browse files

Move Viewmodel initialization to onCreate

  • Loading branch information
zsmb13 committed Jan 7, 2020
1 parent 964d5f7 commit b2c294c6dccedeb22d19ddceb784e2f23250ab32
@@ -22,13 +22,16 @@ class DashboardFragment : Fragment() {

private lateinit var dashboardViewModel: DashboardViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java)

val root = inflater.inflate(R.layout.fragment_dashboard, container, false)

arguments?.getString("id").let {
@@ -24,13 +24,16 @@ class AboutFragment : Fragment() {

private lateinit var dashboardViewModel: DashboardViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java)

val root = inflater.inflate(R.layout.fragment_about, container, false)

arguments?.getString("id").let {
@@ -13,13 +13,16 @@ class EvolutionFragment : Fragment() {

private lateinit var dashboardViewModel: DashboardViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java)

val root = inflater.inflate(R.layout.fragment_evolution, container, false)


@@ -24,13 +24,16 @@ class StatsFragment : Fragment() {

private lateinit var dashboardViewModel: DashboardViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java)

val root = inflater.inflate(R.layout.fragment_stats, container, false)

arguments?.getString("id").let {
@@ -16,13 +16,16 @@ class GenerationFragment : BottomSheetDialogFragment() {

private lateinit var generationViewModel: GenerationViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
generationViewModel = ViewModelProviders.of(this).get(GenerationViewModel::class.java)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
generationViewModel = ViewModelProviders.of(this).get(GenerationViewModel::class.java)

val root = inflater.inflate(R.layout.fragment_generation, container, false)
val recyclerView = root.recyclerView
val layoutManager = GridLayoutManager(context, 2)
@@ -19,14 +19,18 @@ class HomeFragment : Fragment() {

private lateinit var homeViewModel: HomeViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
homeViewModel = ViewModelProviders.of(this).get(HomeViewModel::class.java)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {

val root = inflater.inflate(R.layout.fragment_home, container, false)
homeViewModel = ViewModelProviders.of(this).get(HomeViewModel::class.java)
activity?.window?.statusBarColor = PokemonColorUtil(root.context).covertColor(R.color.red)

val recyclerViewMenu = root.recyclerViewMenu
@@ -20,13 +20,16 @@ class PokedexFragment : Fragment() {

private lateinit var pokedexViewModel: PokedexViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
pokedexViewModel = ViewModelProviders.of(this).get(PokedexViewModel::class.java)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
pokedexViewModel = ViewModelProviders.of(this).get(PokedexViewModel::class.java)

val root = inflater.inflate(R.layout.fragment_pokedex, container, false)

activity?.window?.statusBarColor =

0 comments on commit b2c294c

Please sign in to comment.
You can’t perform that action at this time.