Fix paginations

This commit is contained in:
Thomas 2022-05-04 16:13:30 +02:00
parent 0769082a8c
commit 8bd9ecaa71
4 changed files with 23 additions and 12 deletions

View file

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

View file

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

View file

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

View file

@ -243,8 +243,13 @@ public class FragmentMastodonTimeline extends Fragment {
}
this.statuses.addAll(statuses.statuses);
max_id = statuses.pagination.max_id;
min_id = statuses.pagination.min_id;
if (max_id == null || (statuses.pagination.max_id != null && statuses.pagination.max_id.compareTo(max_id) < 0)) {
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);
if (statusReport != null) {
@ -315,8 +320,12 @@ public class FragmentMastodonTimeline extends Fragment {
statuses.addAll(fetched_statuses.statuses);
statusAdapter.notifyItemRangeInserted(startId, fetched_statuses.statuses.size());
}
max_id = fetched_statuses.pagination.max_id;
min_id = fetched_statuses.pagination.min_id;
if (max_id == null || (fetched_statuses.pagination.max_id != null && fetched_statuses.pagination.max_id.compareTo(max_id) < 0)) {
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;
}
}
}