Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper is able to cancel accepted request #137

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class HelperDetailFragment : Fragment() {

viewModel.idOfRequest.observe(viewLifecycleOwner, Observer { idOfRequest ->
binding.buttonAccept.setOnClickListener {
viewModel.acceptRequest(idOfRequest)
viewModel.acceptOrDeclineRequest(idOfRequest)
findNavController().popBackStack()
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package app.nexd.android.ui.helper.detail

import android.graphics.Typeface
import android.util.Log
import android.widget.Button
import androidx.databinding.BindingAdapter
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import app.nexd.android.Api
Expand All @@ -24,12 +27,18 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() {
val city = MutableLiveData<String>()
val requestArticles = MutableLiveData<List<HelpRequestArticle>>()
val requestIsAccepted = MutableLiveData<Boolean>()
val buttonText = MutableLiveData<String>()
val idOfRequest = MutableLiveData<Long>()

private val compositeDisposable = CompositeDisposable()

fun acceptRequest(requestId: Long) {
fun acceptOrDeclineRequest(requestId: Long) {
requestIsAccepted.value?.let {
if (it) declineRequest(requestId)
else acceptRequest(requestId)
}
}

private fun acceptRequest(requestId: Long) {
api.helpListsControllerGetUserLists(null)
.map { lists ->
if (lists.any { it.status == HelpList.StatusEnum.ACTIVE })
Expand Down Expand Up @@ -57,6 +66,18 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() {
.blockingSubscribe()
}

private fun declineRequest(requestId: Long) {
val helpListIdFromRequest =
api.helpRequestsControllerGetSingleRequest(requestId).blockingFirst().helpListId
helpListIdFromRequest?.let { helpListId ->
hunnihundert marked this conversation as resolved.
Show resolved Hide resolved
api.helpListsControllerDeleteHelpRequestFromHelpList(helpListId, requestId)
.subscribeOn(io())
hunnihundert marked this conversation as resolved.
Show resolved Hide resolved
.doOnError {
Log.e("Error", it.message.toString())
}.blockingSubscribe()
hunnihundert marked this conversation as resolved.
Show resolved Hide resolved
}
}

fun setInfo(requestId: Long) {
val observable = api.helpRequestsControllerGetSingleRequest(requestId)

Expand Down Expand Up @@ -84,4 +105,15 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() {
super.onCleared()
compositeDisposable.clear()
}

object ButtonTextStyleBinding {
hunnihundert marked this conversation as resolved.
Show resolved Hide resolved
@JvmStatic
@BindingAdapter("app:textStyle")
fun setTextStyle(button: Button, style: String) {
when (style) {
"bold" -> button.setTypeface(null, Typeface.BOLD)
else -> button.setTypeface(null, Typeface.NORMAL)
}
}
}
}
5 changes: 3 additions & 2 deletions app/src/main/res/layout/fragment_helper_request_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_white"
android:enabled="@{!viewModel.requestIsAccepted}"
android:text="@{viewModel.requestIsAccepted? @string/helper_request_detail_button_accepted : @string/helper_request_detail_button_accept}"
android:text="@{viewModel.requestIsAccepted? @string/helper_request_detail_button_cancel : @string/helper_request_detail_button_accept}"
android:textColor="@{!viewModel.requestIsAccepted? @android:color/black : @android:color/holo_red_dark}"
app:textStyle='@{!viewModel.requestIsAccepted? "normal" : "bold"}'
android:textAllCaps="false"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_transcript_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
android:autofillHints="postal-code"
android:background="@drawable/rounded_white"
android:error="@{viewModel.zipCodeError}"
android:inputType="number"
android:inputType="textPostalAddress"
android:nextFocusDown="@id/editText_city_value"
android:padding="10dp"
android:text="@={viewModel.zipCode}"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<string name="helper_request_detail_screen_title">"Zu Einkaufen"</string>
<string name="helper_request_detail_button_accepted">"Anfrage bereits angenommen"</string>
<string name="helper_request_detail_button_accept">"Mach ich!"</string>
<string name="helper_request_detail_button_cancel">"Kann ich leider nicht machen "</string>
<string name="delivery_screen_title">"Abgabe!"</string>
<string name="delivery_dialog_deliver_title">"Abgeben"</string>
<string name="delivery_dialog_deliver_description">"Bitte bestätige die Abgabe aller angenommen Aufträge"</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<string name="helper_request_detail_screen_title">"To collect"</string>
<string name="helper_request_detail_button_accepted">"Request already accepted"</string>
<string name="helper_request_detail_button_accept">"Will do!"</string>
<string name="helper_request_detail_button_cancel">"Have to cancel"</string>
<string name="delivery_screen_title">"Delivery!"</string>
<string name="delivery_dialog_deliver_title">"Deliver"</string>
<string name="delivery_dialog_deliver_description">"Confirm the delivery of all accepted requests"</string>
Expand Down