Commit 61d24db5 authored by SusanneFischer's avatar SusanneFischer
Browse files

edit rental

parent bdb10fe0
Pipeline #3598 failed with stages
in 0 seconds
......@@ -39,8 +39,13 @@ class RentalItemChoiceAdapter(
.placeholder(R.drawable.placeholder)
.into(holder.itemBinding.itemImageView)
holder.isSelected = selectedItems?.contains(model) == true
var colorResId = if (selectedItems?.contains(model) == true) {
selectedItems?.forEach {
if (it.picture_name == model.picture_name) {
holder.isSelected = true
return@forEach
}
}
var colorResId = if (holder.isSelected) {
R.color.colorSecondaryLight
} else {
R.color.surface
......
package de.asta.hochschule.trier.verleih.rental.view
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.*
import androidx.activity.viewModels
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
......@@ -47,10 +48,34 @@ class EditRentalActivity : FragmentActivity() {
DateHelper.getDateTime(it).toString(DateHelper.LONG_DATE_TIME_FORMAT)
}
val isEditable = rental?.pickupdate?.let { DateHelper.getDateTime(it).isAfterNow }
if (isEditable == true) {
binding.appbar.inflateMenu(R.menu.appbar_edit_delete)
}
binding.rentalContainer.itemsRecyclerview.layoutManager = LinearLayoutManager(this)
viewModel.receiveRentalObjects(rental) {
binding.rentalContainer.itemsRecyclerview.adapter =
RentalItemOverviewAdapter(it, rental?.objects)
if (isEditable == true) {
binding.appbar.setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.appbar_edit -> {
val intent = Intent(this, NewRentalActivity::class.java)
intent.putExtra(INTENT_EXTRA_RENTAL, Gson().toJson(rental))
intent.putExtra(INTENT_EXTRA_RENTAL_OBJECTS, Gson().toJson(it))
this.startActivityForResult(intent, EDIT_RENTAL_REQUEST_CODE)
return@setOnMenuItemClickListener true
}
R.id.appbar_delete -> {
// TODO
finish()
return@setOnMenuItemClickListener true
}
else -> return@setOnMenuItemClickListener false
}
}
}
}
binding.rentalContainer.noteTitleText.text = getString(R.string.notes)
......@@ -60,15 +85,15 @@ class EditRentalActivity : FragmentActivity() {
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
}
binding.rentalContainer.editItemsButton.visibility = View.INVISIBLE
binding.rentalContainer.editInformationButton.visibility = View.INVISIBLE
}
companion object {
const val INTENT_EXTRA_RENTAL = "Rental"
const val INTENT_EXTRA_RENTAL_OBJECTS = "Rental_Objects"
private const val TAG = "EditRentalActivity"
private const val EDIT_RENTAL_REQUEST_CODE = 1
}
}
\ No newline at end of file
......@@ -8,6 +8,8 @@ import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayoutMediator
import com.google.firebase.database.FirebaseDatabase
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import de.asta.hochschule.trier.verleih.R
import de.asta.hochschule.trier.verleih.databinding.ActivityNewRentalBinding
import de.asta.hochschule.trier.verleih.rental.adapter.NewRentalPagerAdapter
......@@ -29,6 +31,20 @@ class NewRentalActivity : FragmentActivity() {
onBackPressed()
}
val rentalExtra = Gson().fromJson(
intent.getStringExtra(EditRentalActivity.INTENT_EXTRA_RENTAL),
Rental::class.java
)
val rentalObjectType = object : TypeToken<ArrayList<RentalObject>>() {}.type
val rentalObjectsExtra = Gson().fromJson<ArrayList<RentalObject>>(
intent.getStringExtra(EditRentalActivity.INTENT_EXTRA_RENTAL_OBJECTS),
rentalObjectType
)
if (rentalExtra != null && rentalObjectsExtra != null) {
viewModel.setupViewModel(rentalExtra, rentalObjectsExtra)
binding.appbar.setTitle(R.string.edit_rental)
}
val pagerAdapter = NewRentalPagerAdapter(this)
binding.newRentalPager.adapter = pagerAdapter
TabLayoutMediator(binding.newRentalPagerTabs, binding.newRentalPager) { _, _ -> }.attach()
......@@ -69,7 +85,6 @@ class NewRentalActivity : FragmentActivity() {
binding.newRentalPager.currentItem = binding.newRentalPager.currentItem + 1
}
}
}
viewModel.rentalLiveData.observe(this, { rental ->
......
......@@ -5,6 +5,7 @@ import android.view.*
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.*
import com.google.android.material.datepicker.*
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.timepicker.*
import de.asta.hochschule.trier.verleih.R
import de.asta.hochschule.trier.verleih.databinding.FragmentNewRentalDateTimeBinding
......@@ -68,6 +69,18 @@ class NewRentalDateTimeFragment : Fragment(R.layout.fragment_new_rental_date_tim
pickupTime = viewModel.rentalLiveData.value?.pickupdate?.let { DateHelper.getDateTime(it) }
returnDate = viewModel.rentalLiveData.value?.returndate?.let { DateHelper.getDateTime(it) }
returnTime = viewModel.rentalLiveData.value?.returndate?.let { DateHelper.getDateTime(it) }
setText(binding.eventTitleEditText, viewModel.rentalLiveData.value?.eventname)
setText(binding.pickupDateEditText, pickupDate?.toString(DateHelper.DATE_FORMAT))
setText(binding.returnDateEditText, returnDate?.toString(DateHelper.DATE_FORMAT))
setText(binding.pickupTimeEditText, pickupTime?.toString(DateHelper.TIME_FORMAT))
setText(binding.returnTimeEditText, returnTime?.toString(DateHelper.TIME_FORMAT))
}
private fun setText(view: TextInputEditText, text: String?) {
if (text != null) {
view.setText(text)
}
}
private fun setupDatePicker(): MaterialDatePicker<androidx.core.util.Pair<Long, Long>> {
......
......@@ -138,6 +138,12 @@ class NewRentalViewModel : ViewModel() {
}
}
fun setupViewModel(rental: Rental, rentalObjects: ArrayList<RentalObject>) {
mutableRental.value = rental
mutableRentalObjects.value = rental.objects
mutableObjects.value = rentalObjects
}
companion object {
private const val TAG = "NewRentalViewModel"
}
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/appbar_delete"
android:icon="@drawable/ic_delete"
android:title="@string/delete"
android:visible="true"
app:showAsAction="ifRoom" />
<item
android:id="@+id/appbar_edit"
android:icon="@drawable/ic_edit"
android:title="@string/edit"
android:visible="true"
app:showAsAction="always" />
</menu>
\ No newline at end of file
......@@ -37,4 +37,6 @@
<string name="booking">Verleihanfrage</string>
<string name="notes">Notizen</string>
<string name="add_note">Notiz hinzufügen</string>
<string name="edit">Bearbeiten</string>
<string name="edit_rental">Reservierung bearbeiten</string>
</resources>
\ No newline at end of file
......@@ -37,4 +37,6 @@
<string name="booking">Verleihanfrage</string>
<string name="notes">Notizen</string>
<string name="add_note">Notiz hinzufügen</string>
<string name="edit">Bearbeiten</string>
<string name="edit_rental">Reservierung bearbeiten</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