diff --git a/app/src/main/java/io/givenow/app/activities/MainActivity.java b/app/src/main/java/io/givenow/app/activities/MainActivity.java index dab1463..ca10a31 100644 --- a/app/src/main/java/io/givenow/app/activities/MainActivity.java +++ b/app/src/main/java/io/givenow/app/activities/MainActivity.java @@ -50,6 +50,7 @@ import io.givenow.app.fragments.main.profile.ProfileFragment; import io.givenow.app.fragments.main.volunteer.PickupRequestDetailFragment; import io.givenow.app.fragments.main.volunteer.PickupRequestsFragment; +import io.givenow.app.helpers.Analytics; import io.givenow.app.helpers.ErrorDialogs; import io.givenow.app.models.ParseUserHelper; import io.givenow.app.models.PickupRequest; @@ -209,8 +210,6 @@ private void createAcceptPendingVolunteerDialog(final PickupRequest pickupReques acceptPendingDialog.dismiss(); } acceptPendingDialog = new AlertDialog.Builder(this) -// .setTitle(R.string.acceptRequest_submittedDialog_title) -// .setMessage(R.string.acceptRequest_submittedDialog_msg) .setTitle(Html.fromHtml(title)) //TODO: include in message?: + pickupRequest.getDonationCategories().toString() + .setMessage(Html.fromHtml(getString(R.string.dialog_accept_pending_volunteer) + address)) .setPositiveButton(getString(R.string.yes), (dialog, which) -> pendingVolunteerConfirmed(pickupRequest)) @@ -221,24 +220,8 @@ private void createAcceptPendingVolunteerDialog(final PickupRequest pickupReques error -> ErrorDialogs.connectionFailure(this, error))); } - private void cancelPendingVolunteer(PickupRequest pickupRequest) { - mTracker.send(new HitBuilders.EventBuilder() - .setCategory("RequestPickup") - .setAction("PendingVolunteerCanceled") - .setLabel(ParseUser.getCurrentUser().getObjectId()) - .build()); - - //donor doesn't accept volunteer request, so remove the pending volunteer - pickupRequest.remove("pendingVolunteer"); - pickupRequest.saveInBackground(); - } - private void pendingVolunteerConfirmed(final PickupRequest pickupRequest) { - mTracker.send(new HitBuilders.EventBuilder() - .setCategory("RequestPickup") - .setAction("PendingVolunteerConfirmed") - .setLabel(ParseUser.getCurrentUser().getObjectId()) - .build()); + Analytics.sendHit(mTracker, "RequestPickup", "PendingVolunteerConfirmed", ParseUser.getCurrentUser().getObjectId()); pickupRequest.confirmVolunteer().subscribe( response -> Log.d("Cloud Response", response.toString()), @@ -246,15 +229,10 @@ private void pendingVolunteerConfirmed(final PickupRequest pickupRequest) { ); } - //stupid helper method, can go away whenever - private String getId(ParseUser volunteer) { - String id = null; - - if (volunteer != null) { - id = volunteer.getObjectId(); - } - - return id; + private void cancelPendingVolunteer(PickupRequest pickupRequest) { + //donor doesn't accept volunteer request, so remove the pending volunteer + Analytics.sendHit(mTracker, "RequestPickup", "PendingVolunteerCanceled", ParseUser.getCurrentUser().getObjectId()); + pickupRequest.cancelPendingVolunteer(); } private void initializeDrawer() { diff --git a/app/src/main/java/io/givenow/app/adapters/DashboardItemAdapter.java b/app/src/main/java/io/givenow/app/adapters/DashboardItemAdapter.java index 8e8a839..adfc988 100644 --- a/app/src/main/java/io/givenow/app/adapters/DashboardItemAdapter.java +++ b/app/src/main/java/io/givenow/app/adapters/DashboardItemAdapter.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.net.Uri; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; import android.text.Html; import android.util.Log; @@ -29,9 +30,10 @@ import io.givenow.app.helpers.ErrorDialogs; import io.givenow.app.models.ParseUserHelper; import io.givenow.app.models.PickupRequest; -import rx.android.schedulers.AndroidSchedulers; import rx.parse.ParseObservable; +import static rx.android.schedulers.AndroidSchedulers.mainThread; + public class DashboardItemAdapter extends RecyclerView.Adapter { ArrayList mItems = new ArrayList<>(); @@ -77,6 +79,37 @@ public void onBindViewHolder(ViewHolder vh, int position) { setupCardActionButtons(vh, pickupRequest); } }); + + PopupMenu popup = new PopupMenu(mContext, vh.btnMenu); + popup.inflate(R.menu.dashboard_card_waiting); + popup.setOnMenuItemClickListener(item -> { + switch (item.getItemId()) { + case R.id.action_cancel: + cancelItem(position); + return true; + default: + return true; + } + }); + vh.btnMenu.setOnClickListener(btn -> popup.show()); + } + + private void cancelItem(int position) { + final PickupRequest pickupRequest = mItems.get(position); + new AlertDialog.Builder(mContext) + .setTitle(R.string.dialog_dashboard_cancel_pickup_title) + .setMessage(R.string.dialog_dashboard_cancel_pickup_message) + .setPositiveButton(R.string.dialog_dashboard_cancel_positiveButton, (dialog, which) -> { + pickupRequest.cancelPendingVolunteer(); + ParseObservable.save(pickupRequest).observeOn(mainThread()).subscribe( + pr -> { + Log.d(getClass().getSimpleName(), "Removing pickupRequest " + pr.getObjectId() + " from dashboard"); + remove(position); + }, + error -> ErrorDialogs.connectionFailure(mContext, error)); + }) + .setNegativeButton(R.string.dialog_dashboard_cancel_negativeButton, null) + .show(); } private void setupStaticMap(ViewHolder vh, final PickupRequest pickupRequest) { @@ -106,7 +139,7 @@ private void setupStaticMap(ViewHolder vh, final PickupRequest pickupRequest) { private void setupCardActionButtons(ViewHolder vh, final PickupRequest pickupRequest) { ParseObservable.fetchIfNeeded(pickupRequest.getDonor()) - .observeOn(AndroidSchedulers.mainThread()).subscribe( + .observeOn(mainThread()).subscribe( donor -> { vh.btnCall.setOnClickListener(v -> { Intent callIntent = new Intent(Intent.ACTION_CALL); diff --git a/app/src/main/java/io/givenow/app/models/PickupRequest.java b/app/src/main/java/io/givenow/app/models/PickupRequest.java index c70cda5..7931efb 100644 --- a/app/src/main/java/io/givenow/app/models/PickupRequest.java +++ b/app/src/main/java/io/givenow/app/models/PickupRequest.java @@ -176,7 +176,9 @@ public static ParseQuery queryPickupRequestForDonation(Donation d return q; } - /** Properties **/ + /** + * Properties + **/ public ParseGeoPoint getLocation() { return getParseGeoPoint("location"); @@ -227,6 +229,10 @@ public void setPendingVolunteer(ParseUser value) { put("pendingVolunteer", value); } + public void cancelPendingVolunteer() { + remove("pendingVolunteer"); + } + @NonNull public Option getConfirmedVolunteer() { return Option.fromNull(getParseUser("confirmedVolunteer")); @@ -292,7 +298,9 @@ public LatLng getPosition() { return new LatLng(loc.getLatitude(), loc.getLongitude()); } - /** Push notifications **/ + /** + * Push notifications + **/ private void generatePushNotif(ParseUser target_user, String title, String message, String type) { ParseQuery pushQuery = ParseInstallation.getQuery(); @@ -362,8 +370,12 @@ public void reportProblem(Context context) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } PickupRequest that = (PickupRequest) o; diff --git a/app/src/main/res/menu/dashboard_card_waiting.xml b/app/src/main/res/menu/dashboard_card_waiting.xml new file mode 100644 index 0000000..d2d12d9 --- /dev/null +++ b/app/src/main/res/menu/dashboard_card_waiting.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e81fcef..331ad8a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -147,5 +147,10 @@ This will notify the donor and remove it from your Dashboard. Yes, I picked it up @string/no + Cancel + Cancel this pickup? + This will notify the donor that you\'re no longer picking up their donation, and remove this pickup from your dashboard. + Yes, cancel it + No, keep it