diff --git a/app/src/main/java/app/nexd/android/ui/seeker/detail/SeekerDetailFragment.kt b/app/src/main/java/app/nexd/android/ui/seeker/detail/SeekerDetailFragment.kt index 7cd59c8..fbbad78 100644 --- a/app/src/main/java/app/nexd/android/ui/seeker/detail/SeekerDetailFragment.kt +++ b/app/src/main/java/app/nexd/android/ui/seeker/detail/SeekerDetailFragment.kt @@ -4,16 +4,17 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.Toast import androidx.fragment.app.Fragment 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.FragmentSeekerDetailBinding +import app.nexd.android.ui.common.DefaultSnackbar import app.nexd.android.ui.common.HelpRequestArticleBinder import app.nexd.android.ui.utils.livedata.observe -import kotlinx.android.synthetic.main.fragment_seeker_detail.* +import com.google.android.material.snackbar.Snackbar import mva2.adapter.ListSection import mva2.adapter.MultiViewAdapter import org.koin.androidx.viewmodel.ext.android.viewModel @@ -25,34 +26,52 @@ class SeekerDetailFragment : Fragment() { private val articlesAdapter = MultiViewAdapter() + private lateinit var binding: FragmentSeekerDetailBinding + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - return inflater.inflate(R.layout.fragment_seeker_detail, container, false) + binding = FragmentSeekerDetailBinding.inflate(inflater, container, false) + binding.viewModel = vm + binding.lifecycleOwner = viewLifecycleOwner + return binding.root } override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) + vm.setInfo(args.requestId) + initRecyclerView() + initVmObserver() + } - recyclerView_requests.adapter = articlesAdapter - recyclerView_requests.layoutManager = LinearLayoutManager(context) - + private fun initRecyclerView() { + binding.recyclerViewRequests.adapter = articlesAdapter + binding.recyclerViewRequests.layoutManager = LinearLayoutManager(context) articlesAdapter.registerItemBinders( HelpRequestArticleBinder() ) + } + private fun initVmObserver() { vm.progress.observe(viewLifecycleOwner) { when (it) { is SeekerDetailViewModel.Progress.Idle -> { } is SeekerDetailViewModel.Progress.Error -> { - Toast.makeText(requireContext(), getText(R.string.helper_request_detail_message_error_on_cancellation), Toast.LENGTH_LONG).show() + DefaultSnackbar( + binding.root, + R.string.helper_request_detail_message_error_on_cancellation, + Snackbar.LENGTH_SHORT + ) } is SeekerDetailViewModel.Progress.Canceled -> { - // show information - Toast.makeText(requireContext(), getText(R.string.helper_request_detail_message_cancelled), Toast.LENGTH_LONG).show() + DefaultSnackbar( + binding.root, + R.string.helper_request_detail_message_cancelled, + Snackbar.LENGTH_SHORT + ) findNavController().navigateUp() } } @@ -64,11 +83,10 @@ class SeekerDetailFragment : Fragment() { articlesList.addAll(request.articles!!) articlesAdapter.addSection(articlesList) - textView_additionalRequest_label.visibility = + binding.textViewAdditionalRequestLabel.visibility = if (request.additionalRequest.isNullOrBlank()) View.GONE else View.VISIBLE - textView_additionalRequest.text = request.additionalRequest - button_cancel.setOnClickListener { + binding.buttonCancel.setOnClickListener { vm.cancelRequest(request) } } diff --git a/app/src/main/java/app/nexd/android/ui/seeker/detail/SeekerDetailViewModel.kt b/app/src/main/java/app/nexd/android/ui/seeker/detail/SeekerDetailViewModel.kt index 7717276..914ff19 100644 --- a/app/src/main/java/app/nexd/android/ui/seeker/detail/SeekerDetailViewModel.kt +++ b/app/src/main/java/app/nexd/android/ui/seeker/detail/SeekerDetailViewModel.kt @@ -10,6 +10,7 @@ import app.nexd.android.api.model.HelpRequestCreateDto import io.reactivex.BackpressureStrategy import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable +import io.reactivex.rxkotlin.subscribeBy class SeekerDetailViewModel(private val api: Api) : ViewModel() { @@ -21,6 +22,14 @@ class SeekerDetailViewModel(private val api: Api) : ViewModel() { val progress = MutableLiveData(Progress.Idle) + val additionalRequest = MutableLiveData() + val firstName = MutableLiveData() + val lastName = MutableLiveData() + val street = MutableLiveData() + val number = MutableLiveData() + val zipCode = MutableLiveData() + val city = MutableLiveData() + private val compositeDisposable = CompositeDisposable() override fun onCleared() { @@ -56,4 +65,24 @@ class SeekerDetailViewModel(private val api: Api) : ViewModel() { } } + fun setInfo(requestId: Long) { + val observable = api.helpRequestsControllerGetSingleRequest(requestId) + + val disposable = observable + .observeOn(AndroidSchedulers.mainThread()) + .subscribeBy( + onNext = { + firstName.value = it.firstName + lastName.value = it.lastName + street.value = it.street + number.value = it.number + zipCode.value = it.zipCode + city.value = it.city + additionalRequest.value = it.additionalRequest + } + ) + + compositeDisposable.add(disposable) + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_seeker_detail.xml b/app/src/main/res/layout/fragment_seeker_detail.xml index d0edfcc..9bdb1d1 100644 --- a/app/src/main/res/layout/fragment_seeker_detail.xml +++ b/app/src/main/res/layout/fragment_seeker_detail.xml @@ -1,78 +1,134 @@ - - - - - - - + + + + + + + - - + + + + + + + android:layout_marginHorizontal="2dp" + android:layout_marginTop="28dp" + app:cardCornerRadius="@dimen/radius" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.5" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@id/button_cancel"> - + - - - + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + + \ No newline at end of file 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}"