Compare commits
8 Commits
f9570806f9
...
layout
| Author | SHA1 | Date | |
|---|---|---|---|
| acb211c219 | |||
| 47e1283ba2 | |||
| 88325e8abe | |||
| ee8d259c51 | |||
| 9e54bbc978 | |||
| a355301d68 | |||
| ddc218f4cc | |||
| 083b2982b1 |
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package de.chrissthecoder.store.adapter
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import de.chrissthecoder.store.ui.dashboard.tabfragment.ShoppinglistFragment
|
||||
import de.chrissthecoder.store.ui.dashboard.tabfragment.shoppinglist.ShoppinglistShoplistFragment
|
||||
import de.chrissthecoder.store.ui.dashboard.tabfragment.UnderstockFragment
|
||||
|
||||
class DashboardFragmentPagerAdapter(manager: FragmentManager, lifecycle: Lifecycle) : FragmentStateAdapter(manager, lifecycle) {
|
||||
class DashboardFragmentPagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
||||
|
||||
override fun getItemCount() : Int {
|
||||
return 2
|
||||
}
|
||||
|
||||
override fun createFragment(position: Int) : Fragment {
|
||||
return if(position == 0) { ShoppinglistFragment() }
|
||||
return if(position == 0) { ShoppinglistShoplistFragment() }
|
||||
else { UnderstockFragment() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package de.chrissthecoder.store.adapter
|
||||
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
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>, 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 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.bindItem(shoplist[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
Log.d(this.javaClass.name, "Return the size of your dataset (invoked by the layout manager)")
|
||||
return shoplist.size
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package de.chrissthecoder.store.dataclass
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class DashboardFragment : Fragment() {
|
||||
|
||||
tabLayout = binding.tabLayout
|
||||
viewPager = binding.viewPager
|
||||
adapter = DashboardFragmentPagerAdapter(parentFragmentManager, lifecycle)
|
||||
adapter = DashboardFragmentPagerAdapter(this)
|
||||
viewPager.adapter = adapter
|
||||
|
||||
tabLayout.addOnTabSelectedListener(object : OnTabSelectedListener {
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
package de.chrissthecoder.store.ui.dashboard.tabfragment
|
||||
|
||||
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
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private const val ARG_PARAM1 = "param1"
|
||||
private const val ARG_PARAM2 = "param2"
|
||||
|
||||
/**
|
||||
* A simple [Fragment] subclass.
|
||||
* Use the [ShoppinglistFragment.newInstance] factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
class ShoppinglistFragment : Fragment() {
|
||||
// TODO: Rename and change types of parameters
|
||||
private var param1: String? = null
|
||||
private var param2: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
param1 = it.getString(ARG_PARAM1)
|
||||
param2 = it.getString(ARG_PARAM2)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_shoppinglist, container, false)
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment ShoppinglistFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
@JvmStatic
|
||||
fun newInstance(param1: String, param2: String) =
|
||||
ShoppinglistFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(ARG_PARAM1, param1)
|
||||
putString(ARG_PARAM2, param2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
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 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 ShoppinglistShoplistFragment : Fragment(), ShoppinglistShoplistItemClickListener {
|
||||
|
||||
private var _binding: FragmentShoppinglistShoplistBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private lateinit var adapter: ShoppinglistShoplistAdapter
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
_binding = FragmentShoppinglistShoplistBinding.inflate(inflater, container, false)
|
||||
|
||||
val shoplist = ArrayList<ShoppinglistShoplistItem>()
|
||||
shoplist.add(ShoppinglistShoplistItem(1,"Edeka", 0, 3))
|
||||
|
||||
val shoplistRecyclerView = binding.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,16 +4,16 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.dashboard.tabfragment.ShoppinglistFragment">
|
||||
tools:context=".ui.dashboard.tabfragment.shoppinglist.ShoppinglistShoplistFragment">
|
||||
|
||||
<TextView
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/shoplist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Einkaufszettel"
|
||||
android:textAlignment="center"
|
||||
android:textSize="32sp"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.5" />
|
||||
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,69 @@
|
||||
<?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="wrap_content">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/cardview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
app:cardBackgroundColor="@color/cardview_background"
|
||||
app:cardCornerRadius="20dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/shoplabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="20dp"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/cardview_textcolor"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.5" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/shopicon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="100dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/shoppinglistCount"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.5"
|
||||
app:srcCompat="@android:drawable/toast_frame" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/shoppinglistCount"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="20dp"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/cardview_textcolor"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.5" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -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>
|
||||
@@ -7,4 +7,7 @@
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
|
||||
<color name="cardview_background">#444444</color>
|
||||
<color name="cardview_textcolor">#FFFFFF</color>
|
||||
</resources>
|
||||
@@ -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