package app.fedilab.fedilabtube.asynctasks; import android.content.Context; import android.os.AsyncTask; import java.lang.ref.WeakReference; import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.PeertubeAPI; import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface; public class RetrievePeertubeSearchAsyncTask extends AsyncTask { private String query, instance; private APIResponse apiResponse; private OnRetrieveFeedsInterface listener; private WeakReference contextReference; public RetrievePeertubeSearchAsyncTask(Context context, String instance, String query, OnRetrieveFeedsInterface onRetrieveFeedsInterface) { this.contextReference = new WeakReference<>(context); this.query = query; this.listener = onRetrieveFeedsInterface; this.instance = instance; } @Override protected Void doInBackground(Void... params) { PeertubeAPI api = new PeertubeAPI(this.contextReference.get()); apiResponse = api.searchPeertube(instance, query); return null; } @Override protected void onPostExecute(Void result) { listener.onRetrieveFeeds(apiResponse); } }