refactor home-fragment to dashboard-fragment and add a tablayout
This commit is contained in:
@@ -37,7 +37,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// menu should be considered as top level destinations.
|
// menu should be considered as top level destinations.
|
||||||
appBarConfiguration = AppBarConfiguration(
|
appBarConfiguration = AppBarConfiguration(
|
||||||
setOf(
|
setOf(
|
||||||
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow
|
R.id.nav_dashboard, R.id.nav_gallery, R.id.nav_slideshow
|
||||||
), drawerLayout
|
), drawerLayout
|
||||||
)
|
)
|
||||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
package de.chrissthecoder.store.ui.home
|
package de.chrissthecoder.store.ui.dashboard
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import de.chrissthecoder.store.databinding.FragmentHomeBinding
|
import de.chrissthecoder.store.databinding.FragmentDashboardBinding
|
||||||
|
|
||||||
class HomeFragment : Fragment() {
|
class DashboardFragment : Fragment() {
|
||||||
|
|
||||||
private var _binding: FragmentHomeBinding? = null
|
private var _binding: FragmentDashboardBinding? = null
|
||||||
|
|
||||||
// This property is only valid between onCreateView and
|
// This property is only valid between onCreateView and
|
||||||
// onDestroyView.
|
// onDestroyView.
|
||||||
@@ -22,16 +21,11 @@ class HomeFragment : Fragment() {
|
|||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
val homeViewModel =
|
val dashboardViewModel = ViewModelProvider(this).get(DashboardViewModel::class.java)
|
||||||
ViewModelProvider(this).get(HomeViewModel::class.java)
|
|
||||||
|
|
||||||
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
_binding = FragmentDashboardBinding.inflate(inflater, container, false)
|
||||||
val root: View = binding.root
|
val root: View = binding.root
|
||||||
|
|
||||||
val textView: TextView = binding.textHome
|
|
||||||
homeViewModel.text.observe(viewLifecycleOwner) {
|
|
||||||
textView.text = it
|
|
||||||
}
|
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package de.chrissthecoder.store.ui.home
|
package de.chrissthecoder.store.ui.dashboard
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
|
||||||
class HomeViewModel : ViewModel() {
|
class DashboardViewModel : ViewModel() {
|
||||||
|
|
||||||
private val _text = MutableLiveData<String>().apply {
|
private val _text = MutableLiveData<String>().apply {
|
||||||
value = "This is home Fragment"
|
value = "This is home Fragment"
|
||||||
27
app/src/main/res/layout/fragment_dashboard.xml
Normal file
27
app/src/main/res/layout/fragment_dashboard.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.dashboard.DashboardFragment">
|
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0">
|
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabItem
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/tab_shoppinglist" />
|
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabItem
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/tab_understock" />
|
||||||
|
|
||||||
|
</com.google.android.material.tabs.TabLayout>
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context=".ui.home.HomeFragment">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/text_home"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginEnd="8dp"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:textSize="20sp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
<group android:checkableBehavior="single">
|
<group android:checkableBehavior="single">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_home"
|
android:id="@+id/nav_dashboard"
|
||||||
android:icon="@drawable/ic_menu_camera"
|
android:icon="@drawable/ic_menu_camera"
|
||||||
android:title="@string/menu_home" />
|
android:title="@string/menu_dashboard" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_gallery"
|
android:id="@+id/nav_gallery"
|
||||||
android:icon="@drawable/ic_menu_gallery"
|
android:icon="@drawable/ic_menu_gallery"
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/mobile_navigation"
|
android:id="@+id/mobile_navigation"
|
||||||
app:startDestination="@+id/nav_home">
|
app:startDestination="@+id/nav_dashboard">
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/nav_home"
|
android:id="@+id/nav_dashboard"
|
||||||
android:name="de.chrissthecoder.store.ui.home.HomeFragment"
|
android:name="de.chrissthecoder.store.ui.dashboard.DashboardFragment"
|
||||||
android:label="@string/menu_home"
|
android:label="@string/menu_dashboard"
|
||||||
tools:layout="@layout/fragment_home" />
|
tools:layout="@layout/fragment_dashboard" />
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/nav_gallery"
|
android:id="@+id/nav_gallery"
|
||||||
|
|||||||
@@ -7,7 +7,10 @@
|
|||||||
<string name="nav_header_desc">Navigation header</string>
|
<string name="nav_header_desc">Navigation header</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
|
|
||||||
<string name="menu_home">Home</string>
|
<string name="menu_dashboard">Dashboard</string>
|
||||||
<string name="menu_gallery">Gallery</string>
|
<string name="menu_gallery">Gallery</string>
|
||||||
<string name="menu_slideshow">Slideshow</string>
|
<string name="menu_slideshow">Slideshow</string>
|
||||||
|
|
||||||
|
<string name="tab_shoppinglist">Einkaufszettel</string>
|
||||||
|
<string name="tab_understock">Minderbestand</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user