Compare commits
4 Commits
9e54bbc978
...
layout
| Author | SHA1 | Date | |
|---|---|---|---|
| acb211c219 | |||
| 47e1283ba2 | |||
| 88325e8abe | |||
| ee8d259c51 |
@@ -4,6 +4,7 @@ import java.util.Properties
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("androidx.navigation.safeargs")
|
||||
}
|
||||
|
||||
val mqttProperties = Properties()
|
||||
|
||||
@@ -46,7 +46,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
// 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
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package de.chrissthecoder.store.adapter
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
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
|
||||
|
||||
class DashboardFragmentPagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
||||
@@ -12,7 +12,7 @@ class DashboardFragmentPagerAdapter(fragment: Fragment) : FragmentStateAdapter(f
|
||||
}
|
||||
|
||||
override fun createFragment(position: Int) : Fragment {
|
||||
return if(position == 0) { ShoplistFragment() }
|
||||
return if(position == 0) { ShoppinglistShoplistFragment() }
|
||||
else { UnderstockFragment() }
|
||||
}
|
||||
}
|
||||
@@ -8,32 +8,31 @@ import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import de.chrissthecoder.store.R
|
||||
import de.chrissthecoder.store.databinding.FragmentShoppinglistShoplistItemBinding
|
||||
import de.chrissthecoder.store.dataclass.ShoppinglistShoplistItem
|
||||
import de.chrissthecoder.store.interfaces.ShoppinglistShoplistItemClickListener
|
||||
|
||||
class ShoppinglistShoplistAdapter(val shoplist: List<ShoppinglistShoplistItem>) : RecyclerView.Adapter<ShoppinglistShoplistAdapter.ItemViewHolder>() {
|
||||
inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val shoplabel: TextView
|
||||
val shopicon: ImageView
|
||||
val shoppinglistCount: TextView
|
||||
|
||||
init {
|
||||
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)
|
||||
class ShoppinglistShoplistAdapter(val shoplist: List<ShoppinglistShoplistItem>, private val listener: ShoppinglistShoplistItemClickListener) : RecyclerView.Adapter<ShoppinglistShoplistAdapter.ItemViewHolder>() {
|
||||
inner class ItemViewHolder(private val binding: FragmentShoppinglistShoplistItemBinding, private val listener: ShoppinglistShoplistItemClickListener) : RecyclerView.ViewHolder(binding.root) {
|
||||
fun bindItem(item: ShoppinglistShoplistItem) {
|
||||
binding.shoplabel.text = item.shoplabel
|
||||
binding.shoppinglistCount.text = "(" + item.shoppinglistCount + ")"
|
||||
binding.cardview.setOnClickListener {
|
||||
listener.onClick(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
|
||||
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)
|
||||
return ItemViewHolder(view)
|
||||
val from = LayoutInflater.from(parent.context)
|
||||
val binding = FragmentShoppinglistShoplistItemBinding.inflate(from, parent, false)
|
||||
return ItemViewHolder(binding, listener)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ShoppinglistShoplistAdapter.ItemViewHolder, position: Int) {
|
||||
Log.d(this.javaClass.name,"Replace the contents of a view (invoked by the layout manager)")
|
||||
holder.shoplabel.text = shoplist[position].shoplabel
|
||||
holder.shoppinglistCount.text = "(" + shoplist[position].shoppinglistCount + ")"
|
||||
holder.bindItem(shoplist[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package de.chrissthecoder.store.dataclass
|
||||
|
||||
data class ShoppinglistShoplistItem(val shoplabel: String, val iconID: Int, val shoppinglistCount: Int)
|
||||
data class ShoppinglistShoplistItem(val shopID: Int, val shoplabel: String, val iconID: Int, val shoppinglistCount: 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,18 @@ import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import de.chrissthecoder.store.R
|
||||
import de.chrissthecoder.store.adapter.ShoppinglistShoplistAdapter
|
||||
import de.chrissthecoder.store.databinding.FragmentShoppinglistShoplistBinding
|
||||
import de.chrissthecoder.store.dataclass.ShoppinglistShoplistItem
|
||||
import de.chrissthecoder.store.interfaces.ShoppinglistShoplistItemClickListener
|
||||
import de.chrissthecoder.store.ui.dashboard.DashboardFragmentDirections
|
||||
|
||||
/**
|
||||
* A [Fragment] subclass to list all shops that contains assigned shoppinglists.
|
||||
*/
|
||||
class ShoplistFragment : Fragment() {
|
||||
class ShoppinglistShoplistFragment : Fragment(), ShoppinglistShoplistItemClickListener {
|
||||
|
||||
private var _binding: FragmentShoppinglistShoplistBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
@@ -23,11 +27,17 @@ class ShoplistFragment : Fragment() {
|
||||
_binding = FragmentShoppinglistShoplistBinding.inflate(inflater, container, false)
|
||||
|
||||
val shoplist = ArrayList<ShoppinglistShoplistItem>()
|
||||
shoplist.add(ShoppinglistShoplistItem(1,"Edeka", 0, 3))
|
||||
|
||||
val shoplistRecyclerView = binding.shoplist
|
||||
adapter = ShoppinglistShoplistAdapter(shoplist)
|
||||
adapter = ShoppinglistShoplistAdapter(shoplist, this)
|
||||
shoplistRecyclerView.adapter = adapter
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onClick(shopitem: ShoppinglistShoplistItem) {
|
||||
val direction = DashboardFragmentDirections.actionNavDashboardToShoppinglistLists(shopitem.shopID)
|
||||
findNavController().navigate(direction)
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:fitsSystemWindows="true"
|
||||
app:headerLayout="@layout/nav_header_main"
|
||||
app:menu="@menu/activity_main_drawer" />
|
||||
app:headerLayout="@layout/burger_header"
|
||||
app:menu="@menu/burger" />
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
@@ -16,5 +16,5 @@
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:navGraph="@navigation/mobile_navigation" />
|
||||
app:navGraph="@navigation/app_navigation" />
|
||||
</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"
|
||||
android:layout_width="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
|
||||
android:id="@+id/shoplist"
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<?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:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/cardview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
|
||||
@@ -9,7 +9,11 @@
|
||||
android:id="@+id/nav_dashboard"
|
||||
android:name="de.chrissthecoder.store.ui.dashboard.DashboardFragment"
|
||||
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
|
||||
android:id="@+id/nav_gallery"
|
||||
@@ -22,4 +26,14 @@
|
||||
android:name="de.chrissthecoder.store.ui.slideshow.SlideshowFragment"
|
||||
android:label="@string/menu_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" >
|
||||
<argument
|
||||
android:name="shopID"
|
||||
app:argType="integer" />
|
||||
</fragment>
|
||||
</navigation>
|
||||
@@ -13,4 +13,6 @@
|
||||
|
||||
<string name="tab_shoppinglist">Einkaufszettel</string>
|
||||
<string name="tab_understock">Minderbestand</string>
|
||||
|
||||
<string name="nav_shoppinglist">Einkaufszettel</string>
|
||||
</resources>
|
||||
@@ -1,4 +1,12 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
dependencies {
|
||||
val nav_version = "2.7.7"
|
||||
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("com.android.application") version "8.3.0" apply false
|
||||
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
|
||||
|
||||
Reference in New Issue
Block a user