From 753b96e8fa8ed346de78de61d1c9f4a2e8fa6787 Mon Sep 17 00:00:00 2001 From: hunnihundert <47563806+hunnihundert@users.noreply.github.com> Date: Fri, 29 May 2020 16:52:28 +0900 Subject: [PATCH 1/8] changed input type for zip code input field in transcript info --- app/src/main/res/layout/fragment_transcript_info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/layout/fragment_transcript_info.xml b/app/src/main/res/layout/fragment_transcript_info.xml index e9fce1b..4084895 100644 --- a/app/src/main/res/layout/fragment_transcript_info.xml +++ b/app/src/main/res/layout/fragment_transcript_info.xml @@ -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}" From d7d4f3cb2bc591942e4ff08884ca6058db74ce57 Mon Sep 17 00:00:00 2001 From: hunnihundert <47563806+hunnihundert@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:39:29 +0900 Subject: [PATCH 2/8] implemented cancel accepted request --- .../ui/helper/detail/HelperDetailFragment.kt | 2 +- .../ui/helper/detail/HelperDetailViewModel.kt | 36 +++++++++++++++++-- .../layout/fragment_helper_request_detail.xml | 5 +-- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt index 63f3233..39c33a0 100644 --- a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt +++ b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt @@ -65,7 +65,7 @@ class HelperDetailFragment : Fragment() { viewModel.idOfRequest.observe(viewLifecycleOwner, Observer { idOfRequest -> binding.buttonAccept.setOnClickListener { - viewModel.acceptRequest(idOfRequest) + viewModel.acceptOrDeclineRequest(idOfRequest) findNavController().popBackStack() } }) diff --git a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt index 7bb874f..188cd0e 100644 --- a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt +++ b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt @@ -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 @@ -24,12 +27,18 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() { val city = MutableLiveData() val requestArticles = MutableLiveData>() val requestIsAccepted = MutableLiveData() - val buttonText = MutableLiveData() val idOfRequest = MutableLiveData() 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 }) @@ -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 -> + api.helpListsControllerDeleteHelpRequestFromHelpList(helpListId, requestId) + .subscribeOn(io()) + .doOnError { + Log.e("Error", it.message.toString()) + }.blockingSubscribe() + } + } + fun setInfo(requestId: Long) { val observable = api.helpRequestsControllerGetSingleRequest(requestId) @@ -84,4 +105,15 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() { super.onCleared() compositeDisposable.clear() } + + object ButtonTextStyleBinding { + @JvmStatic + @BindingAdapter("app:textStyle") + fun setTextStyle(button: Button, style: String) { + when (style) { + "bold" -> button.setTypeface(null, Typeface.BOLD) + else -> button.setTypeface(null, Typeface.NORMAL) + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_helper_request_detail.xml b/app/src/main/res/layout/fragment_helper_request_detail.xml index ae43755..16a2a02 100644 --- a/app/src/main/res/layout/fragment_helper_request_detail.xml +++ b/app/src/main/res/layout/fragment_helper_request_detail.xml @@ -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" diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index acbdc46..2a5dd50 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -57,6 +57,7 @@ "Zu Einkaufen" "Anfrage bereits angenommen" "Mach ich!" + "Kann ich leider nicht machen " "Abgabe!" "Abgeben" "Bitte bestätige die Abgabe aller angenommen Aufträge" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f08bfcc..a820d1d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -57,6 +57,7 @@ "To collect" "Request already accepted" "Will do!" + "Have to cancel" "Delivery!" "Deliver" "Confirm the delivery of all accepted requests" From 3583f55bc9041a1147d5e6843ca6f4d87e067d47 Mon Sep 17 00:00:00 2001 From: hunnihundert <47563806+hunnihundert@users.noreply.github.com> Date: Sat, 20 Jun 2020 16:50:14 +0900 Subject: [PATCH 3/8] moved text style binding for accept/decline request button from ViewModel to Fragment added progress to ViewModel and let Fragment observe it for showing status, indicating loading (TODO) and going back to the request overview removed unnecessary .subscribeOn(io), switched from .blockingSubscribe() to .subscribeBy() for accepting/declining request added strings for feedback (SnackBar) to user in case of accepted/declined requests --- .../ui/helper/detail/HelperDetailFragment.kt | 46 ++++++++++- .../ui/helper/detail/HelperDetailViewModel.kt | 76 +++++++++++-------- app/src/main/res/values-de/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 4 files changed, 94 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt index 39c33a0..e7b24ad 100644 --- a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt +++ b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt @@ -1,9 +1,12 @@ package app.nexd.android.ui.helper.detail +import android.graphics.Typeface import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Button +import androidx.databinding.BindingAdapter import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.navigation.fragment.findNavController @@ -11,7 +14,9 @@ import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager import app.nexd.android.api.model.HelpRequestArticle import app.nexd.android.databinding.FragmentHelperRequestDetailBinding +import app.nexd.android.ui.common.DefaultSnackbar import app.nexd.android.ui.common.HelpRequestArticleBinder +import com.google.android.material.snackbar.Snackbar import mva2.adapter.ListSection import mva2.adapter.MultiViewAdapter import org.koin.androidx.viewmodel.ext.android.viewModel @@ -66,8 +71,47 @@ class HelperDetailFragment : Fragment() { viewModel.idOfRequest.observe(viewLifecycleOwner, Observer { idOfRequest -> binding.buttonAccept.setOnClickListener { viewModel.acceptOrDeclineRequest(idOfRequest) - findNavController().popBackStack() } }) + + viewModel.progress.observe(viewLifecycleOwner, Observer { progress -> + when (progress) { + is HelperDetailViewModel.Progress.Idle -> { + // do nothing + } + is HelperDetailViewModel.Progress.Loading -> { + // TODO: Show loading circle + } + is HelperDetailViewModel.Progress.Finished -> { + DefaultSnackbar( + requireParentFragment().requireView(), + progress.message, + Snackbar.LENGTH_SHORT + ) + findNavController().popBackStack() + } + is HelperDetailViewModel.Progress.Error -> { + DefaultSnackbar( + requireParentFragment().requireView(), + progress.message, + Snackbar.LENGTH_SHORT + ) + findNavController().popBackStack() + } + } + + }) + } + + + object ButtonTextStyleBinding { + @JvmStatic + @BindingAdapter("app:textStyle") + fun setTextStyle(button: Button, style: String) { + when (style) { + "bold" -> button.setTypeface(null, Typeface.BOLD) + else -> button.setTypeface(null, Typeface.NORMAL) + } + } } } diff --git a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt index 188cd0e..ab148f0 100644 --- a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt +++ b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt @@ -1,22 +1,25 @@ 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.annotation.StringRes import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import app.nexd.android.Api +import app.nexd.android.R import app.nexd.android.api.model.HelpList import app.nexd.android.api.model.HelpListCreateDto import app.nexd.android.api.model.HelpRequestArticle import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import io.reactivex.rxkotlin.subscribeBy -import io.reactivex.schedulers.Schedulers.io class HelperDetailViewModel(private val api: Api) : ViewModel() { + sealed class Progress { + object Idle : Progress() + object Loading : Progress() + class Finished(@StringRes val message: Int) : Progress() + class Error(val message: String) : Progress() + } val additionalRequest = MutableLiveData() val firstName = MutableLiveData() @@ -29,9 +32,12 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() { val requestIsAccepted = MutableLiveData() val idOfRequest = MutableLiveData() + val progress = MutableLiveData(Progress.Idle) + private val compositeDisposable = CompositeDisposable() fun acceptOrDeclineRequest(requestId: Long) { + progress.value = Progress.Loading requestIsAccepted.value?.let { if (it) declineRequest(requestId) else acceptRequest(requestId) @@ -39,7 +45,7 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() { } private fun acceptRequest(requestId: Long) { - api.helpListsControllerGetUserLists(null) + val disposable = api.helpListsControllerGetUserLists(null) .map { lists -> if (lists.any { it.status == HelpList.StatusEnum.ACTIVE }) lists.first { it.status == HelpList.StatusEnum.ACTIVE } @@ -59,28 +65,46 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() { ) } } - .subscribeOn(io()) - .doOnError { - Log.e("Error", it.message.toString()) - } - .blockingSubscribe() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeBy( + onError = { + progress.value = Progress.Error(it.message ?: "Unknown Error") + }, + onComplete = { + progress.value = + Progress.Finished(R.string.helper_request_detail_request_accepted) + } + ) + compositeDisposable.add(disposable) + } private fun declineRequest(requestId: Long) { - val helpListIdFromRequest = - api.helpRequestsControllerGetSingleRequest(requestId).blockingFirst().helpListId - helpListIdFromRequest?.let { helpListId -> - api.helpListsControllerDeleteHelpRequestFromHelpList(helpListId, requestId) - .subscribeOn(io()) - .doOnError { - Log.e("Error", it.message.toString()) - }.blockingSubscribe() - } + val helpListToDecline = + api.helpRequestsControllerGetSingleRequest(requestId) + val disposable = helpListToDecline + .observeOn(AndroidSchedulers.mainThread()) + .flatMap { helpListId -> + api.helpListsControllerDeleteHelpRequestFromHelpList( + helpListId.helpListId, + requestId + ) + + }.observeOn(AndroidSchedulers.mainThread()) + .subscribeBy( + onError = { + progress.value = Progress.Error(it.message ?: "Unknown Error") + }, + onComplete = { + progress.value = + Progress.Finished(R.string.helper_request_detail_request_declined) + } + ) + compositeDisposable.add(disposable) } fun setInfo(requestId: Long) { val observable = api.helpRequestsControllerGetSingleRequest(requestId) - val disposable = observable .observeOn(AndroidSchedulers.mainThread()) .subscribeBy( @@ -106,14 +130,4 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() { compositeDisposable.clear() } - object ButtonTextStyleBinding { - @JvmStatic - @BindingAdapter("app:textStyle") - fun setTextStyle(button: Button, style: String) { - when (style) { - "bold" -> button.setTypeface(null, Typeface.BOLD) - else -> button.setTypeface(null, Typeface.NORMAL) - } - } - } } \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 2a5dd50..39e60ba 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -181,6 +181,8 @@ "Lieferhinweis" "The delivery address is not available." "Die Einkaufsliste ist fehlerhaft oder enthält keine Einträge." + Die Anfrage wurde angenommen! + Die Anfrage wurde abgelehnt. "Bisher hast du noch keine Anfragen angenommen. Bitte tippe auf eine offene Anfrage um sie anzusehen und anzunehmen." "Für deine eingestellte Region sind derzeit keine offenen Anfragen vorhanden. Bitte such in einer anderen Region in deiner Nähe oder hilf uns in dem du Telefonanrufe übersetzt." "Bitte gib den Namen, Anzahl und Maßeinheit des Artikels an den du zur Liste hinzufügen möchtest." diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a820d1d..672f3be 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -181,6 +181,8 @@ phone call" "Delivery comment" "The delivery address is not available." "The shopping list is empty or failed to load." + The request has been accepted! + The request has been declined. "No accepted requests found. Please chose requests from the list below." "Currently there are no open requests in your selected region. Please try to check other regions nearby for open requests or help us by translating phone calls." "To add a new article to the list provide its name, amount and unit." From 2aca2b7116c9b0b44965669508347d958b4ad1cf Mon Sep 17 00:00:00 2001 From: hunnihundert <47563806+hunnihundert@users.noreply.github.com> Date: Sun, 21 Jun 2020 07:08:56 +0900 Subject: [PATCH 4/8] moved text style binding for buttons from HelperDetailFragment to DataBindingAdapters now all cases are covered (normal, bold, italic, italic_bold) by using all lower snake case, in case of non recognized value "normal" will be used --- .../ui/helper/detail/HelperDetailFragment.kt | 13 ------------- .../nexd/android/ui/utils/DataBindingAdapters.kt | 13 +++++++++++++ .../res/layout/fragment_helper_request_detail.xml | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt index e7b24ad..e682308 100644 --- a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt +++ b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt @@ -1,12 +1,9 @@ package app.nexd.android.ui.helper.detail -import android.graphics.Typeface import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.Button -import androidx.databinding.BindingAdapter import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.navigation.fragment.findNavController @@ -104,14 +101,4 @@ class HelperDetailFragment : Fragment() { } - object ButtonTextStyleBinding { - @JvmStatic - @BindingAdapter("app:textStyle") - fun setTextStyle(button: Button, style: String) { - when (style) { - "bold" -> button.setTypeface(null, Typeface.BOLD) - else -> button.setTypeface(null, Typeface.NORMAL) - } - } - } } diff --git a/app/src/main/java/app/nexd/android/ui/utils/DataBindingAdapters.kt b/app/src/main/java/app/nexd/android/ui/utils/DataBindingAdapters.kt index 97dcaeb..68fcb3c 100644 --- a/app/src/main/java/app/nexd/android/ui/utils/DataBindingAdapters.kt +++ b/app/src/main/java/app/nexd/android/ui/utils/DataBindingAdapters.kt @@ -1,5 +1,7 @@ package app.nexd.android.ui.utils +import android.graphics.Typeface +import android.widget.Button import android.widget.TextView import androidx.annotation.StringRes import androidx.databinding.BindingAdapter @@ -17,4 +19,15 @@ object DataBindingAdapters { fun textViewBindText(view: TextView, @StringRes text: Int) { view.text = if (text != 0) view.context.getString(text) else null } + + @JvmStatic + @BindingAdapter("android:textStyle") + fun setTextStyle(view: Button, style: String) { + when (style) { + "bold" -> view.setTypeface(null, Typeface.BOLD) + "italic" -> view.setTypeface(null, Typeface.ITALIC) + "bold_italic" -> view.setTypeface(null, Typeface.BOLD_ITALIC) + else -> view.setTypeface(null, Typeface.NORMAL) + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_helper_request_detail.xml b/app/src/main/res/layout/fragment_helper_request_detail.xml index 16a2a02..229731f 100644 --- a/app/src/main/res/layout/fragment_helper_request_detail.xml +++ b/app/src/main/res/layout/fragment_helper_request_detail.xml @@ -130,7 +130,7 @@ android:background="@drawable/rounded_white" 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:textStyle='@{!viewModel.requestIsAccepted? "normal" : "bold"}' android:textAllCaps="false" android:textSize="20sp" app:layout_constraintBottom_toBottomOf="parent" From 40eb612946d96eba6fbff6e8138beed542e89741 Mon Sep 17 00:00:00 2001 From: hunnihundert <47563806+hunnihundert@users.noreply.github.com> Date: Sun, 21 Jun 2020 09:15:59 +0900 Subject: [PATCH 5/8] checking if there is an issue with CI as build is showing an error despite there being none --- .../app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt index ab148f0..70bf662 100644 --- a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt +++ b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailViewModel.kt @@ -119,6 +119,7 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() { additionalRequest.value = it.additionalRequest idOfRequest.value = it.id requestIsAccepted.value = (it.helpListId != null) + } ) @@ -130,4 +131,6 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() { compositeDisposable.clear() } + // added comment for checking possible CI issues + } \ No newline at end of file From 449bab0bb7c5fa2d610415a0eb82542e846c8e14 Mon Sep 17 00:00:00 2001 From: hunnihundert <47563806+hunnihundert@users.noreply.github.com> Date: Sun, 21 Jun 2020 09:26:08 +0900 Subject: [PATCH 6/8] DefaultSnackbar arguments changed for possible ci issue --- .../app/nexd/android/ui/helper/detail/HelperDetailFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt index e682308..3bbfcd6 100644 --- a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt +++ b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt @@ -81,7 +81,7 @@ class HelperDetailFragment : Fragment() { } is HelperDetailViewModel.Progress.Finished -> { DefaultSnackbar( - requireParentFragment().requireView(), + binding.buttonAccept, progress.message, Snackbar.LENGTH_SHORT ) @@ -89,7 +89,7 @@ class HelperDetailFragment : Fragment() { } is HelperDetailViewModel.Progress.Error -> { DefaultSnackbar( - requireParentFragment().requireView(), + binding.buttonAccept, progress.message, Snackbar.LENGTH_SHORT ) From e0b5800312b0b034f068498ac97c9c343a73b836 Mon Sep 17 00:00:00 2001 From: hunnihundert <47563806+hunnihundert@users.noreply.github.com> Date: Sun, 21 Jun 2020 09:30:54 +0900 Subject: [PATCH 7/8] changing DefaultSnackbar to DefaultSnackBar due to possible mix up of previous commits/merges --- .../android/ui/helper/detail/HelperDetailFragment.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt index 3bbfcd6..3050947 100644 --- a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt +++ b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt @@ -11,7 +11,7 @@ import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager import app.nexd.android.api.model.HelpRequestArticle import app.nexd.android.databinding.FragmentHelperRequestDetailBinding -import app.nexd.android.ui.common.DefaultSnackbar +import app.nexd.android.ui.common.DefaultSnackBar import app.nexd.android.ui.common.HelpRequestArticleBinder import com.google.android.material.snackbar.Snackbar import mva2.adapter.ListSection @@ -80,16 +80,16 @@ class HelperDetailFragment : Fragment() { // TODO: Show loading circle } is HelperDetailViewModel.Progress.Finished -> { - DefaultSnackbar( - binding.buttonAccept, + DefaultSnackBar( + requireParentFragment().requireView(), progress.message, Snackbar.LENGTH_SHORT ) findNavController().popBackStack() } is HelperDetailViewModel.Progress.Error -> { - DefaultSnackbar( - binding.buttonAccept, + DefaultSnackBar( + requireParentFragment().requireView(), progress.message, Snackbar.LENGTH_SHORT ) From 0c665582cd4b4089049a2a0272c6dde8d928ac63 Mon Sep 17 00:00:00 2001 From: hunnihundert <47563806+hunnihundert@users.noreply.github.com> Date: Sun, 21 Jun 2020 13:05:55 +0900 Subject: [PATCH 8/8] removed if-programming-logic from layout xml, moved to underlying Fragment removed with above mentioned related DataBindingAdapter --- .../ui/helper/detail/HelperDetailFragment.kt | 17 +++++++++++++++++ .../requestOverview/HelperOverviewFragment.kt | 4 ++-- .../android/ui/utils/DataBindingAdapters.kt | 13 ------------- .../layout/fragment_helper_request_detail.xml | 3 --- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt index 3050947..3014703 100644 --- a/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt +++ b/app/src/main/java/app/nexd/android/ui/helper/detail/HelperDetailFragment.kt @@ -1,5 +1,6 @@ package app.nexd.android.ui.helper.detail +import android.graphics.Typeface import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -9,6 +10,7 @@ import androidx.lifecycle.Observer import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager +import app.nexd.android.R import app.nexd.android.api.model.HelpRequestArticle import app.nexd.android.databinding.FragmentHelperRequestDetailBinding import app.nexd.android.ui.common.DefaultSnackBar @@ -98,6 +100,21 @@ class HelperDetailFragment : Fragment() { } }) + viewModel.requestIsAccepted.observe(viewLifecycleOwner, Observer { requestIsAccepted -> + if (requestIsAccepted) { + binding.buttonAccept.apply { + text = getString(R.string.helper_request_detail_button_cancel) + setTextColor(resources.getColor(android.R.color.holo_red_dark, null)) + setTypeface(null, Typeface.BOLD) + } + } else { + binding.buttonAccept.apply { + text = getString(R.string.helper_request_detail_button_accept) + setTextColor(resources.getColor(android.R.color.black, null)) + setTypeface(null, Typeface.NORMAL) + } + } + }) } diff --git a/app/src/main/java/app/nexd/android/ui/helper/requestOverview/HelperOverviewFragment.kt b/app/src/main/java/app/nexd/android/ui/helper/requestOverview/HelperOverviewFragment.kt index c11c50a..a6bfb08 100644 --- a/app/src/main/java/app/nexd/android/ui/helper/requestOverview/HelperOverviewFragment.kt +++ b/app/src/main/java/app/nexd/android/ui/helper/requestOverview/HelperOverviewFragment.kt @@ -12,7 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import app.nexd.android.R import app.nexd.android.api.model.HelpRequest import app.nexd.android.databinding.FragmentHelperRequestOverviewBinding -import app.nexd.android.ui.common.DefaultSnackbar +import app.nexd.android.ui.common.DefaultSnackBar import app.nexd.android.ui.common.HelpRequestBinder import app.nexd.android.ui.dialog.SelectTextDialog import app.nexd.android.ui.helper.requestOverview.HelperOverviewFragmentDirections.Companion.requestDetailAction @@ -83,7 +83,7 @@ class HelperOverviewFragment : Fragment() { } is Error -> { progressBar.visibility = View.GONE - DefaultSnackbar(view, progress.message, Snackbar.LENGTH_SHORT) + DefaultSnackBar(view, progress.message, Snackbar.LENGTH_SHORT) } } }) diff --git a/app/src/main/java/app/nexd/android/ui/utils/DataBindingAdapters.kt b/app/src/main/java/app/nexd/android/ui/utils/DataBindingAdapters.kt index 68fcb3c..97dcaeb 100644 --- a/app/src/main/java/app/nexd/android/ui/utils/DataBindingAdapters.kt +++ b/app/src/main/java/app/nexd/android/ui/utils/DataBindingAdapters.kt @@ -1,7 +1,5 @@ package app.nexd.android.ui.utils -import android.graphics.Typeface -import android.widget.Button import android.widget.TextView import androidx.annotation.StringRes import androidx.databinding.BindingAdapter @@ -19,15 +17,4 @@ object DataBindingAdapters { fun textViewBindText(view: TextView, @StringRes text: Int) { view.text = if (text != 0) view.context.getString(text) else null } - - @JvmStatic - @BindingAdapter("android:textStyle") - fun setTextStyle(view: Button, style: String) { - when (style) { - "bold" -> view.setTypeface(null, Typeface.BOLD) - "italic" -> view.setTypeface(null, Typeface.ITALIC) - "bold_italic" -> view.setTypeface(null, Typeface.BOLD_ITALIC) - else -> view.setTypeface(null, Typeface.NORMAL) - } - } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_helper_request_detail.xml b/app/src/main/res/layout/fragment_helper_request_detail.xml index 229731f..ce57dfc 100644 --- a/app/src/main/res/layout/fragment_helper_request_detail.xml +++ b/app/src/main/res/layout/fragment_helper_request_detail.xml @@ -128,9 +128,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/rounded_white" - 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}" - android:textStyle='@{!viewModel.requestIsAccepted? "normal" : "bold"}' android:textAllCaps="false" android:textSize="20sp" app:layout_constraintBottom_toBottomOf="parent"