Fix pagination

This commit is contained in:
tom79 2019-12-08 17:49:13 +01:00
parent 215b9614fb
commit 96e806fd99
2 changed files with 35 additions and 10 deletions

View File

@ -19,7 +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;
@ -3417,14 +3417,20 @@ public class API {
apiResponse.setError(error);
return apiResponse;
}
StringBuilder params = new StringBuilder();
StringBuilder urlparams = new StringBuilder();
for(String param: usernames){
params.append(param.trim()).append(",");
urlparams.append(param.trim()).append(",");
}
String url = "https://" + nitterHost + "/" + urlparams + "/rss";
if( max_id != null ){
url += "?max_position=" + max_id;
}
try {
statuses = new ArrayList<>();
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get("https://" + nitterHost + "/" + params + "/rss", 30, null, null);
String response = httpsConnection.get(url, 30, null, null);
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseNitter(response);
} catch (HttpsConnection.HttpsConnectionException e) {

View File

@ -170,13 +170,18 @@ public class HttpsConnection {
}
}
StringBuilder postData = new StringBuilder();
for (Map.Entry<String, Object> param : params.entrySet()) {
if (postData.length() != 0) postData.append('&');
postData.append(param.getKey());
postData.append('=');
postData.append(param.getValue());
URL url;
if( params.size() > 0 ) {
for (Map.Entry<String, Object> param : params.entrySet()) {
if (postData.length() != 0) postData.append('&');
postData.append(param.getKey());
postData.append('=');
postData.append(param.getValue());
}
url = new URL(urlConnection + "?" + postData);
}else{
url = new URL(urlConnection);
}
URL url = new URL(urlConnection + "?" + postData);
if (Build.VERSION.SDK_INT >= 21) {
OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(timeout, TimeUnit.SECONDS).cache(new Cache(context.getCacheDir(), cacheSize));
@ -331,6 +336,7 @@ public class HttpsConnection {
throw new HttpsConnectionException(code, error);
}
}
} else {
URL url = new URL(urlConnection);
if (proxy != null)
@ -1443,6 +1449,12 @@ public class HttpsConnection {
}
}
}else if (entry.toString().startsWith("Min-Id") || entry.toString().startsWith("min-id")) {
Pattern patternMaxId = Pattern.compile("min-id=\\[([0-9a-zA-Z]{1,}).*\\]");
Matcher matcherMaxId = patternMaxId.matcher(entry.toString());
if (matcherMaxId.find()) {
max_id = matcherMaxId.group(1);
}
}
}
}
@ -1454,6 +1466,7 @@ public class HttpsConnection {
if (httpsURLConnection == null)
return;
Map<String, List<String>> map = httpsURLConnection.getHeaderFields();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
if (entry.toString().startsWith("Link") || entry.toString().startsWith("link")) {
Pattern patternMaxId = Pattern.compile("max_id=([0-9a-zA-Z]{1,}).*");
@ -1469,6 +1482,12 @@ public class HttpsConnection {
}
}
}else if (entry.toString().startsWith("Min-Id") || entry.toString().startsWith("min-id")) {
Pattern patternMaxId = Pattern.compile("min-id=\\[([0-9a-zA-Z]{1,}).*\\]");
Matcher matcherMaxId = patternMaxId.matcher(entry.toString());
if (matcherMaxId.find()) {
max_id = matcherMaxId.group(1);
}
}
}
} else {