Created
October 23, 2013 13:06
-
-
Save arjan/7118372 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package nu.reckon.app.tasks; | |
import nu.reckon.api.Client; | |
import nu.reckon.api.v5.Photo; | |
import nu.reckon.app.PhotoCache; | |
import nu.reckon.app.ReckonApi; | |
import nu.reckon.app.ui.ActivityIndicator; | |
import android.os.AsyncTask; | |
import android.support.v4.app.FragmentActivity; | |
import android.util.Log; | |
public class DeletePhotoTask extends AsyncTask<Void, Void, Boolean> | |
{ | |
private static final String TAG = "DeletePhotoTask"; | |
private ActivityIndicator mIndicator; | |
private FragmentActivity mActivity; | |
private Photo mPhoto; | |
public DeletePhotoTask(FragmentActivity activity, Photo photo, ActivityIndicator indicator) { | |
mActivity = activity; | |
mIndicator = indicator; | |
mPhoto = photo; | |
mIndicator.apiCallStart(); | |
} | |
@Override | |
protected Boolean doInBackground(Void... params) { | |
Client client = ReckonApi.getClient(mActivity); | |
try { | |
boolean r = client.v5.removePhoto(mPhoto.id); | |
return Boolean.valueOf(r); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
@Override | |
protected void onPostExecute(Boolean result) { | |
super.onPostExecute(result); | |
mIndicator.apiCallStop(); | |
if (result == null) { | |
return; | |
} | |
Log.v(TAG, "Photo deleted!"); | |
mPhoto.deleted = true; | |
PhotoCache.getInstance(mActivity).set(mPhoto); | |
mActivity.getSupportFragmentManager().popBackStack(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment