Commit bdb10fe0 authored by SusanneFischer's avatar SusanneFischer
Browse files

show rental overview on item click in main rental list, disable edit buttons on past rentals

parent 27bbad26
......@@ -28,6 +28,9 @@
<activity
android:name=".rental.view.NewRentalActivity"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".rental.view.EditRentalActivity"
android:windowSoftInputMode="adjustPan" />
</application>
</manifest>
\ No newline at end of file
......@@ -2,6 +2,7 @@ package de.asta.hochschule.trier.verleih.helper
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import java.text.SimpleDateFormat
import java.util.*
object DateHelper {
......@@ -25,4 +26,10 @@ object DateHelper {
"${dateTime.hourOfDay().asString}:${dateTime.minuteOfHour().asText}"
}
}
fun timeStampToString(timeStamp: Long, format: String): String {
val date = Date(timeStamp)
val formatter = SimpleDateFormat(format, Locale.getDefault())
return formatter.format(date)
}
}
\ No newline at end of file
package de.asta.hochschule.trier.verleih.rental.adapter
import android.view.*
import androidx.recyclerview.widget.RecyclerView
import de.asta.hochschule.trier.verleih.databinding.RowNoteOverviewBinding
import de.asta.hochschule.trier.verleih.helper.DateHelper
class EditRentalNotesAdapter(private var notes: MutableMap<String, String>?) :
RecyclerView.Adapter<EditRentalNotesAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val itemBinding =
RowNoteOverviewBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
return ViewHolder(itemBinding)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(notes?.toList()?.get(position))
}
override fun getItemCount(): Int {
return notes?.size ?: 0
}
class ViewHolder(private val itemBinding: RowNoteOverviewBinding) :
RecyclerView.ViewHolder(itemBinding.root) {
fun bind(note: Pair<String, String>?) {
itemBinding.noteTimeText.text =
note?.first?.toLong()?.let {
DateHelper.timeStampToString(it, DateHelper.DATE_TIME_FORMAT)
}
itemBinding.noteContentText.text = note?.second
}
}
}
\ No newline at end of file
package de.asta.hochschule.trier.verleih.rental.adapter
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.view.*
import androidx.recyclerview.widget.RecyclerView
import com.firebase.ui.database.*
import com.google.gson.Gson
import de.asta.hochschule.trier.verleih.databinding.RowRentalListBinding
import de.asta.hochschule.trier.verleih.helper.DateHelper
import de.asta.hochschule.trier.verleih.rental.model.Rental
import de.asta.hochschule.trier.verleih.rental.view.EditRentalActivity
import org.joda.time.DateTime
import java.util.*
class RentalMainListAdapter(
private val context: Activity,
private val options: FirebaseRecyclerOptions<Rental>,
private val showEmptyState: (Boolean) -> Unit
) : FirebaseRecyclerAdapter<
......@@ -36,6 +41,12 @@ class RentalMainListAdapter(
} else {
returnDateTime?.let { setupDateTimeText(holder, it) }
}
holder.itemView.setOnClickListener {
val intent = Intent(context, EditRentalActivity::class.java)
intent.putExtra(EditRentalActivity.INTENT_EXTRA_RENTAL, Gson().toJson(model))
context.startActivity(intent)
}
}
@SuppressLint("SetTextI18n")
......
package de.asta.hochschule.trier.verleih.rental.view
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson
import de.asta.hochschule.trier.verleih.R
import de.asta.hochschule.trier.verleih.databinding.ActivityEditRentalBinding
import de.asta.hochschule.trier.verleih.helper.DateHelper
import de.asta.hochschule.trier.verleih.rental.adapter.*
import de.asta.hochschule.trier.verleih.rental.model.Rental
import de.asta.hochschule.trier.verleih.rental.viewmodel.EditRentalViewModel
class EditRentalActivity : FragmentActivity() {
private lateinit var binding: ActivityEditRentalBinding
private var rental: Rental? = null
private val viewModel: EditRentalViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityEditRentalBinding.inflate(layoutInflater)
setContentView(binding.root)
rental = Gson().fromJson(intent.getStringExtra(INTENT_EXTRA_RENTAL), Rental::class.java)
binding.appbar.setNavigationOnClickListener {
onBackPressed()
}
binding.rentalContainer.overviewDescription.visibility = View.GONE
binding.rentalContainer.statusText.visibility = View.VISIBLE
binding.rentalContainer.statusDescription.visibility = View.VISIBLE
binding.rentalContainer.eventTitleText.text = rental?.eventname
binding.rentalContainer.statusText.text = rental?.status
binding.rentalContainer.eventPickupText.text =
rental?.pickupdate?.let {
DateHelper.getDateTime(it).toString(DateHelper.LONG_DATE_TIME_FORMAT)
}
binding.rentalContainer.eventReturnText.text =
rental?.returndate?.let {
DateHelper.getDateTime(it).toString(DateHelper.LONG_DATE_TIME_FORMAT)
}
binding.rentalContainer.itemsRecyclerview.layoutManager = LinearLayoutManager(this)
viewModel.receiveRentalObjects(rental) {
binding.rentalContainer.itemsRecyclerview.adapter =
RentalItemOverviewAdapter(it, rental?.objects)
}
binding.rentalContainer.noteTitleText.text = getString(R.string.notes)
binding.rentalContainer.noteDescription.visibility = View.GONE
binding.rentalContainer.notesRecyclerView.visibility = View.VISIBLE
binding.rentalContainer.notesRecyclerView.layoutManager = LinearLayoutManager(this)
binding.rentalContainer.notesRecyclerView.adapter = EditRentalNotesAdapter(rental?.notes)
binding.rentalContainer.noteTextInputLayout.hint = getString(R.string.add_note)
val isEditable = rental?.pickupdate?.let { DateHelper.getDateTime(it).isAfterNow }
if (isEditable == false) {
binding.rentalContainer.editItemsButton.visibility = View.INVISIBLE
binding.rentalContainer.editInformationButton.visibility = View.INVISIBLE
}
}
companion object {
const val INTENT_EXTRA_RENTAL = "Rental"
private const val TAG = "EditRentalActivity"
}
}
\ No newline at end of file
......@@ -56,15 +56,16 @@ class RentalMainFragment : Fragment(R.layout.fragment_rental_main) {
val optionsRecent =
FirebaseRecyclerOptions.Builder<Rental>().setQuery(queryRecent, Rental::class.java)
.build()
recentRentalsAdapter = RentalMainListAdapter(optionsRecent) { showEmptyState ->
recentRentalsIsEmpty = showEmptyState
toggleEmptyState(
recentRentalsIsEmpty,
binding.noRecentRentalsText,
recentRentalsIsExpanded,
binding.recentRentalsHeaderIcon
)
}
recentRentalsAdapter =
RentalMainListAdapter(requireActivity(), optionsRecent) { showEmptyState ->
recentRentalsIsEmpty = showEmptyState
toggleEmptyState(
recentRentalsIsEmpty,
binding.noRecentRentalsText,
recentRentalsIsExpanded,
binding.recentRentalsHeaderIcon
)
}
binding.recentRentalsRecyclerView.layoutManager = LinearLayoutManager(this.context)
binding.recentRentalsRecyclerView.adapter = recentRentalsAdapter
......@@ -74,15 +75,16 @@ class RentalMainFragment : Fragment(R.layout.fragment_rental_main) {
val optionsPast =
FirebaseRecyclerOptions.Builder<Rental>().setQuery(queryPast, Rental::class.java)
.build()
pastRentalsAdapter = RentalMainListAdapter(optionsPast) { showEmptyState ->
pastRentalsIsEmpty = showEmptyState
toggleEmptyState(
pastRentalsIsEmpty,
binding.noPastRentalsText,
pastRentalsIsExpanded,
binding.pastRentalsHeaderIcon
)
}
pastRentalsAdapter =
RentalMainListAdapter(requireActivity(), optionsPast) { showEmptyState ->
pastRentalsIsEmpty = showEmptyState
toggleEmptyState(
pastRentalsIsEmpty,
binding.noPastRentalsText,
pastRentalsIsExpanded,
binding.pastRentalsHeaderIcon
)
}
binding.pastRentalsRecyclerView.layoutManager = LinearLayoutManager(this.context)
binding.pastRentalsRecyclerView.adapter = pastRentalsAdapter
......
package de.asta.hochschule.trier.verleih.rental.viewmodel
import android.util.Log
import androidx.lifecycle.ViewModel
import com.google.firebase.database.FirebaseDatabase
import de.asta.hochschule.trier.verleih.rental.model.*
class EditRentalViewModel : ViewModel() {
fun receiveRentalObjects(
rental: Rental?,
allRentalObjectsReceived: (ArrayList<RentalObject>) -> Unit
) {
val rentalObjects = ArrayList<RentalObject>()
rental?.objects?.forEach { o ->
val childrenReference = FirebaseDatabase.getInstance().reference.child("objects")
.orderByChild("picture_name").equalTo(o.key).limitToFirst(1)
childrenReference.get().addOnSuccessListener { allChildren ->
allChildren.children.forEach { child ->
val rentalObject = child.getValue(RentalObject::class.java)
if (rentalObject != null) {
rentalObjects.add(rentalObject)
}
}
}.addOnFailureListener { Log.e(TAG, it.message.toString()) }.addOnCompleteListener {
allRentalObjectsReceived.invoke(rentalObjects)
}
}
}
companion object {
private const val TAG = "EditRentalViewModel"
}
}
\ No newline at end of file
<?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="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:navigationIcon="?attr/homeAsUpIndicator"
app:title="@string/booking" />
</com.google.android.material.appbar.AppBarLayout>
<include
android:id="@+id/rental_container"
layout="@layout/fragment_new_rental_overview"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/appbar_layout" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -88,6 +88,30 @@
app:layout_constraintStart_toEndOf="@id/event_title_description"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/status_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Abgeschlossen"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/event_title_description"
app:layout_constraintTop_toBottomOf="@id/event_title_text" />
<TextView
android:id="@+id/status_description"
style="@style/Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status:"
android:textColor="@color/colorSecondaryLight"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/status_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/status_text" />
<TextView
android:id="@+id/event_pickup_description"
style="@style/Caption"
......@@ -108,7 +132,7 @@
android:text="Mi. 12.05.2021 um 12:45 Uhr"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/event_title_description"
app:layout_constraintTop_toBottomOf="@id/event_title_text" />
app:layout_constraintTop_toBottomOf="@id/status_text" />
<TextView
android:id="@+id/event_return_description"
......@@ -214,16 +238,34 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/note_description"
style="@style/Caption"
<LinearLayout
android:id="@+id/notes_content_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="Du hast noch Anmerkungen zu deiner Reservierung? Dann ist hier der richtige Platz dafür."
app:layout_constraintTop_toBottomOf="@id/note_title_text" />
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/note_title_text">
<TextView
android:id="@+id/note_description"
style="@style/Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="Du hast noch Anmerkungen zu deiner Reservierung? Dann ist hier der richtige Platz dafür."
app:layout_constraintTop_toBottomOf="@id/note_title_text" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/notes_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/note_title_text" />
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/note_text_input_layout"
......@@ -237,7 +279,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/note_description">
app:layout_constraintTop_toBottomOf="@id/notes_content_layout">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/note_text_input_edit_text"
......
<?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">
<TextView
android:id="@+id/note_time_text"
style="@style/Caption"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="15.02.2021 12:00"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/note_content_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Eine Notiz"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/note_time_text" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -34,4 +34,7 @@
<string name="deleted">gelöscht</string>
<string name="undo">Rückgängig</string>
<string name="quantity">Anzahl</string>
<string name="booking">Verleihanfrage</string>
<string name="notes">Notizen</string>
<string name="add_note">Notiz hinzufügen</string>
</resources>
\ No newline at end of file
......@@ -34,4 +34,7 @@
<string name="deleted">gelöscht</string>
<string name="undo">Rückgängig</string>
<string name="quantity">Anzahl</string>
<string name="booking">Verleihanfrage</string>
<string name="notes">Notizen</string>
<string name="add_note">Notiz hinzufügen</string>
</resources>
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