43 lines
1.3 KiB
Java
43 lines
1.3 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.Account;
|
|
import app.fedilab.fedilabtube.client.entities.Error;
|
|
import app.fedilab.fedilabtube.interfaces.OnRetrieveAccountInterface;
|
|
|
|
|
|
public class RetrieveAccountAsyncTask extends AsyncTask<Void, Void, Void> {
|
|
|
|
|
|
private String targetedId;
|
|
private Account account;
|
|
private OnRetrieveAccountInterface listener;
|
|
private Error error;
|
|
private WeakReference<Context> contextReference;
|
|
|
|
public RetrieveAccountAsyncTask(Context context, String targetedId, OnRetrieveAccountInterface onRetrieveAccountInterface) {
|
|
this.contextReference = new WeakReference<>(context);
|
|
this.targetedId = targetedId;
|
|
this.listener = onRetrieveAccountInterface;
|
|
}
|
|
|
|
@Override
|
|
protected Void doInBackground(Void... params) {
|
|
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
|
account = peertubeAPI.getAccount(targetedId);
|
|
error = peertubeAPI.getError();
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
protected void onPostExecute(Void result) {
|
|
listener.onRetrieveAccount(account, error);
|
|
}
|
|
|
|
}
|