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

show target address in SeekerDetailRequest #135

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -21,6 +22,14 @@ class SeekerDetailViewModel(private val api: Api) : ViewModel() {

val progress = MutableLiveData<Progress>(Progress.Idle)

val additionalRequest = MutableLiveData<String>()
val firstName = MutableLiveData<String>()
val lastName = MutableLiveData<String>()
val street = MutableLiveData<String>()
val number = MutableLiveData<String>()
val zipCode = MutableLiveData<String>()
val city = MutableLiveData<String>()

private val compositeDisposable = CompositeDisposable()

override fun onCleared() {
Expand Down Expand Up @@ -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)
}

}
194 changes: 125 additions & 69 deletions app/src/main/res/layout/fragment_seeker_detail.xml
Original file line number Diff line number Diff line change
@@ -1,78 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/horizontalPadding"
tools:background="@color/colorPrimary">

<TextView
android:id="@+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/seeker_detail_screen_title"
android:textColor="@android:color/white"
android:textSize="@dimen/textSize_screen_title"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/button_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_delete_black_24dp"
android:tint="@color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/textView_title" />

<androidx.cardview.widget.CardView
android:id="@+id/cardView"
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="viewModel"
type="app.nexd.android.ui.seeker.detail.SeekerDetailViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView_requests"
android:layout_height="match_parent"
android:padding="@dimen/horizontalPadding"
tools:background="@color/colorPrimary">

<TextView
android:id="@+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/seeker_detail_screen_title"
android:textColor="@android:color/white"
android:textSize="@dimen/textSize_screen_title"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/button_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_delete_black_24dp"
android:tint="@color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/textView_title" />

<androidx.cardview.widget.CardView
android:id="@+id/cardView_request"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
tools:listitem="@layout/row_help_request_article" />
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">

</androidx.cardview.widget.CardView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView_requests"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
tools:listitem="@layout/row_help_request_article" />

<TextView
android:id="@+id/textView_additionalRequest_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/seeker_detail_placeholder_information"
android:textColor="@android:color/white"
android:textColorHint="@android:color/white"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@id/textView_additionalRequest" />

<TextView
android:id="@+id/textView_additionalRequest"
android:paddingHorizontal="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:backgroundTint="@color/text"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="As fast as possible!!" />
</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:id="@+id/cardView_target_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:cardCornerRadius="@dimen/radius"
app:layout_constraintBottom_toTopOf="@id/textView_additionalRequest_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cardView_request"
app:layout_constraintVertical_bias="0.0">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">

<TextView
android:id="@+id/textView_delivery_address_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/helper_request_detail_delivery_address_header"
android:textColor="@color/colorPrimaryDark"
android:textSize="20sp" />

<ScrollView
android:id="@+id/scrollView_additional_request"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/textView_delivery_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{viewModel.firstName + ' ' + viewModel.lastName + '\n' + viewModel.street + ' ' + viewModel.number + '\n' + viewModel.zipCode + ' ' + viewModel.city}"
android:textColor="@android:color/black"
android:textSize="16sp"
tools:text="Max\nMusterstr. 15\n12345 Musterstadt" />

</ScrollView>
</LinearLayout>
</androidx.cardview.widget.CardView>

<TextView
android:id="@+id/textView_additionalRequest_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/seeker_detail_placeholder_information"
android:textColor="@android:color/white"
android:textColorHint="@android:color/white"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@id/textView_additionalRequest" />

<TextView
android:id="@+id/textView_additionalRequest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:backgroundTint="@color/text"
android:paddingHorizontal="10dp"
android:text="@{viewModel.additionalRequest}"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="As fast as possible!!" />


</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
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