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