diff --git a/app/src/main/java/app/nexd/android/ui/common/HelpRequestAvailableHeaderBinder.kt b/app/src/main/java/app/nexd/android/ui/common/HelpRequestAvailableHeaderBinder.kt new file mode 100644 index 0000000..ac6605b --- /dev/null +++ b/app/src/main/java/app/nexd/android/ui/common/HelpRequestAvailableHeaderBinder.kt @@ -0,0 +1,40 @@ +package app.nexd.android.ui.common + +import android.view.View +import android.view.ViewGroup +import android.widget.ImageButton +import android.widget.TextView +import app.nexd.android.R +import app.nexd.android.ui.helper.requestOverview.HelperOverviewFragment +import mva2.adapter.ItemBinder +import mva2.adapter.ItemViewHolder + +class HelpRequestAvailableHeaderBinder(private val clickListener: () -> Unit) : + ItemBinder() { + + override fun bindViewHolder( + holder: ViewHolder?, + item: HelperOverviewFragment.Header? + ) { + holder!!.header.text = item!!.header + if (item.header == holder.header.context.getString(R.string.helper_request_overview_heading_accepted_section)) { + holder.button.visibility = View.GONE + } else { + holder.button.setOnClickListener { clickListener() } + } + } + + override fun createViewHolder(parent: ViewGroup?): ViewHolder { + return ViewHolder(inflate(parent!!, R.layout.row_help_request_header)) + } + + override fun canBindData(item: Any?): Boolean { + return item is HelperOverviewFragment.Header + } + + class ViewHolder(itemView: View) : + ItemViewHolder(itemView) { + val header: TextView = itemView.findViewById(R.id.textView_header) + val button: ImageButton = itemView.findViewById(R.id.button_nearRequests) + } +} \ No newline at end of file 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..3fd4053 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 @@ -13,14 +13,17 @@ 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.HelpRequestAvailableHeaderBinder import app.nexd.android.ui.common.HelpRequestBinder import app.nexd.android.ui.dialog.SelectTextDialog import app.nexd.android.ui.helper.requestOverview.HelperOverviewFragmentDirections.Companion.requestDetailAction import app.nexd.android.ui.helper.requestOverview.HelperOverviewViewModel.Progress.* import com.google.android.material.snackbar.Snackbar import kotlinx.android.synthetic.main.fragment_helper_request_overview.* +import mva2.adapter.HeaderSection import mva2.adapter.ListSection import mva2.adapter.MultiViewAdapter +import mva2.adapter.util.Mode import org.koin.androidx.viewmodel.ext.android.viewModel class HelperOverviewFragment : Fragment() { @@ -28,8 +31,7 @@ class HelperOverviewFragment : Fragment() { private val vm: HelperOverviewViewModel by viewModel() private lateinit var binding: FragmentHelperRequestOverviewBinding - private val nearRequestsAdapter = MultiViewAdapter() - private val acceptedRequestsAdapter = MultiViewAdapter() + private val allRequestsAdapter = MultiViewAdapter() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -43,16 +45,10 @@ class HelperOverviewFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - - recyclerView_acceptedRequests.layoutManager = LinearLayoutManager(context) - recyclerView_acceptedRequests.adapter = acceptedRequestsAdapter - acceptedRequestsAdapter.registerItemBinders( - HelpRequestBinder() - ) - - recyclerView_nearRequests.layoutManager = LinearLayoutManager(context) - recyclerView_nearRequests.adapter = nearRequestsAdapter - nearRequestsAdapter.registerItemBinders( + recyclerView_allRequests.layoutManager = LinearLayoutManager(context) + recyclerView_allRequests.adapter = allRequestsAdapter + allRequestsAdapter.registerItemBinders( + HelpRequestAvailableHeaderBinder { vm.editZipCode() }, HelpRequestBinder() ) @@ -89,36 +85,42 @@ class HelperOverviewFragment : Fragment() { }) vm.myAcceptedRequests.observe(viewLifecycleOwner, Observer { acceptedRequests -> - acceptedRequestsAdapter.removeAllSections() - - val acceptedRequestsList = ListSection() - - acceptedRequestsList.addAll(acceptedRequests) - acceptedRequestsList.setOnSelectionChangedListener { request: HelpRequest, - b: Boolean, _ -> - if (b) { - request.id?.let { - findNavController().navigate(requestDetailAction(it)) + vm.openRequests.observe(viewLifecycleOwner, Observer { openRequests -> + allRequestsAdapter.removeAllSections() + allRequestsAdapter.setExpansionMode(Mode.MULTIPLE) + val acceptedRequestsListHeaderSection = + HeaderSection(Header(requireContext().getString(R.string.helper_request_overview_heading_accepted_section))) + val nearRequestListHeaderSection = + HeaderSection(Header(requireContext().getString(R.string.helper_request_overview_heading_available_section))) + + val acceptedRequestsList = ListSection() + val nearRequestList = ListSection() + + acceptedRequestsListHeaderSection.addSection(acceptedRequestsList) + nearRequestListHeaderSection.addSection(nearRequestList) + + acceptedRequestsList.addAll(acceptedRequests) + acceptedRequestsList.setOnSelectionChangedListener { request: HelpRequest, + b: Boolean, _ -> + if (b) { + request.id?.let { + findNavController().navigate(requestDetailAction(it)) + } } } - } - acceptedRequestsAdapter.addSection(acceptedRequestsList) - }) - - vm.openRequests.observe(viewLifecycleOwner, Observer { requests -> - nearRequestsAdapter.removeAllSections() - - val nearRequestList = ListSection() - nearRequestList.addAll(requests) - nearRequestList.setOnSelectionChangedListener { helpRequest: HelpRequest, - b: Boolean, _ -> - if (b) { - helpRequest.id?.let { - findNavController().navigate(requestDetailAction(it)) + allRequestsAdapter.addSection(acceptedRequestsListHeaderSection) + + nearRequestList.addAll(openRequests) + nearRequestList.setOnSelectionChangedListener { helpRequest: HelpRequest, + b: Boolean, _ -> + if (b) { + helpRequest.id?.let { + findNavController().navigate(requestDetailAction(it)) + } } } - } - nearRequestsAdapter.addSection(nearRequestList) + allRequestsAdapter.addSection(nearRequestListHeaderSection) + }) }) button_shopping.setOnClickListener { @@ -126,4 +128,6 @@ class HelperOverviewFragment : Fragment() { } } + class Header(val header: String) + } diff --git a/app/src/main/res/layout/fragment_helper_request_overview.xml b/app/src/main/res/layout/fragment_helper_request_overview.xml index 50dc80e..f0a7435 100644 --- a/app/src/main/res/layout/fragment_helper_request_overview.xml +++ b/app/src/main/res/layout/fragment_helper_request_overview.xml @@ -1,5 +1,6 @@ - + @@ -8,8 +9,7 @@ type="app.nexd.android.ui.helper.requestOverview.HelperOverviewViewModel" /> - @@ -56,50 +56,17 @@ android:textSize="@dimen/textSize_button" android:textStyle="bold" /> - - - -