Skip to content
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 @@ -31,18 +31,22 @@ class CheckoutFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

progressBar.visibility = View.VISIBLE

recyclerView_helpRequests.adapter = adapter
recyclerView_helpRequests.layoutManager = LinearLayoutManager(context)
adapter.registerItemBinders(
CheckoutHelpRequestBinder()
)

vm.getShoppingList().observe(viewLifecycleOwner, Observer { shoppingList ->
progressBar.visibility = View.VISIBLE
adapter.removeAllSections()

val requestList = ListSection<HelpRequest>()
requestList.addAll(shoppingList.helpRequests)
adapter.addSection(requestList)
progressBar.visibility = View.GONE
})

button_deliver.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class DeliveryFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

progressBar.visibility = View.VISIBLE

recyclerView_helpRequests.adapter = adapter
recyclerView_helpRequests.layoutManager = LinearLayoutManager(context)

Expand All @@ -40,11 +42,13 @@ class DeliveryFragment : Fragment() {
)

vm.getShoppingList().observe(viewLifecycleOwner, Observer { shoppingList ->
progressBar.visibility = View.VISIBLE
adapter.removeAllSections()

val requestList = ListSection<HelpRequest>()
requestList.addAll(shoppingList.helpRequests)
adapter.addSection(requestList)
progressBar.visibility = View.GONE

context?.let { context ->
closeRequest.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import app.nexd.android.api.model.HelpRequestArticle
import app.nexd.android.databinding.FragmentHelperRequestDetailBinding
import app.nexd.android.ui.common.HelpRequestArticleBinder
import app.nexd.android.ui.helper.detail.HelperDetailViewModel.Progress.*
import mva2.adapter.ListSection
import mva2.adapter.MultiViewAdapter
import org.koin.androidx.viewmodel.ext.android.viewModel
Expand Down Expand Up @@ -66,8 +67,23 @@ class HelperDetailFragment : Fragment() {
viewModel.idOfRequest.observe(viewLifecycleOwner, Observer { idOfRequest ->
binding.buttonAccept.setOnClickListener {
viewModel.acceptRequest(idOfRequest)
findNavController().popBackStack()
}
})

viewModel.progress.observe(viewLifecycleOwner, Observer { progress ->
when (progress) {
Loading -> {
binding.progressBar.visibility = View.VISIBLE
}
Idle -> {
binding.progressBar.visibility = View.GONE
}
Finished -> {
binding.progressBar.visibility = View.GONE
findNavController().popBackStack()
}
}

})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import io.reactivex.schedulers.Schedulers.io

class HelperDetailViewModel(private val api: Api) : ViewModel() {

sealed class Progress {
object Idle : Progress()
object Loading : Progress()
object Finished : Progress()
}

val additionalRequest = MutableLiveData<String>()
val firstName = MutableLiveData<String>()
Expand All @@ -27,6 +32,8 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() {
val buttonText = MutableLiveData<String>()
val idOfRequest = MutableLiveData<Long>()

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

private val compositeDisposable = CompositeDisposable()

fun acceptRequest(requestId: Long) {
Expand All @@ -53,6 +60,8 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() {
.subscribeOn(io())
.doOnError {
Log.e("Error", it.message.toString())
}.doOnComplete {
progress.value = Progress.Finished
}
.blockingSubscribe()
}
Expand All @@ -62,8 +71,12 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() {

val disposable = observable
.observeOn(AndroidSchedulers.mainThread())
.doOnComplete {
progress.value = Progress.Idle
}
.subscribeBy(
onNext = {

requestArticles.value = it.articles
firstName.value = it.firstName
lastName.value = it.lastName
Expand All @@ -76,7 +89,6 @@ class HelperDetailViewModel(private val api: Api) : ViewModel() {
requestIsAccepted.value = (it.helpListId != null)
}
)

compositeDisposable.add(disposable)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import app.nexd.android.R
import app.nexd.android.databinding.FragmentShoppingListBinding
import app.nexd.android.ui.helper.shoppingList.ShoppingListFragmentDirections.Companion.toCheckoutFragment
import kotlinx.android.synthetic.main.fragment_shopping_list.*
Expand Down Expand Up @@ -38,6 +37,8 @@ class ShoppingListFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

binding.progressBar.visibility = View.VISIBLE

adapter = MultiViewAdapter()
recyclerView_shoppingList.addItemDecoration(adapter.itemDecoration)
recyclerView_shoppingList.layoutManager = LinearLayoutManager(context)
Expand All @@ -50,11 +51,14 @@ class ShoppingListFragment : Fragment() {
)

viewModel.getShoppingListArticles().observe(viewLifecycleOwner, Observer { shoppingListEntries ->
binding.progressBar.visibility = View.VISIBLE
adapter.removeAllSections()
val listSection = ListSection<ShoppingListViewModel.ShoppingListEntry>()
listSection.addAll(shoppingListEntries)
adapter.addSection(listSection)

binding.progressBar.visibility = View.GONE

button_checkout.setOnClickListener {
findNavController().navigate(toCheckoutFragment())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ class PhoneCallFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
progressBar.visibility = View.VISIBLE

vm.getPhoneNumber().observe(viewLifecycleOwner, Observer { phoneNumber ->
textView_details.text = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(
getString(R.string.seeker_phone_call_text, phoneNumber),
Html.FROM_HTML_MODE_LEGACY
)

} else {
Html.fromHtml(
getString(R.string.seeker_phone_call_text, phoneNumber)
)
}
progressBar.visibility = View.GONE
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class SeekerCreateRequestConfirmAddressFragment : Fragment() {
}

binding.buttonConfirm.setOnClickListener {
binding.progressBar.visibility = View.VISIBLE
vm.sendRequest()
}
}
Expand All @@ -65,11 +66,13 @@ class SeekerCreateRequestConfirmAddressFragment : Fragment() {
//
}
is Error -> {
binding.progressBar.visibility = View.GONE
it.message?.let { errorMessageId ->
DefaultSnackbar(binding.root, errorMessageId, Snackbar.LENGTH_SHORT)
}
}
is Finished -> {
binding.progressBar.visibility = View.GONE
findNavController().navigate(SeekerCreateRequestConfirmAddressFragmentDirections.toSeekerOverviewFragment())
}
else -> Log.d(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ class SeekerCreateRequestEnterArticlesFragment : Fragment() {
articleListSection = ListSection<HelpRequestCreateArticleBinder.ArticleInput>()
articleListSection!!.addAll(articles)
adapter.addSection(articleListSection!!)
binding.progressBar.visibility = View.GONE
}

})

vm.progress.observe(viewLifecycleOwner, Observer {
when (it) {
is Idle -> {
//nothing to do
binding.progressBar.visibility = View.VISIBLE
}
is Loading -> {
findNavController().navigate(SeekerCreateRequestEnterArticlesFragmentDirections.toSeekerCreateRequestConfirmAddressFragment())
Expand All @@ -91,6 +93,7 @@ class SeekerCreateRequestEnterArticlesFragment : Fragment() {
// state not reachable
}
is Error -> {
binding.progressBar.visibility = View.GONE
it.message?.let { errorMessageId ->
DefaultSnackbar(binding.root, errorMessageId, Snackbar.LENGTH_SHORT)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ class SeekerDetailFragment : Fragment() {
HelpRequestArticleBinder()
)

progressBar.visibility = View.VISIBLE

vm.progress.observe(viewLifecycleOwner) {
when (it) {
is SeekerDetailViewModel.Progress.Idle -> {
}
is SeekerDetailViewModel.Progress.Error -> {
progressBar.visibility = View.GONE
Toast.makeText(requireContext(), getText(R.string.helper_request_detail_message_error_on_cancellation), Toast.LENGTH_LONG).show()
}
is SeekerDetailViewModel.Progress.Canceled -> {
progressBar.visibility = View.GONE
// show information
Toast.makeText(requireContext(), getText(R.string.helper_request_detail_message_cancelled), Toast.LENGTH_LONG).show()
findNavController().navigateUp()
Expand All @@ -67,8 +71,9 @@ class SeekerDetailFragment : Fragment() {
textView_additionalRequest_label.visibility =
if (request.additionalRequest.isNullOrBlank()) View.GONE else View.VISIBLE
textView_additionalRequest.text = request.additionalRequest

progressBar.visibility = View.GONE
button_cancel.setOnClickListener {
progressBar.visibility = View.VISIBLE
vm.cancelRequest(request)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ class SeekerOverviewFragment : Fragment() {
SeekerOverviewHelpRequestBinder()
)

progressBar.visibility = View.VISIBLE

vm.getHelpRequests().observe(viewLifecycleOwner, Observer { requests ->
adapter.removeAllSections()

if (requests.isEmpty()) {
progressBar.visibility = View.GONE
textView_empty.visibility = View.VISIBLE
} else {
textView_empty.visibility = View.GONE
progressBar.visibility = View.GONE
val requestsSection = ListSection<HelpRequest>()
requestsSection.addAll(requests)
adapter.addSection(requestsSection)
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/res/layout/fragment_checkout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@
android:layout_height="match_parent"
tools:background="@color/colorPrimary"
android:paddingTop="@dimen/topPadding"
android:paddingHorizontal="@dimen/horizontalPadding"

tools:context=".ui.helper.checkout.CheckoutFragment">

<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-6dp"
android:layout_marginBottom="-8dp"
android:indeterminate="true"
android:indeterminateTint="@color/colorPrimaryDark"
android:max="100"
android:padding="0dp"
android:visibility="gone" />

<TextView
android:id="@+id/textView_title"
android:text="@string/checkout_screen_title"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp"
android:layout_marginHorizontal="15dp"
android:textSize="@dimen/textSize_screen_title"
android:textColor="@android:color/white"
android:textStyle="bold"
Expand All @@ -23,7 +37,8 @@
<ScrollView
android:layout_below="@id/textView_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
android:layout_height="wrap_content"
android:layout_marginHorizontal="15dp">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView_helpRequests"
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/res/layout/fragment_delivery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="@dimen/horizontalPadding"
android:paddingTop="@dimen/topPadding"
tools:background="@color/colorPrimary"
tools:context=".ui.helper.delivery.DeliveryFragment">

<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-6dp"
android:layout_marginBottom="-8dp"
android:indeterminate="true"
android:indeterminateTint="@color/colorPrimaryDark"
android:max="100"
android:padding="0dp"
android:visibility="gone" />

<TextView
android:id="@+id/textView_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginHorizontal="15dp"
android:text="@string/delivery_screen_title"
android:textColor="@android:color/white"
android:textSize="@dimen/textSize_screen_title"
Expand All @@ -31,6 +44,7 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="15dp"
android:layout_below="@id/textView_title">

<androidx.recyclerview.widget.RecyclerView
Expand Down
Loading