Compare commits
3 Commits
9e54bbc978
...
47e1283ba2
| Author | SHA1 | Date | |
|---|---|---|---|
| 47e1283ba2 | |||
| 88325e8abe | |||
| ee8d259c51 |
@@ -46,7 +46,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
menuInflater.inflate(R.menu.main, menu)
|
menuInflater.inflate(R.menu.threedots, menu)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package de.chrissthecoder.store.adapter
|
|||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
import de.chrissthecoder.store.ui.dashboard.tabfragment.shoppinglist.ShoplistFragment
|
import de.chrissthecoder.store.ui.dashboard.tabfragment.shoppinglist.ShoppinglistShoplistFragment
|
||||||
import de.chrissthecoder.store.ui.dashboard.tabfragment.UnderstockFragment
|
import de.chrissthecoder.store.ui.dashboard.tabfragment.UnderstockFragment
|
||||||
|
|
||||||
class DashboardFragmentPagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
class DashboardFragmentPagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
||||||
@@ -12,7 +12,7 @@ class DashboardFragmentPagerAdapter(fragment: Fragment) : FragmentStateAdapter(f
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun createFragment(position: Int) : Fragment {
|
override fun createFragment(position: Int) : Fragment {
|
||||||
return if(position == 0) { ShoplistFragment() }
|
return if(position == 0) { ShoppinglistShoplistFragment() }
|
||||||
else { UnderstockFragment() }
|
else { UnderstockFragment() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,32 +8,31 @@ import android.widget.ImageView
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import de.chrissthecoder.store.R
|
import de.chrissthecoder.store.R
|
||||||
|
import de.chrissthecoder.store.databinding.FragmentShoppinglistShoplistItemBinding
|
||||||
import de.chrissthecoder.store.dataclass.ShoppinglistShoplistItem
|
import de.chrissthecoder.store.dataclass.ShoppinglistShoplistItem
|
||||||
|
import de.chrissthecoder.store.interfaces.ShoppinglistShoplistItemClickListener
|
||||||
|
|
||||||
class ShoppinglistShoplistAdapter(val shoplist: List<ShoppinglistShoplistItem>) : RecyclerView.Adapter<ShoppinglistShoplistAdapter.ItemViewHolder>() {
|
class ShoppinglistShoplistAdapter(val shoplist: List<ShoppinglistShoplistItem>, private val listener: ShoppinglistShoplistItemClickListener) : RecyclerView.Adapter<ShoppinglistShoplistAdapter.ItemViewHolder>() {
|
||||||
inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
inner class ItemViewHolder(private val binding: FragmentShoppinglistShoplistItemBinding, private val listener: ShoppinglistShoplistItemClickListener) : RecyclerView.ViewHolder(binding.root) {
|
||||||
val shoplabel: TextView
|
fun bindItem(item: ShoppinglistShoplistItem) {
|
||||||
val shopicon: ImageView
|
binding.shoplabel.text = item.shoplabel
|
||||||
val shoppinglistCount: TextView
|
binding.shoppinglistCount.text = "(" + item.shoppinglistCount + ")"
|
||||||
|
binding.cardview.setOnClickListener {
|
||||||
init {
|
listener.onClick(item)
|
||||||
Log.d(this.javaClass.name,"Get necessary Views")
|
}
|
||||||
shoplabel = view.findViewById(R.id.shoplabel)
|
|
||||||
shopicon = view.findViewById(R.id.shopicon)
|
|
||||||
shoppinglistCount = view.findViewById(R.id.shoppinglistCount)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
|
||||||
Log.d(this.javaClass.name, "Create new views (invoked by the layout manager)")
|
Log.d(this.javaClass.name, "Create new views (invoked by the layout manager)")
|
||||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.fragment_shoppinglist_shoplist_item, parent, false)
|
val from = LayoutInflater.from(parent.context)
|
||||||
return ItemViewHolder(view)
|
val binding = FragmentShoppinglistShoplistItemBinding.inflate(from, parent, false)
|
||||||
|
return ItemViewHolder(binding, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ShoppinglistShoplistAdapter.ItemViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ShoppinglistShoplistAdapter.ItemViewHolder, position: Int) {
|
||||||
Log.d(this.javaClass.name,"Replace the contents of a view (invoked by the layout manager)")
|
Log.d(this.javaClass.name,"Replace the contents of a view (invoked by the layout manager)")
|
||||||
holder.shoplabel.text = shoplist[position].shoplabel
|
holder.bindItem(shoplist[position])
|
||||||
holder.shoppinglistCount.text = "(" + shoplist[position].shoppinglistCount + ")"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package de.chrissthecoder.store.interfaces
|
||||||
|
|
||||||
|
import de.chrissthecoder.store.dataclass.ShoppinglistShoplistItem
|
||||||
|
|
||||||
|
interface ShoppinglistShoplistItemClickListener {
|
||||||
|
fun onClick(shopitem: ShoppinglistShoplistItem)
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package de.chrissthecoder.store.ui.dashboard.tabfragment.shoppinglist
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import de.chrissthecoder.store.R
|
||||||
|
|
||||||
|
class ShoppinglistListsFragment : Fragment() {
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
// Inflate the layout for this fragment
|
||||||
|
return inflater.inflate(R.layout.fragment_shoppinglist_lists, container, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,14 +5,17 @@ import androidx.fragment.app.Fragment
|
|||||||
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 androidx.navigation.fragment.findNavController
|
||||||
|
import de.chrissthecoder.store.R
|
||||||
import de.chrissthecoder.store.adapter.ShoppinglistShoplistAdapter
|
import de.chrissthecoder.store.adapter.ShoppinglistShoplistAdapter
|
||||||
import de.chrissthecoder.store.databinding.FragmentShoppinglistShoplistBinding
|
import de.chrissthecoder.store.databinding.FragmentShoppinglistShoplistBinding
|
||||||
import de.chrissthecoder.store.dataclass.ShoppinglistShoplistItem
|
import de.chrissthecoder.store.dataclass.ShoppinglistShoplistItem
|
||||||
|
import de.chrissthecoder.store.interfaces.ShoppinglistShoplistItemClickListener
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A [Fragment] subclass to list all shops that contains assigned shoppinglists.
|
* A [Fragment] subclass to list all shops that contains assigned shoppinglists.
|
||||||
*/
|
*/
|
||||||
class ShoplistFragment : Fragment() {
|
class ShoppinglistShoplistFragment : Fragment(), ShoppinglistShoplistItemClickListener {
|
||||||
|
|
||||||
private var _binding: FragmentShoppinglistShoplistBinding? = null
|
private var _binding: FragmentShoppinglistShoplistBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
@@ -23,11 +26,16 @@ class ShoplistFragment : Fragment() {
|
|||||||
_binding = FragmentShoppinglistShoplistBinding.inflate(inflater, container, false)
|
_binding = FragmentShoppinglistShoplistBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
val shoplist = ArrayList<ShoppinglistShoplistItem>()
|
val shoplist = ArrayList<ShoppinglistShoplistItem>()
|
||||||
|
shoplist.add(ShoppinglistShoplistItem("Edeka", 0, 3))
|
||||||
|
|
||||||
val shoplistRecyclerView = binding.shoplist
|
val shoplistRecyclerView = binding.shoplist
|
||||||
adapter = ShoppinglistShoplistAdapter(shoplist)
|
adapter = ShoppinglistShoplistAdapter(shoplist, this)
|
||||||
shoplistRecyclerView.adapter = adapter
|
shoplistRecyclerView.adapter = adapter
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onClick(shopitem: ShoppinglistShoplistItem) {
|
||||||
|
findNavController().navigate(R.id.action_nav_dashboard_to_shoppinglistLists)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,6 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="start"
|
android:layout_gravity="start"
|
||||||
android:fitsSystemWindows="true"
|
android:fitsSystemWindows="true"
|
||||||
app:headerLayout="@layout/nav_header_main"
|
app:headerLayout="@layout/burger_header"
|
||||||
app:menu="@menu/activity_main_drawer" />
|
app:menu="@menu/burger" />
|
||||||
</androidx.drawerlayout.widget.DrawerLayout>
|
</androidx.drawerlayout.widget.DrawerLayout>
|
||||||
@@ -16,5 +16,5 @@
|
|||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:navGraph="@navigation/mobile_navigation" />
|
app:navGraph="@navigation/app_navigation" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
9
app/src/main/res/layout/fragment_shoppinglist_lists.xml
Normal file
9
app/src/main/res/layout/fragment_shoppinglist_lists.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.dashboard.tabfragment.shoppinglist.ShoppinglistListsFragment">
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -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.dashboard.tabfragment.shoppinglist.ShoplistFragment">
|
tools:context=".ui.dashboard.tabfragment.shoppinglist.ShoppinglistShoplistFragment">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/shoplist"
|
android:id="@+id/shoplist"
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
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:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
<androidx.cardview.widget.CardView
|
||||||
|
android:id="@+id/cardview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="15dp"
|
android:layout_marginStart="15dp"
|
||||||
|
|||||||
@@ -9,7 +9,11 @@
|
|||||||
android:id="@+id/nav_dashboard"
|
android:id="@+id/nav_dashboard"
|
||||||
android:name="de.chrissthecoder.store.ui.dashboard.DashboardFragment"
|
android:name="de.chrissthecoder.store.ui.dashboard.DashboardFragment"
|
||||||
android:label="@string/menu_dashboard"
|
android:label="@string/menu_dashboard"
|
||||||
tools:layout="@layout/fragment_dashboard" />
|
tools:layout="@layout/fragment_dashboard" >
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_nav_dashboard_to_shoppinglistLists"
|
||||||
|
app:destination="@id/shoppinglistLists" />
|
||||||
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/nav_gallery"
|
android:id="@+id/nav_gallery"
|
||||||
@@ -22,4 +26,10 @@
|
|||||||
android:name="de.chrissthecoder.store.ui.slideshow.SlideshowFragment"
|
android:name="de.chrissthecoder.store.ui.slideshow.SlideshowFragment"
|
||||||
android:label="@string/menu_slideshow"
|
android:label="@string/menu_slideshow"
|
||||||
tools:layout="@layout/fragment_slideshow" />
|
tools:layout="@layout/fragment_slideshow" />
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/shoppinglistLists"
|
||||||
|
android:name="de.chrissthecoder.store.ui.dashboard.tabfragment.shoppinglist.ShoppinglistListsFragment"
|
||||||
|
android:label="@string/nav_shoppinglist"
|
||||||
|
tools:layout="@layout/fragment_shoppinglist_lists" />
|
||||||
</navigation>
|
</navigation>
|
||||||
@@ -13,4 +13,6 @@
|
|||||||
|
|
||||||
<string name="tab_shoppinglist">Einkaufszettel</string>
|
<string name="tab_shoppinglist">Einkaufszettel</string>
|
||||||
<string name="tab_understock">Minderbestand</string>
|
<string name="tab_understock">Minderbestand</string>
|
||||||
|
|
||||||
|
<string name="nav_shoppinglist">Einkaufszettel</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user