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

display helper overview as single recycler view #123

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
@@ -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<HelperOverviewFragment.Header, HelpRequestAvailableHeaderBinder.ViewHolder>() {

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<HelperOverviewFragment.Header?>(itemView) {
val header: TextView = itemView.findViewById(R.id.textView_header)
val button: ImageButton = itemView.findViewById(R.id.button_nearRequests)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@ 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() {

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?,
Expand All @@ -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()
)

Expand Down Expand Up @@ -89,41 +85,49 @@ class HelperOverviewFragment : Fragment() {
})

vm.myAcceptedRequests.observe(viewLifecycleOwner, Observer { acceptedRequests ->
acceptedRequestsAdapter.removeAllSections()

val acceptedRequestsList = ListSection<HelpRequest>()

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<HelpRequest>()
val nearRequestList = ListSection<HelpRequest>()

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<HelpRequest>()
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 {
findNavController().navigate(HelperOverviewFragmentDirections.toShoppingListFragment())
}
}

class Header(val header: String)

}
47 changes: 7 additions & 40 deletions app/src/main/res/layout/fragment_helper_request_overview.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layout>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand All @@ -8,8 +9,7 @@
type="app.nexd.android.ui.helper.requestOverview.HelperOverviewViewModel" />
</data>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down Expand Up @@ -56,50 +56,17 @@
android:textSize="@dimen/textSize_button"
android:textStyle="bold" />

<TextView
android:id="@+id/textView_acceptedLists"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/helper_request_overview_heading_accepted_section"
android:textColor="@android:color/white"
android:textSize="@dimen/textSize_screen_title"
android:textStyle="bold" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView_acceptedRequests"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
tools:listitem="@layout/row_call" />

<Button
android:id="@+id/button_nearRequests"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="@drawable/ic_edit_black_24dp"
android:drawableTint="@android:color/white"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:text="@string/helper_request_overview_heading_available_section"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textSize="@dimen/textSize_screen_title"
android:textStyle="bold"
android:onClick="@{() -> viewModel.editZipCode()}"/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView_nearRequests"
android:id="@+id/recyclerView_allRequests"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:layout_weight="3"
android:orientation="vertical"
tools:listitem="@layout/row_call" />
tools:listitem="@layout/row_call">

</androidx.recyclerview.widget.RecyclerView>

</LinearLayout>
</RelativeLayout>
Expand Down
66 changes: 66 additions & 0 deletions app/src/main/res/layout/row_help_request_header.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<layout>

<data>

<variable
name="viewModel"
type="app.nexd.android.ui.helper.requestOverview.HelperOverviewViewModel" />
</data>

<androidx.cardview.widget.CardView 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="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:cardCornerRadius="0dp"
app:cardElevation="0dp"
tools:layout_margin="8dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="horizontal"
android:padding="8dp">

<TextView
android:id="@+id/textView_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:paddingStart="0dp"
android:paddingTop="8dp"
android:paddingEnd="0dp"
android:paddingBottom="8dp"
android:textAlignment="textStart"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textSize="@dimen/textSize_screen_title"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Header" />

<ImageButton
android:id="@+id/button_nearRequests"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:onClick="@{() -> viewModel.editZipCode()}"
android:src="@drawable/ic_edit_black_24dp"
android:tint="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />


</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>
</layout>