1
Fork 0
mirror of https://github.com/Steffo99/twom.git synced 2024-11-22 08:04:26 +00:00

Remove all fragments but the "Events" one

This commit is contained in:
Steffo 2023-11-04 15:29:12 +01:00
parent 1afece5123
commit 91e7e14415
Signed by: steffo
GPG key ID: 2A24051445686895
11 changed files with 19 additions and 147 deletions

View file

@ -13,6 +13,9 @@ import androidx.drawerlayout.widget.DrawerLayout
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import eu.steffo.twom.databinding.ActivityMainBinding import eu.steffo.twom.databinding.ActivityMainBinding
/**
* The main activity of the application.
*/
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
private lateinit var appBarConfiguration: AppBarConfiguration private lateinit var appBarConfiguration: AppBarConfiguration
@ -37,7 +40,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_events
), drawerLayout ), drawerLayout
) )
setupActionBarWithNavController(navController, appBarConfiguration) setupActionBarWithNavController(navController, appBarConfiguration)

View file

@ -1,4 +1,4 @@
package eu.steffo.twom.ui.home package eu.steffo.twom.ui.events
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -9,7 +9,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import eu.steffo.twom.databinding.FragmentHomeBinding import eu.steffo.twom.databinding.FragmentHomeBinding
class HomeFragment : Fragment() { class EventsFragment : Fragment() {
private var _binding: FragmentHomeBinding? = null private var _binding: FragmentHomeBinding? = null
@ -22,14 +22,14 @@ class HomeFragment : Fragment() {
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View { ): View {
val homeViewModel = val eventsViewModel =
ViewModelProvider(this).get(HomeViewModel::class.java) ViewModelProvider(this).get(EventsViewModel::class.java)
_binding = FragmentHomeBinding.inflate(inflater, container, false) _binding = FragmentHomeBinding.inflate(inflater, container, false)
val root: View = binding.root val root: View = binding.root
val textView: TextView = binding.textHome val textView: TextView = binding.textHome
homeViewModel.text.observe(viewLifecycleOwner) { eventsViewModel.text.observe(viewLifecycleOwner) {
textView.text = it textView.text = it
} }
return root return root

View file

@ -1,10 +1,10 @@
package eu.steffo.twom.ui.home package eu.steffo.twom.ui.events
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 EventsViewModel : ViewModel() {
private val _text = MutableLiveData<String>().apply { private val _text = MutableLiveData<String>().apply {
value = "This is home Fragment" value = "This is home Fragment"

View file

@ -1,42 +0,0 @@
package eu.steffo.twom.ui.gallery
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.lifecycle.ViewModelProvider
import eu.steffo.twom.databinding.FragmentGalleryBinding
class GalleryFragment : Fragment() {
private var _binding: FragmentGalleryBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val galleryViewModel =
ViewModelProvider(this).get(GalleryViewModel::class.java)
_binding = FragmentGalleryBinding.inflate(inflater, container, false)
val root: View = binding.root
val textView: TextView = binding.textGallery
galleryViewModel.text.observe(viewLifecycleOwner) {
textView.text = it
}
return root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}

View file

@ -1,13 +0,0 @@
package eu.steffo.twom.ui.gallery
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
class GalleryViewModel : ViewModel() {
private val _text = MutableLiveData<String>().apply {
value = "This is gallery Fragment"
}
val text: LiveData<String> = _text
}

View file

@ -1,42 +0,0 @@
package eu.steffo.twom.ui.slideshow
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.lifecycle.ViewModelProvider
import eu.steffo.twom.databinding.FragmentSlideshowBinding
class SlideshowFragment : Fragment() {
private var _binding: FragmentSlideshowBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val slideshowViewModel =
ViewModelProvider(this).get(SlideshowViewModel::class.java)
_binding = FragmentSlideshowBinding.inflate(inflater, container, false)
val root: View = binding.root
val textView: TextView = binding.textSlideshow
slideshowViewModel.text.observe(viewLifecycleOwner) {
textView.text = it
}
return root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}

View file

@ -1,13 +0,0 @@
package eu.steffo.twom.ui.slideshow
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
class SlideshowViewModel : ViewModel() {
private val _text = MutableLiveData<String>().apply {
value = "This is slideshow Fragment"
}
val text: LiveData<String> = _text
}

View file

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.home.HomeFragment"> tools:context=".ui.events.EventsFragment">
<TextView <TextView
android:id="@+id/text_home" android:id="@+id/text_home"

View file

@ -5,16 +5,8 @@
<group android:checkableBehavior="single"> <group android:checkableBehavior="single">
<item <item
android:id="@+id/nav_home" android:id="@+id/nav_events"
android:icon="@drawable/ic_menu_camera"
android:title="@string/menu_home" />
<item
android:id="@+id/nav_gallery"
android:icon="@drawable/ic_menu_gallery" android:icon="@drawable/ic_menu_gallery"
android:title="@string/menu_gallery" /> android:title="@string/menu_events" />
<item
android:id="@+id/nav_slideshow"
android:icon="@drawable/ic_menu_slideshow"
android:title="@string/menu_slideshow" />
</group> </group>
</menu> </menu>

View file

@ -3,23 +3,12 @@
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_events">
<fragment <fragment
android:id="@+id/nav_home" android:id="@+id/nav_events"
android:name="eu.steffo.twom.ui.home.HomeFragment" android:name="eu.steffo.twom.ui.events.EventsFragment"
android:label="@string/menu_home" android:label="@string/menu_events"
tools:layout="@layout/fragment_home" /> tools:layout="@layout/fragment_home" />
<fragment
android:id="@+id/nav_gallery"
android:name="eu.steffo.twom.ui.gallery.GalleryFragment"
android:label="@string/menu_gallery"
tools:layout="@layout/fragment_gallery" />
<fragment
android:id="@+id/nav_slideshow"
android:name="eu.steffo.twom.ui.slideshow.SlideshowFragment"
android:label="@string/menu_slideshow"
tools:layout="@layout/fragment_slideshow" />
</navigation> </navigation>

View file

@ -7,7 +7,5 @@
<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_events">Events</string>
<string name="menu_gallery">Gallery</string>
<string name="menu_slideshow">Slideshow</string>
</resources> </resources>