Improvements
This commit is contained in:
parent
37913818ce
commit
893963e90f
|
@ -53,6 +53,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
private WeakReference<Context> contextReference;
|
||||
private FilterToots filterToots;
|
||||
private String instanceName,remoteInstance, name;
|
||||
private boolean cached = true;
|
||||
|
||||
public enum Type{
|
||||
HOME,
|
||||
|
@ -89,6 +90,14 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.listener = onRetrieveFeedsInterface;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, boolean cached, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.action = action;
|
||||
this.max_id = max_id;
|
||||
this.listener = onRetrieveFeedsInterface;
|
||||
this.cached = cached;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, String instanceName, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.action = action;
|
||||
|
@ -140,13 +149,17 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
switch (action){
|
||||
case HOME:
|
||||
List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses = new StatusCacheDAO(contextReference.get(), db).getAllCachedStatus(max_id);
|
||||
if( statuses == null || statuses.size() == 0)
|
||||
if( cached){
|
||||
List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses = new StatusCacheDAO(contextReference.get(), db).getAllCachedStatus(max_id);
|
||||
if( statuses == null || statuses.size() == 0)
|
||||
apiResponse = api.getHomeTimeline(max_id);
|
||||
else{
|
||||
apiResponse = new APIResponse();
|
||||
apiResponse.setStatuses(statuses);
|
||||
apiResponse.setMax_id(statuses.get(statuses.size()-1).getId());
|
||||
}
|
||||
}else{
|
||||
apiResponse = api.getHomeTimeline(max_id);
|
||||
else{
|
||||
apiResponse = new APIResponse();
|
||||
apiResponse.setStatuses(statuses);
|
||||
apiResponse.setMax_id(statuses.get(statuses.size()-1).getId());
|
||||
}
|
||||
break;
|
||||
case LOCAL:
|
||||
|
@ -199,7 +212,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
case CACHE_BOOKMARKS:
|
||||
apiResponse = new APIResponse();
|
||||
db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
statuses = new StatusCacheDAO(contextReference.get(), db).getAllStatus(StatusCacheDAO.BOOKMARK_CACHE);
|
||||
List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses = new StatusCacheDAO(contextReference.get(), db).getAllStatus(StatusCacheDAO.BOOKMARK_CACHE);
|
||||
apiResponse.setStatuses(statuses);
|
||||
break;
|
||||
case CACHE_BOOKMARKS_PEERTUBE:
|
||||
|
|
|
@ -719,7 +719,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
}
|
||||
|
||||
public void fetchMore(String max_id){
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id,false, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@ public class StatusCacheDAO {
|
|||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(context);
|
||||
try {
|
||||
Cursor c = db.query(Sqlite.TABLE_STATUSES_CACHE, null, Sqlite.COL_CACHED_ACTION + " = '" + StatusCacheDAO.STATUS_CACHE+ "' AND " + Sqlite.COL_INSTANCE + " = '" + instance+ "' AND " + Sqlite.COL_USER_ID + " = '" + userId+ "' AND " + Sqlite.COL_STATUS_ID +" <= '" + max_id+ "'", null, null, null, Sqlite.COL_STATUS_ID + " DESC", "40");
|
||||
Cursor c = db.query(Sqlite.TABLE_STATUSES_CACHE, null, Sqlite.COL_CACHED_ACTION + " = '" + StatusCacheDAO.STATUS_CACHE+ "' AND " + Sqlite.COL_INSTANCE + " = '" + instance+ "' AND " + Sqlite.COL_USER_ID + " = '" + userId+ "' AND " + Sqlite.COL_STATUS_ID +" < '" + max_id+ "'", null, null, null, Sqlite.COL_STATUS_ID + " DESC", "40");
|
||||
return cursorToListStatuses(c);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in New Issue