Commit 74ab8427 authored by SusanneFischer's avatar SusanneFischer
Browse files

added overview, load data into overview, added overview functionality

parent 0e5cde61
......@@ -11,6 +11,7 @@ object DateHelper {
const val DATE_TIME_FORMAT = "dd.MM.yyyy HH:mm"
const val PRETTY_DATE_FORMAT = "dd.MMMM yyyy"
const val TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm"
const val LONG_DATE_TIME_FORMAT = "EEE, dd.MM.yyyy HH:mm"
fun getDateTime(dateString: String): DateTime {
val formatter = DateTimeFormat.forPattern(TIMESTAMP_FORMAT).withLocale(Locale.getDefault())
......
package de.asta.hochschule.trier.verleih.rental.adapter
import androidx.fragment.app.*
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import de.asta.hochschule.trier.verleih.app.TestFragment
import de.asta.hochschule.trier.verleih.rental.view.*
class NewRentalPagerAdapter(activity: FragmentActivity) : FragmentStateAdapter(activity) {
class NewRentalPagerAdapter(private val activity: NewRentalActivity) :
FragmentStateAdapter(activity) {
override fun getItemCount(): Int {
return NewRentalActivity.NUM_PAGES
}
......@@ -15,7 +16,7 @@ class NewRentalPagerAdapter(activity: FragmentActivity) : FragmentStateAdapter(a
0 -> NewRentalDateTimeFragment()
1 -> NewRentalItemsChoiceFragment()
2 -> NewRentalItemsQuantityFragment()
3 -> NewRentalOverviewFragment()
3 -> NewRentalOverviewFragment(activity)
else -> TestFragment()
}
}
......
package de.asta.hochschule.trier.verleih.rental.adapter
import android.annotation.SuppressLint
import android.view.*
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.google.firebase.storage.FirebaseStorage
import de.asta.hochschule.trier.verleih.R
import de.asta.hochschule.trier.verleih.databinding.RowItemOverviewBinding
import de.asta.hochschule.trier.verleih.rental.model.RentalObject
import de.asta.hochschule.trier.verleih.util.GlideApp
class RentalItemOverviewAdapter(
private var objects: ArrayList<RentalObject>?,
private var components: MutableMap<String, MutableMap<String, Int>>?
) :
RecyclerView.Adapter<RentalItemOverviewAdapter.ViewHolder>() {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): ViewHolder {
val itemBinding =
RowItemOverviewBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
return ViewHolder(itemBinding)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val obj = objects?.get(position)
val objComponents = components?.get(obj?.picture_name)
holder.bind(obj, objComponents)
}
override fun getItemCount(): Int {
return objects?.size ?: 0
}
fun resetData(
objs: ArrayList<RentalObject>?,
comps: MutableMap<String, MutableMap<String, Int>>?
): RentalItemOverviewAdapter {
objects = objs
components = comps
notifyDataSetChanged()
return this
}
class ViewHolder(private val itemBinding: RowItemOverviewBinding) :
RecyclerView.ViewHolder(itemBinding.root) {
@SuppressLint("SetTextI18n")
fun bind(obj: RentalObject?, objComponents: MutableMap<String, Int>?) {
objComponents?.get(obj?.picture_name)
val itemTitle = if (objComponents != null && objComponents.size > 1) {
obj?.name
} else {
"${objComponents?.toList()?.get(0)?.second}x ${obj?.name}"
}
itemBinding.itemTitle.text = itemTitle
if (objComponents != null && objComponents.size > 1) {
itemBinding.itemComponentsLayout.removeAllViews()
objComponents.forEach {
val textView = TextView(itemView.context)
textView.text = "${it.value}x ${it.key}"
itemBinding.itemComponentsLayout.addView(textView)
}
}
val storageRef =
FirebaseStorage.getInstance().reference.child("objects/round/${obj?.picture_name}.png")
GlideApp.with(itemView.context).load(storageRef)
.placeholder(R.drawable.placeholder)
.into(itemBinding.itemCircleImageView)
}
}
}
\ No newline at end of file
......@@ -130,6 +130,12 @@ class NewRentalActivity : FragmentActivity() {
}
}
fun goToPage(page: Int) {
if (page in PAGE_DATE_TIME..PAGE_OVERVIEW) {
binding.newRentalPager.currentItem = page
}
}
private fun isValidInput(
page: Int,
rental: Rental?,
......@@ -172,10 +178,10 @@ class NewRentalActivity : FragmentActivity() {
private const val TAG = "NewRentalActivity"
const val NUM_PAGES = 4
private const val PAGE_DATE_TIME = 0
private const val PAGE_ITEMS_CHOICE = 1
private const val PAGE_ITEMS_QUANTITY = 2
private const val PAGE_OVERVIEW = 3
const val PAGE_DATE_TIME = 0
const val PAGE_ITEMS_CHOICE = 1
const val PAGE_ITEMS_QUANTITY = 2
const val PAGE_OVERVIEW = 3
}
}
\ No newline at end of file
......@@ -2,14 +2,24 @@ package de.asta.hochschule.trier.verleih.rental.view
import android.os.Bundle
import android.view.*
import androidx.fragment.app.Fragment
import androidx.fragment.app.*
import androidx.recyclerview.widget.LinearLayoutManager
import de.asta.hochschule.trier.verleih.R
import de.asta.hochschule.trier.verleih.databinding.FragmentNewRentalOverviewBinding
import de.asta.hochschule.trier.verleih.helper.DateHelper
import de.asta.hochschule.trier.verleih.rental.adapter.RentalItemOverviewAdapter
import de.asta.hochschule.trier.verleih.rental.model.Rental
import de.asta.hochschule.trier.verleih.rental.viewmodel.NewRentalViewModel
class NewRentalOverviewFragment : Fragment(R.layout.fragment_new_rental_overview) {
class NewRentalOverviewFragment(private val parentActivity: NewRentalActivity) :
Fragment(R.layout.fragment_new_rental_overview) {
private lateinit var binding: FragmentNewRentalOverviewBinding
private val viewModel: NewRentalViewModel by activityViewModels()
private var adapter: RentalItemOverviewAdapter? = null
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
......@@ -21,6 +31,44 @@ class NewRentalOverviewFragment : Fragment(R.layout.fragment_new_rental_overview
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
updateTextViews(viewModel.rentalLiveData.value)
binding.editInformationButton.setOnClickListener {
parentActivity.goToPage(NewRentalActivity.PAGE_DATE_TIME)
}
binding.editItemsButton.setOnClickListener {
parentActivity.goToPage(NewRentalActivity.PAGE_ITEMS_QUANTITY)
}
binding.itemsRecyclerview.layoutManager = LinearLayoutManager(context)
adapter = RentalItemOverviewAdapter(
viewModel.objectsLiveData.value,
viewModel.rentalObjectsLiveData.value
)
binding.itemsRecyclerview.adapter = adapter
viewModel.objectsLiveData.observe(requireActivity(), { objects ->
adapter = adapter?.resetData(objects, viewModel.rentalObjectsLiveData.value)
})
viewModel.rentalObjectsLiveData.observe(requireActivity(), { rentalObjects ->
adapter = adapter?.resetData(viewModel.objectsLiveData.value, rentalObjects)
})
viewModel.rentalLiveData.observe(requireActivity(), { rental ->
updateTextViews(rental)
})
}
private fun updateTextViews(rental: Rental?) {
binding.eventTitleText.text = rental?.eventname
binding.eventPickupText.text =
rental?.pickupdate?.let {
DateHelper.getDateTime(it).toString(DateHelper.LONG_DATE_TIME_FORMAT)
}
binding.eventReturnText.text =
rental?.returndate?.let {
DateHelper.getDateTime(it).toString(DateHelper.LONG_DATE_TIME_FORMAT)
}
}
companion object {
......
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/item_circle_image_view"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:foregroundGravity="top"
android:src="@drawable/panda"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/item_title"
style="@style/Body1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:text="1x Grill"
app:layout_constraintBottom_toBottomOf="@id/item_circle_image_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/item_circle_image_view"
app:layout_constraintTop_toTopOf="@id/item_circle_image_view" />
<LinearLayout
android:id="@+id/item_components_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/item_title"
app:layout_constraintTop_toBottomOf="@id/item_circle_image_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -7,8 +7,8 @@
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/item_quantity_chip_group"
......@@ -20,6 +20,8 @@
style="@style/Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="Anzahl:" />
<TextView
......@@ -36,9 +38,7 @@
android:id="@+id/item_quantity_chip_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment