Fix paginations

pull/17/head
Thomas 3 years ago
parent 0769082a8c
commit 8bd9ecaa71

@ -613,7 +613,7 @@ public class Helper {
* @param url String url to open * @param url String url to open
*/ */
public static void openBrowser(Context context, String url) { public static void openBrowser(Context context, String url) {
url = transformURL(context, url); //url = transformURL(context, url);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean embedded_browser = sharedpreferences.getBoolean(context.getString(R.string.SET_EMBEDDED_BROWSER), true); boolean embedded_browser = sharedpreferences.getBoolean(context.getString(R.string.SET_EMBEDDED_BROWSER), true);
if (embedded_browser && !url.toLowerCase().startsWith("gemini://")) { if (embedded_browser && !url.toLowerCase().startsWith("gemini://")) {
@ -644,7 +644,7 @@ public class Helper {
* @param context Context * @param context Context
* @param url String * @param url String
*/ */
private static String transformURL(Context context, String url) { public static String transformURL(Context context, String url) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
Matcher matcher = Helper.nitterPattern.matcher(url); Matcher matcher = Helper.nitterPattern.matcher(url);
boolean nitter = Helper.getSharedValue(context, context.getString(R.string.SET_NITTER)); boolean nitter = Helper.getSharedValue(context, context.getString(R.string.SET_NITTER));

@ -166,15 +166,17 @@ public class SpannableHelper {
continue; continue;
}*/ }*/
final String url = content.toString().substring(matchStart, matchEnd); final String url = content.toString().substring(matchStart, matchEnd);
String newURL = Helper.transformURL(context, url);
content.replace(matchStart, matchEnd, newURL);
//Truncate URL if needed //Truncate URL if needed
//TODO: add an option to disable truncated URLs //TODO: add an option to disable truncated URLs
String urlText = url; String urlText = newURL;
if (url.length() > 30) { if (newURL.length() > 30) {
urlText = urlText.substring(0, 30); urlText = urlText.substring(0, 30);
urlText += "…"; urlText += "…";
content.replace(matchStart, matchEnd, urlText); content.replace(matchStart, matchEnd, urlText);
matchEnd = matchStart + 31; matchEnd = matchStart + 31;
offSetTruncate += (url.length() - urlText.length()); offSetTruncate += (newURL.length() - urlText.length());
} }
if (!urlText.startsWith("http")) { if (!urlText.startsWith("http")) {
continue; continue;
@ -184,7 +186,7 @@ public class SpannableHelper {
@Override @Override
public void onClick(@NonNull View textView) { public void onClick(@NonNull View textView) {
textView.setTag(CLICKABLE_SPAN); textView.setTag(CLICKABLE_SPAN);
Helper.openBrowser(context, url); Helper.openBrowser(context, newURL);
} }
@Override @Override

@ -305,8 +305,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
holder.binding.cardTitle.setText(status.card.title); holder.binding.cardTitle.setText(status.card.title);
holder.binding.cardDescription.setText(status.card.description); holder.binding.cardDescription.setText(status.card.description);
holder.binding.cardUrl.setText(status.card.url); holder.binding.cardUrl.setText(Helper.transformURL(context, status.card.url));
holder.binding.cardUrl.setOnClickListener(v -> Helper.openBrowser(context, status.card.url)); holder.binding.cardviewContainer.setOnClickListener(v -> Helper.openBrowser(context, Helper.transformURL(context, status.card.url)));
holder.binding.card.setVisibility(View.VISIBLE); holder.binding.card.setVisibility(View.VISIBLE);
} else { } else {
holder.binding.card.setVisibility(View.GONE); holder.binding.card.setVisibility(View.GONE);

@ -243,8 +243,13 @@ public class FragmentMastodonTimeline extends Fragment {
} }
this.statuses.addAll(statuses.statuses); this.statuses.addAll(statuses.statuses);
max_id = statuses.pagination.max_id; if (max_id == null || (statuses.pagination.max_id != null && statuses.pagination.max_id.compareTo(max_id) < 0)) {
min_id = statuses.pagination.min_id; max_id = statuses.pagination.max_id;
}
if (min_id == null || (statuses.pagination.max_id != null && statuses.pagination.min_id.compareTo(min_id) > 0)) {
min_id = statuses.pagination.min_id;
}
statusAdapter = new StatusAdapter(this.statuses, timelineType == Timeline.TimeLineEnum.REMOTE, minified); statusAdapter = new StatusAdapter(this.statuses, timelineType == Timeline.TimeLineEnum.REMOTE, minified);
if (statusReport != null) { if (statusReport != null) {
@ -315,8 +320,12 @@ public class FragmentMastodonTimeline extends Fragment {
statuses.addAll(fetched_statuses.statuses); statuses.addAll(fetched_statuses.statuses);
statusAdapter.notifyItemRangeInserted(startId, fetched_statuses.statuses.size()); statusAdapter.notifyItemRangeInserted(startId, fetched_statuses.statuses.size());
} }
max_id = fetched_statuses.pagination.max_id; if (max_id == null || (fetched_statuses.pagination.max_id != null && fetched_statuses.pagination.max_id.compareTo(max_id) < 0)) {
min_id = fetched_statuses.pagination.min_id; max_id = fetched_statuses.pagination.max_id;
}
if (min_id == null || (fetched_statuses.pagination.max_id != null && fetched_statuses.pagination.min_id.compareTo(min_id) > 0)) {
min_id = fetched_statuses.pagination.min_id;
}
} }
} }

Loading…
Cancel
Save