Fix timeline
This commit is contained in:
parent
cffbbd73a6
commit
48ee8380ac
|
@ -32,6 +32,7 @@ import app.fedilab.android.client.Entities.Results;
|
|||
import app.fedilab.android.client.Entities.RetrieveFeedsParam;
|
||||
import app.fedilab.android.client.GNUAPI;
|
||||
import app.fedilab.android.client.PeertubeAPI;
|
||||
import app.fedilab.android.fragments.DisplayStatusFragment;
|
||||
import app.fedilab.android.helper.FilterToots;
|
||||
import app.fedilab.android.interfaces.OnRetrieveFeedsInterface;
|
||||
import app.fedilab.android.sqlite.InstancesDAO;
|
||||
|
@ -66,6 +67,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
private int timelineId;
|
||||
private String currentfilter;
|
||||
private String social;
|
||||
private boolean fromCahe;
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, FilterToots filterToots, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
|
@ -73,16 +75,26 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.max_id = max_id;
|
||||
this.listener = onRetrieveFeedsInterface;
|
||||
this.filterToots = filterToots;
|
||||
this.fromCahe = false;
|
||||
}
|
||||
|
||||
|
||||
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.fromCahe = false;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, boolean fromCahe, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.action = action;
|
||||
this.max_id = max_id;
|
||||
this.listener = onRetrieveFeedsInterface;
|
||||
this.fromCahe = fromCahe;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, String instanceName, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
|
@ -90,6 +102,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.max_id = max_id;
|
||||
this.listener = onRetrieveFeedsInterface;
|
||||
this.instanceName = instanceName;
|
||||
this.fromCahe = false;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, int timelineId, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
|
@ -98,6 +111,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.max_id = max_id;
|
||||
this.listener = onRetrieveFeedsInterface;
|
||||
this.timelineId = timelineId;
|
||||
this.fromCahe = false;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, String targetedID, String max_id, boolean showMediaOnly, boolean showPinned, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
|
@ -108,6 +122,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.targetedID = targetedID;
|
||||
this.showMediaOnly = showMediaOnly;
|
||||
this.showPinned = showPinned;
|
||||
this.fromCahe = false;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, String targetedID, String max_id, boolean showMediaOnly, boolean showPinned, boolean showReply, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
|
@ -119,6 +134,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.showMediaOnly = showMediaOnly;
|
||||
this.showPinned = showPinned;
|
||||
this.showReply = showReply;
|
||||
this.fromCahe = false;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, Type action, String tag, String targetedID, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
|
@ -128,6 +144,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.listener = onRetrieveFeedsInterface;
|
||||
this.targetedID = targetedID;
|
||||
this.tag = tag;
|
||||
this.fromCahe = false;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, String remoteInstance, String name, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
|
@ -137,6 +154,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.listener = onRetrieveFeedsInterface;
|
||||
this.name = name;
|
||||
this.action = Type.REMOTE_INSTANCE;
|
||||
this.fromCahe = false;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, RetrieveFeedsParam retrieveFeedsParam, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
|
||||
|
@ -154,8 +172,12 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.social = retrieveFeedsParam.getSocial();
|
||||
this.instanceName = retrieveFeedsParam.getInstanceName();
|
||||
this.remoteInstance = retrieveFeedsParam.getRemoteInstance();
|
||||
this.fromCahe = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
API api = new API(this.contextReference.get());
|
||||
|
@ -164,7 +186,11 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
return null;
|
||||
switch (action) {
|
||||
case HOME:
|
||||
apiResponse = api.getHomeTimelineCache(max_id);
|
||||
if (this.fromCahe) {
|
||||
apiResponse = api.getHomeTimelineCache(max_id);
|
||||
} else {
|
||||
apiResponse = api.getHomeTimeline(max_id);
|
||||
}
|
||||
break;
|
||||
case LOCAL:
|
||||
apiResponse = api.getPublicTimeline(true, max_id);
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
|
@ -33,6 +34,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.ParseException;
|
||||
|
@ -2906,15 +2908,13 @@ public class API {
|
|||
} else {
|
||||
statuses = parseStatuses(context, new JSONArray(response));
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
} catch (UnknownHostException e){
|
||||
if (since_id == null){
|
||||
getHomeTimelineCache(max_id);
|
||||
}
|
||||
} catch(HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (apiResponse == null)
|
||||
|
|
|
@ -70,6 +70,7 @@ import app.fedilab.android.client.Entities.Error;
|
|||
import app.fedilab.android.helper.FileNameCleaner;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.interfaces.OnDownloadInterface;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
@ -95,6 +96,7 @@ public class HttpsConnection {
|
|||
private Proxy proxy;
|
||||
private String instance;
|
||||
private String USER_AGENT;
|
||||
private int cacheSize = 30*1024*1024;
|
||||
|
||||
public HttpsConnection(Context context, String instance) {
|
||||
this.instance = instance;
|
||||
|
@ -177,7 +179,7 @@ public class HttpsConnection {
|
|||
URL url = new URL(urlConnection + "?" + postData);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(timeout, TimeUnit.SECONDS);
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(timeout, TimeUnit.SECONDS).cache(new Cache(context.getCacheDir(), cacheSize));
|
||||
if (proxy != null) {
|
||||
builder.proxy(proxy);
|
||||
}
|
||||
|
@ -297,7 +299,7 @@ public class HttpsConnection {
|
|||
public String get(String urlConnection) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException {
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS);
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS).cache(new Cache(context.getCacheDir(), cacheSize));
|
||||
if (proxy != null) {
|
||||
builder.proxy(proxy);
|
||||
}
|
||||
|
|
|
@ -1076,7 +1076,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
if (context instanceof BaseMainActivity) {
|
||||
boolean remember_position_home = sharedpreferences.getBoolean(Helper.SET_REMEMBER_POSITION_HOME, true);
|
||||
if (remember_position_home)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, initialBookMark, DisplayStatusFragment.this).execute();
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, initialBookMark, true,DisplayStatusFragment.this).execute();
|
||||
else
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, null, DisplayStatusFragment.this).execute();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue