45 lines
1.4 KiB
Java
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.APIResponse;
|
|
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
|
import app.fedilab.fedilabtube.client.entities.Peertube;
|
|
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeInterface;
|
|
|
|
|
|
public class PostPeertubeAsyncTask extends AsyncTask<Void, Void, Void> {
|
|
|
|
|
|
private APIResponse apiResponse;
|
|
private OnRetrievePeertubeInterface listener;
|
|
private WeakReference<Context> contextReference;
|
|
private Peertube peertube;
|
|
|
|
|
|
public PostPeertubeAsyncTask(Context context, Peertube peertube, OnRetrievePeertubeInterface onRetrievePeertubeInterface) {
|
|
this.contextReference = new WeakReference<>(context);
|
|
this.listener = onRetrievePeertubeInterface;
|
|
this.peertube = peertube;
|
|
}
|
|
|
|
|
|
@Override
|
|
protected Void doInBackground(Void... params) {
|
|
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
|
apiResponse = peertubeAPI.updateVideo(peertube);
|
|
if (apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0)
|
|
apiResponse.getPeertubes().get(0).setUpdate(true);
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
protected void onPostExecute(Void result) {
|
|
listener.onRetrievePeertube(apiResponse);
|
|
}
|
|
}
|