From c17e2c4ba40eccff417529c4c56cde6e80018602 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 10 Jul 2022 12:20:18 +0200 Subject: [PATCH] Fix Nitter Pagination + Allow to share through Nitter --- .../client/entities/nitter/Nitter.java | 11 ++++++- .../android/ui/drawer/StatusAdapter.java | 29 +++++++++++++++++++ .../viewmodel/mastodon/TimelinesVM.java | 5 ++-- app/src/main/res/layout/drawer_status.xml | 21 ++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/client/entities/nitter/Nitter.java b/app/src/main/java/app/fedilab/android/client/entities/nitter/Nitter.java index afc88ee4d..d53985337 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/nitter/Nitter.java +++ b/app/src/main/java/app/fedilab/android/client/entities/nitter/Nitter.java @@ -105,8 +105,8 @@ public class Nitter implements Serializable { } } Nitter nitterAccount = accounts.get(feedItem.creator); + app.fedilab.android.client.entities.api.Account account = new app.fedilab.android.client.entities.api.Account(); if (nitterAccount != null) { - app.fedilab.android.client.entities.api.Account account = new app.fedilab.android.client.entities.api.Account(); String[] names = nitterAccount.image.title.split("/"); account.id = feedItem.guid; account.acct = names[1].replace("@", ""); @@ -116,6 +116,15 @@ public class Nitter implements Serializable { account.avatar_static = nitterAccount.image.url; account.url = nitterAccount.image.link; status.account = account; + } else { + account.id = feedItem.guid; + account.acct = feedItem.creator.replace("@", ""); + account.username = feedItem.creator.replace("@", ""); + account.display_name = feedItem.creator.replace("@", ""); + account.avatar = ""; + account.avatar_static = ""; + account.url = feedItem.link; + status.account = account; } if (feedItem.description != null) { diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index c8aacea37..208055d0c 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -471,6 +471,35 @@ public class StatusAdapter extends RecyclerView.Adapter } else { holder.binding.card.setVisibility(View.GONE); } + if (!canBeFederated) { + holder.binding.actionShareContainer.setVisibility(View.VISIBLE); + holder.binding.actionShare.setOnClickListener(v -> { + Intent sendIntent = new Intent(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); + String url; + if (statusToDeal.uri.startsWith("http")) + url = status.uri; + else + url = status.url; + String extra_text; + if (share_details) { + extra_text = statusToDeal.account.acct; + if (extra_text.split("@").length == 1) + extra_text = "@" + extra_text + "@" + BaseMainActivity.currentInstance; + else + extra_text = "@" + extra_text; + extra_text += " \uD83D\uDD17 " + url + "\r\n-\n"; + extra_text += statusToDeal.text; + } else { + extra_text = url; + } + sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text); + sendIntent.setType("text/plain"); + context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); + }); + } else { + holder.binding.actionShareContainer.setVisibility(View.GONE); + } if (minified || !canBeFederated) { holder.binding.actionButtons.setVisibility(View.GONE); } else { diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java index a04c2a0de..465ec9e59 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java @@ -219,7 +219,6 @@ public class TimelinesVM extends AndroidViewModel { statusesMutableLiveData = new MutableLiveData<>(); new Thread(() -> { Call publicTlCall = mastodonTimelinesService.getNitter(accountsStr, max_position); - Statuses statuses = new Statuses(); if (publicTlCall != null) { try { @@ -234,7 +233,9 @@ public class TimelinesVM extends AndroidViewModel { } } statuses.statuses = SpannableHelper.convertNitterStatus(getApplication().getApplicationContext(), statusList); - statuses.pagination = MastodonHelper.getPagination(publicTlResponse.headers()); + String max_id = publicTlResponse.headers().get("min-id"); + statuses.pagination = new Pagination(); + statuses.pagination.max_id = max_id; } } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/res/layout/drawer_status.xml b/app/src/main/res/layout/drawer_status.xml index 93808fc2a..54e66bf4f 100644 --- a/app/src/main/res/layout/drawer_status.xml +++ b/app/src/main/res/layout/drawer_status.xml @@ -492,6 +492,27 @@ + + + + +