134 lines
4.5 KiB
Java
134 lines
4.5 KiB
Java
|
|
package app.fedilab.fedilabtube.asynctasks;
|
|
|
|
import android.content.Context;
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
import android.os.AsyncTask;
|
|
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.List;
|
|
|
|
import app.fedilab.fedilabtube.client.APIResponse;
|
|
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
|
import app.fedilab.fedilabtube.client.entities.Peertube;
|
|
import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface;
|
|
import app.fedilab.fedilabtube.sqlite.PeertubeFavoritesDAO;
|
|
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
|
|
|
|
|
public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|
|
|
|
|
private Type action;
|
|
private APIResponse apiResponse;
|
|
private String max_id;
|
|
private OnRetrieveFeedsInterface listener;
|
|
private String targetedID;
|
|
private String tag;
|
|
private boolean showMediaOnly = false;
|
|
private boolean showPinned = false;
|
|
private boolean showReply = false;
|
|
private WeakReference<Context> contextReference;
|
|
private String instanceName, remoteInstance, name;
|
|
private int timelineId;
|
|
private String search;
|
|
|
|
|
|
private String social;
|
|
|
|
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
|
this.contextReference = new WeakReference<>(context);
|
|
this.action = action;
|
|
this.max_id = max_id;
|
|
this.listener = onRetrieveFeedsInterface;
|
|
this.search = null;
|
|
}
|
|
|
|
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, String search, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
|
this.contextReference = new WeakReference<>(context);
|
|
this.action = action;
|
|
this.max_id = max_id;
|
|
this.listener = onRetrieveFeedsInterface;
|
|
this.search = search;
|
|
}
|
|
|
|
|
|
@Override
|
|
protected Void doInBackground(Void... params) {
|
|
PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
|
|
|
if (action == null)
|
|
return null;
|
|
switch (action) {
|
|
case USER:
|
|
apiResponse = peertubeAPI.getVideos(targetedID, max_id);
|
|
break;
|
|
case MYVIDEOS:
|
|
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
|
apiResponse = peertubeAPI.getMyVideos(max_id);
|
|
break;
|
|
case PEERTUBE_HISTORY:
|
|
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
|
apiResponse = peertubeAPI.getMyHistory(max_id);
|
|
break;
|
|
case CHANNEL:
|
|
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
|
apiResponse = peertubeAPI.getVideosChannel(targetedID, max_id);
|
|
break;
|
|
|
|
case CACHE_BOOKMARKS_PEERTUBE:
|
|
apiResponse = new APIResponse();
|
|
SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
List<Peertube> peertubes = new PeertubeFavoritesDAO(contextReference.get(), db).getAllPeertube();
|
|
apiResponse.setPeertubes(peertubes);
|
|
break;
|
|
case PSUBSCRIPTIONS:
|
|
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
|
apiResponse = peertubeAPI.getSubscriptionsTL(max_id);
|
|
break;
|
|
case POVERVIEW:
|
|
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
|
apiResponse = peertubeAPI.getOverviewTL(max_id);
|
|
break;
|
|
case PTRENDING:
|
|
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
|
apiResponse = peertubeAPI.getTrendingTL(max_id);
|
|
break;
|
|
case PRECENTLYADDED:
|
|
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
|
apiResponse = peertubeAPI.getRecentlyAddedTL(max_id);
|
|
break;
|
|
case PLOCAL:
|
|
peertubeAPI = new PeertubeAPI(this.contextReference.get());
|
|
apiResponse = peertubeAPI.getLocalTL(max_id);
|
|
break;
|
|
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
protected void onPostExecute(Void result) {
|
|
listener.onRetrieveFeeds(apiResponse);
|
|
}
|
|
|
|
public enum Type {
|
|
|
|
USER,
|
|
|
|
PPUBLIC,
|
|
PSUBSCRIPTIONS,
|
|
POVERVIEW,
|
|
PTRENDING,
|
|
PRECENTLYADDED,
|
|
PMOSTLIKED,
|
|
PLOCAL,
|
|
CHANNEL,
|
|
MYVIDEOS,
|
|
PEERTUBE_HISTORY,
|
|
|
|
CACHE_BOOKMARKS_PEERTUBE,
|
|
|
|
}
|
|
}
|