Fix some weird behavior when clicking links in statuses (#2304)
* Fix some weird behavior when clicking links in statuses * open browser when user clicks a status link again
This commit is contained in:
parent
bf05c8a5d5
commit
8f5fb5b35c
5 changed files with 97 additions and 70 deletions
|
@ -180,6 +180,8 @@ abstract class BottomSheetActivity : BaseActivity() {
|
|||
// https://friendica.foo.bar/profile/user
|
||||
// https://friendica.foo.bar/display/d4643c42-3ae0-4b73-b8b0-c725f5819207
|
||||
// https://misskey.foo.bar/notes/83w6r388br (always lowercase)
|
||||
// https://pixelfed.social/p/connyduck/391263492998670833
|
||||
// https://pixelfed.social/connyduck
|
||||
fun looksLikeMastodonUrl(urlString: String): Boolean {
|
||||
val uri: URI
|
||||
try {
|
||||
|
@ -203,7 +205,9 @@ fun looksLikeMastodonUrl(urlString: String): Boolean {
|
|||
path.matches("^/objects/[-a-f0-9]+$".toRegex()) ||
|
||||
path.matches("^/notes/[a-z0-9]+$".toRegex()) ||
|
||||
path.matches("^/display/[-a-f0-9]+$".toRegex()) ||
|
||||
path.matches("^/profile/\\w+$".toRegex())
|
||||
path.matches("^/profile/\\w+$".toRegex()) ||
|
||||
path.matches("^/p/\\w+/\\d+$".toRegex()) ||
|
||||
path.matches("^/\\w+$".toRegex())
|
||||
}
|
||||
|
||||
enum class PostLookupFallbackBehavior {
|
||||
|
|
|
@ -771,7 +771,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
|
||||
if (cardView != null) {
|
||||
setupCard(status, statusDisplayOptions.cardViewMode(), statusDisplayOptions);
|
||||
setupCard(status, statusDisplayOptions.cardViewMode(), statusDisplayOptions, listener);
|
||||
}
|
||||
|
||||
setupButtons(listener, actionable.getAccount().getId(), status.getContent().toString(),
|
||||
|
@ -1034,7 +1034,12 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
return pollDescription.getContext().getString(R.string.poll_info_format, votesText, pollDurationInfo);
|
||||
}
|
||||
|
||||
protected void setupCard(StatusViewData.Concrete status, CardViewMode cardViewMode, StatusDisplayOptions statusDisplayOptions) {
|
||||
protected void setupCard(
|
||||
StatusViewData.Concrete status,
|
||||
CardViewMode cardViewMode,
|
||||
StatusDisplayOptions statusDisplayOptions,
|
||||
final StatusActionListener listener
|
||||
) {
|
||||
final Card card = status.getActionable().getCard();
|
||||
if (cardViewMode != CardViewMode.NONE &&
|
||||
status.getActionable().getAttachments().size() == 0 &&
|
||||
|
@ -1125,7 +1130,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
cardImage.setImageResource(R.drawable.card_image_placeholder);
|
||||
}
|
||||
|
||||
View.OnClickListener visitLink = v -> LinkHelper.openLink(card.getUrl(), v.getContext());
|
||||
View.OnClickListener visitLink = v -> listener.onViewUrl(card.getUrl());
|
||||
View.OnClickListener openImage = v -> cardView.getContext().startActivity(ViewMediaActivity.newSingleImageIntent(cardView.getContext(), card.getEmbed_url()));
|
||||
|
||||
cardInfo.setOnClickListener(visitLink);
|
||||
|
|
|
@ -106,7 +106,7 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
|
|||
StatusDisplayOptions statusDisplayOptions,
|
||||
@Nullable Object payloads) {
|
||||
super.setupWithStatus(status, listener, statusDisplayOptions, payloads);
|
||||
setupCard(status, CardViewMode.FULL_WIDTH, statusDisplayOptions); // Always show card for detailed status
|
||||
setupCard(status, CardViewMode.FULL_WIDTH, statusDisplayOptions, listener); // Always show card for detailed status
|
||||
if (payloads == null) {
|
||||
|
||||
if (!statusDisplayOptions.hideStats()) {
|
||||
|
|
|
@ -60,6 +60,7 @@ import com.keylesspalace.tusky.network.FilterModel;
|
|||
import com.keylesspalace.tusky.network.MastodonApi;
|
||||
import com.keylesspalace.tusky.settings.PrefKeys;
|
||||
import com.keylesspalace.tusky.util.CardViewMode;
|
||||
import com.keylesspalace.tusky.util.LinkHelper;
|
||||
import com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate;
|
||||
import com.keylesspalace.tusky.util.PairedList;
|
||||
import com.keylesspalace.tusky.util.StatusDisplayOptions;
|
||||
|
@ -319,6 +320,22 @@ public final class ViewThreadFragment extends SFragment implements
|
|||
super.viewThread(status.getActionableId(), status.getActionableStatus().getUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewUrl(String url) {
|
||||
Status status = null;
|
||||
if (!statuses.isEmpty()) {
|
||||
status = statuses.get(statusIndex);
|
||||
}
|
||||
if (status != null && status.getUrl().equals(url)) {
|
||||
// already viewing the status with this url
|
||||
// probably just a preview federated and the user is clicking again to view more -> open the browser
|
||||
// this can happen with some friendica statuses
|
||||
LinkHelper.openLink(url, requireContext());
|
||||
return;
|
||||
}
|
||||
super.onViewUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpenReblog(int position) {
|
||||
// there should be no reblogs in the thread but let's implement it to be sure
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue