Skip to content

Commit

Permalink
Implement dashboard card menu for "waiting for donor" card, with a Ca…
Browse files Browse the repository at this point in the history
…ncel option that cancels the pending volunteer. #20
  • Loading branch information
aphexcx committed Feb 3, 2016
1 parent c43119a commit 8ef4496
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 34 deletions.
34 changes: 6 additions & 28 deletions app/src/main/java/io/givenow/app/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand All @@ -221,40 +220,19 @@ 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()),
error -> ErrorDialogs.connectionFailure(this, error) //TODO: maybe implement Retry dialog here?
);
}

//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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<DashboardItemAdapter.ViewHolder> {
ArrayList<PickupRequest> mItems = new ArrayList<>();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 16 additions & 4 deletions app/src/main/java/io/givenow/app/models/PickupRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ public static ParseQuery<PickupRequest> queryPickupRequestForDonation(Donation d
return q;
}

/** Properties **/
/**
* Properties
**/

public ParseGeoPoint getLocation() {
return getParseGeoPoint("location");
Expand Down Expand Up @@ -227,6 +229,10 @@ public void setPendingVolunteer(ParseUser value) {
put("pendingVolunteer", value);
}

public void cancelPendingVolunteer() {
remove("pendingVolunteer");
}

@NonNull
public Option<ParseUser> getConfirmedVolunteer() {
return Option.fromNull(getParseUser("confirmedVolunteer"));
Expand Down Expand Up @@ -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<ParseInstallation> pushQuery = ParseInstallation.getQuery();
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/menu/dashboard_card_waiting.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_cancel"
android:icon="@drawable/ic_clear_white_24dp"
android:showAsAction="always"
android:title="@string/action_dashboard_item_cancel"/>
</menu>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,10 @@
<string name="dialog_pickup_pickupRequest_message">This will notify the donor and remove it from your Dashboard.</string>
<string name="dialog_pickup_pickupRequest_positiveButton">Yes, I picked it up</string>
<string name="dialog_pickup_pickupRequest_negativeButton">@string/no</string>
<string name="action_dashboard_item_cancel">Cancel</string>
<string name="dialog_dashboard_cancel_pickup_title">Cancel this pickup?</string>
<string name="dialog_dashboard_cancel_pickup_message">This will notify the donor that you\'re no longer picking up their donation, and remove this pickup from your dashboard.</string>
<string name="dialog_dashboard_cancel_positiveButton">Yes, cancel it</string>
<string name="dialog_dashboard_cancel_negativeButton">No, keep it</string>

</resources>

0 comments on commit 8ef4496

Please sign in to comment.