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 { private String accountId; private Relationship relationship; private OnRetrieveRelationshipInterface listener; private Error error; private WeakReference 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); } }