TubeLab-App-Android/app/src/main/java/app/fedilab/fedilabtube/asynctasks/RetrieveRelationshipAsyncTa...

45 lines
1.4 KiB
Java

package app.fedilab.fedilabtube.asynctasks;
import android.content.Context;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import app.fedilab.fedilabtube.client.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.Relationship;
import app.fedilab.fedilabtube.interfaces.OnRetrieveRelationshipInterface;
public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, Void> {
private String accountId;
private Relationship relationship;
private OnRetrieveRelationshipInterface listener;
private Error error;
private WeakReference<Context> contextReference;
public RetrieveRelationshipAsyncTask(Context context, String accountId, OnRetrieveRelationshipInterface onRetrieveRelationshipInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveRelationshipInterface;
this.accountId = accountId;
}
@Override
protected Void doInBackground(Void... params) {
PeertubeAPI api = new PeertubeAPI(this.contextReference.get());
relationship = new Relationship();
relationship.setFollowing(api.isFollowing(accountId));
error = api.getError();
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveRelationship(relationship, error);
}
}