Skip to content
Merged
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
162 changes: 162 additions & 0 deletions app/res/layout/connect_delivery_progress_item.xml
Comment thread
conroy-ricketts marked this conversation as resolved.
Comment thread
conroy-ricketts marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/connect_space_md"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="?attr/colorSurface"
app:cardCornerRadius="@dimen/connect_radius_lg"
app:cardElevation="10dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/connect_space_lg">

<TextView
android:id="@+id/tvDeliveryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/connectOnSurfaceEmphasis"
android:textSize="@dimen/connect_text_body"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Household visit" />

<ImageView
android:id="@+id/imgApproved"
android:layout_width="13dp"
android:layout_height="13dp"
android:layout_marginStart="@dimen/connect_space_xs"
android:layout_marginTop="@dimen/connect_space_sm"
android:contentDescription="@null"
android:src="@drawable/ic_connect_thumb_up"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDeliveryTitle" />

<LinearLayout
android:id="@+id/approvedStats"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/connect_space_sm"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="@id/centerGuideline"
app:layout_constraintStart_toEndOf="@id/imgApproved"
app:layout_constraintTop_toTopOf="@id/imgApproved">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/connect_results_summary_approved"
android:textColor="?attr/connectOnSurfaceMuted"
android:textSize="@dimen/connect_text_caption"
android:textStyle="bold" />

<TextView
android:id="@+id/tvApproved"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/connect_space_xs"
android:textColor="?attr/connectStatusPositive"
android:textSize="@dimen/connect_text_caption"
android:textStyle="bold"
tools:text="10" />

<TextView
android:id="@+id/tvDeliveryTotalAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/connect_space_xs"
android:textColor="?attr/connectStatusPositive"
android:textSize="@dimen/connect_text_caption"
android:textStyle="bold"
tools:text="10,000 MWK" />
</LinearLayout>

<ImageView
android:id="@+id/imgRemaining"
android:layout_width="13dp"
android:layout_height="13dp"
android:layout_marginStart="@dimen/connect_space_xs"
android:contentDescription="@null"
android:src="@drawable/ic_connect_delivery_check_circle"
app:layout_constraintStart_toStartOf="@id/centerGuideline"
app:layout_constraintTop_toTopOf="@id/imgApproved" />

<LinearLayout
android:id="@+id/remainingStats"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/connect_space_sm"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/imgRemaining"
app:layout_constraintTop_toTopOf="@id/imgRemaining">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/connect_results_summary_remaining"
android:textColor="?attr/connectOnSurfaceMuted"
android:textSize="@dimen/connect_text_caption"
android:textStyle="bold" />

<TextView
android:id="@+id/tvRemaining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/connect_space_xs"
android:textColor="?attr/colorPrimary"
android:textSize="@dimen/connect_text_caption"
android:textStyle="bold"
tools:text="6 in 3 days" />
</LinearLayout>

<androidx.constraintlayout.widget.Barrier
android:id="@+id/statsBottomBarrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="approvedStats, remainingStats" />

<org.commcare.views.connect.LinearProgressBar
android:id="@+id/linearProgressBar"
android:layout_width="0dp"
android:layout_height="@dimen/connect_progress_card_bar_height"
android:layout_marginTop="@dimen/connect_space_sm"
app:layout_constraintEnd_toStartOf="@id/progressEndGuideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/statsBottomBarrier" />

<ImageView
android:id="@+id/imgArrowForward"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginEnd="@dimen/connect_space_sm"
android:contentDescription="@null"
android:src="@drawable/ic_connect_arrow_forward"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/linearProgressBar" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/centerGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/progressEndGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.75" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
9 changes: 7 additions & 2 deletions app/res/layout/fragment_connect_delivery_visits.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rvPaymentUnits"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/connect_background_color" />
android:background="@color/connect_background_color"
android:clipToPadding="false"
android:paddingVertical="6dp"
tools:listitem="@layout/connect_delivery_progress_item" />
3 changes: 3 additions & 0 deletions app/res/navigation/nav_graph_connect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
<action
android:id="@+id/action_connect_delivery_home_fragment_to_connect_job_detail_bottom_sheet_dialog_fragment"
app:destination="@id/connect_job_detail_bottom_sheet_dialog_fragment" />
<action
android:id="@+id/action_connect_delivery_home_fragment_to_connect_delivery_visits_detail_fragment"
app:destination="@id/connect_delivery_visits_detail_fragment" />
</fragment>

<fragment
Expand Down
90 changes: 90 additions & 0 deletions app/src/org/commcare/adapters/ConnectDeliveryPaymentUnitAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.commcare.adapters

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.color.MaterialColors
import org.commcare.dalvik.R
import org.commcare.dalvik.databinding.ConnectDeliveryProgressItemBinding
import org.commcare.models.connect.ConnectDeliveryDetails

class ConnectDeliveryPaymentUnitAdapter(
private val onPaymentUnitClicked: (ConnectDeliveryDetails) -> Unit,
) : RecyclerView.Adapter<ConnectDeliveryPaymentUnitAdapter.PaymentUnitViewHolder>() {
private val paymentUnits = mutableListOf<ConnectDeliveryDetails>()

class PaymentUnitViewHolder(
val binding: ConnectDeliveryProgressItemBinding,
) : RecyclerView.ViewHolder(binding.root)

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int,
): PaymentUnitViewHolder {
val binding =
ConnectDeliveryProgressItemBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false,
)
return PaymentUnitViewHolder(binding)
}

override fun onBindViewHolder(
holder: PaymentUnitViewHolder,
position: Int,
) {
val details = paymentUnits[position]
val context = holder.itemView.context
with(holder.binding) {
linearProgressBar.setProgress(details.approvedPercentage.toFloat())
linearProgressBar.setProgressColor(
MaterialColors.getColor(holder.itemView, R.attr.connectStatusPositive),
)
tvDeliveryTitle.text = details.deliveryName
tvApproved.text = details.approvedCount.toString()
tvDeliveryTotalAmount.text = details.totalAmount
tvRemaining.text = remainingText(context, details)
rootView.setOnClickListener { onPaymentUnitClicked(details) }
}
}

private fun remainingText(
context: Context,
details: ConnectDeliveryDetails,
): String {
if (details.pendingCount <= 0) {
return context.getString(R.string.connect_results_summary_visits_done)
}
return when (details.remainingDays) {
0 -> {
context.getString(R.string.connect_results_summary_days_over)
}

1 -> {
context.getString(R.string.connect_results_summary_remaining_today, details.pendingCount)
}

2 -> {
context.getString(R.string.connect_results_summary_remaining_tomorrow, details.pendingCount)
}

else -> {
context.getString(
R.string.connect_results_summary_remaining_days,
details.pendingCount,
details.remainingDays,
)
}
}
}

override fun getItemCount(): Int = paymentUnits.size

fun updateData(newData: List<ConnectDeliveryDetails>) {
paymentUnits.clear()
paymentUnits.addAll(newData)
notifyDataSetChanged()
Comment thread
conroy-ricketts marked this conversation as resolved.
}
}
Comment thread
conroy-ricketts marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.commcare.android.database.connect.models.ConnectJobDeliveryFlagRecord;
import org.commcare.android.database.connect.models.ConnectJobDeliveryRecord;
import org.commcare.android.database.connect.models.ConnectJobRecord;
import org.commcare.android.database.connect.models.ConnectPaymentUnitRecord;
import org.commcare.connect.ConnectDateUtils;
import org.commcare.connect.repository.ConnectRepository;
import org.commcare.connect.viewmodel.ConnectDeliveryHomeViewModel;
Expand All @@ -53,7 +54,7 @@ public class ConnectDeliveryVisitsDetailFragment extends ConnectJobFragment<Frag
};

private String currentFilter = ALL_IDENTIFIER;
private String unitName;
private String unitUuid;
private DeliveryAdapter adapter;
private ConnectDeliveryHomeViewModel viewModel;

Expand All @@ -65,10 +66,11 @@ public static ConnectDeliveryVisitsDetailFragment newInstance() {
public @NotNull View onCreateView(@NotNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
if (getArguments() != null) {
unitName = ConnectDeliveryVisitsDetailFragmentArgs.fromBundle(getArguments()).getUnitId();
unitUuid = ConnectDeliveryVisitsDetailFragmentArgs.fromBundle(getArguments()).getUnitId();
}
if (unitName != null) {
((CommonBaseActivity)requireActivity()).setActionBarTitle(getString(R.string.connect_visit_type_title, unitName));
if (unitUuid != null) {
((CommonBaseActivity)requireActivity()).setActionBarTitle(
getString(R.string.connect_visit_type_title, getUnitName()));
setupMenuProvider();
}
viewModel = new ViewModelProvider(
Expand All @@ -81,6 +83,15 @@ public static ConnectDeliveryVisitsDetailFragment newInstance() {
return view;
}

private String getUnitName() {
for (ConnectPaymentUnitRecord unit : job.getPaymentUnits()) {
if (unit.getUnitUUID().equals(unitUuid)) {
return unit.getName();
}
}
return "";
}

private void setupRecyclerView() {
getBinding().deliveryList.setLayoutManager(new LinearLayoutManager(getContext()));
adapter = new DeliveryAdapter(getContext(), getFilteredDeliveries());
Expand Down Expand Up @@ -203,7 +214,7 @@ private List<ConnectJobDeliveryRecord> getFilteredDeliveries() {
}

private boolean matchesFilter(ConnectJobDeliveryRecord delivery, String filter) {
boolean matchesUnit = unitName == null || delivery.getUnitName().equalsIgnoreCase(unitName);
boolean matchesUnit = unitUuid == null || unitUuid.equals(delivery.getSlugUUID());
boolean matchesStatus = filter.equals(ALL_IDENTIFIER) || delivery.getStatus().equalsIgnoreCase(filter);
return matchesUnit && matchesStatus;
}
Expand Down
Loading
Loading