Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add property to ViewModel to show some problems in the start template
- Loading branch information
1 parent
14aa1b9
commit fa3a80b
Showing
5 changed files
with
58 additions
and
18 deletions.
There are no files selected for viewing
33 changes: 16 additions & 17 deletions
33
app/src/main/java/com/aaglobal/jnc_playground/ui/dashboard/DashboardFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
package com.aaglobal.jnc_playground.ui.dashboard | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.Observer | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.aaglobal.jnc_playground.R | ||
import kotlinx.android.synthetic.main.fragment_dashboard.* | ||
|
||
class DashboardFragment : Fragment() { | ||
class DashboardFragment : Fragment(R.layout.fragment_dashboard) { | ||
|
||
private lateinit var dashboardViewModel: DashboardViewModel | ||
private val dashboardViewModel: DashboardViewModel by viewModels() | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
dashboardViewModel = | ||
ViewModelProvider(this).get(DashboardViewModel::class.java) | ||
val root = inflater.inflate(R.layout.fragment_dashboard, container, false) | ||
val textView: TextView = root.findViewById(R.id.text_dashboard) | ||
dashboardViewModel.text.observe(viewLifecycleOwner, Observer { | ||
textView.text = it | ||
fragment_dashboard__text__title.text = it | ||
}) | ||
|
||
// ========= Problem 1 ========= | ||
// When we move to another bottom navigation tab, our counter will be reset! | ||
dashboardViewModel.counter.observe(viewLifecycleOwner, Observer { | ||
fragment_dashboard__text__counter.text = "$it" | ||
}) | ||
return root | ||
fragment_dashboard__text__counter.setOnClickListener { dashboardViewModel.incCounter() } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<style name="LargeTitle"> | ||
<item name="android:textSize">34sp</item> | ||
<item name="android:fontFamily">sans-serif</item> | ||
<item name="android:textStyle">bold</item> | ||
<item name="android:textColor">@color/black</item> | ||
<item name="android:includeFontPadding">false</item> | ||
<item name="lineHeight">40sp</item> | ||
<item name="firstBaselineToTopHeight">32sp</item> | ||
<item name="lastBaselineToBottomHeight">8sp</item> | ||
</style> | ||
|
||
</resources> |