Skip to content

Commit

Permalink
Merge pull request #2883 from dimagi/jp/issue-delivery-progress-sync
Browse files Browse the repository at this point in the history
Issue Delivery Progress Sync Button
  • Loading branch information
OrangeAndGreen authored Oct 23, 2024
2 parents aa656e4 + dd93821 commit 1c79590
Showing 1 changed file with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.commcare.fragments.connect;

import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;
Expand Down Expand Up @@ -76,6 +74,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
if (parentFragment != null) {
parentFragment.refreshData();
}
setDeliveriesData();
});

RoundedButton reviewButton = view.findViewById(R.id.connect_progress_review_button);
Expand All @@ -85,9 +84,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
});

updateView();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
updateView12();
}
setDeliveriesData();
return view;
}

Expand Down Expand Up @@ -228,9 +225,7 @@ public void updateView() {
textView.setTextColor(getResources().getColor(color));
}


@RequiresApi(api = Build.VERSION_CODES.N)
public void updateView12() {
public void setDeliveriesData() {
ConnectDeliveryDetails connectDeliveryDetails = null;
ConnectJobRecord job = ConnectManager.getActiveJob();
if (job != null) {
Expand Down Expand Up @@ -258,7 +253,7 @@ public void updateView12() {
HashMap<String, Integer> typeCounts = paymentTypeAndStatusCounts.get(deliverySlug);
String status = delivery.getStatus();

int count = typeCounts.getOrDefault(status, 0);
int count = typeCounts.containsKey(status) ? typeCounts.get(status) : 0;
typeCounts.put(status, count + 1);
}

Expand All @@ -269,11 +264,11 @@ public void updateView12() {
}

String unitIdKey = Integer.toString(unit.getUnitId());
HashMap<String, Integer> statusCounts = paymentTypeAndStatusCounts.getOrDefault(unitIdKey, new HashMap<>());
HashMap<String, Integer> statusCounts = paymentTypeAndStatusCounts.containsKey(unitIdKey) ? paymentTypeAndStatusCounts.get(unitIdKey) : new HashMap<>();

// Get pending and approved counts
totalPending = statusCounts.getOrDefault("pending", 0);
totalApproved = statusCounts.getOrDefault("approved", 0);
totalPending = statusCounts.containsKey("pending") ? statusCounts.get("pending") : 0;
totalApproved = statusCounts.containsKey("approved") ? statusCounts.get("approved") : 0;

// Calculate the total amount for this delivery (numApproved * unit amount)
totalAmount = job.getMoneyString(totalApproved * unit.getAmount());
Expand Down Expand Up @@ -305,7 +300,6 @@ public void updateView12() {
}
}


private long calculateDaysPending(ConnectJobDeliveryRecord delivery) {
Date dueDate = delivery.getDate();
if (dueDate == null) {
Expand Down

0 comments on commit 1c79590

Please sign in to comment.