diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/SplashFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/SplashFragment.java index 3296d3c6e..b4964f040 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/SplashFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/SplashFragment.java @@ -34,6 +34,7 @@ import org.joinmastodon.android.ui.views.SizeListenerFrameLayout; import org.parceler.Parcels; import java.util.List; +import java.util.Objects; import java.util.concurrent.ThreadLocalRandom; import androidx.annotation.Nullable; @@ -263,7 +264,7 @@ public class SplashFragment extends AppKitFragment{ String clipText=clipData.getItemAt(0).coerceToText(getActivity()).toString(); if(HtmlParser.isValidInviteUrl(clipText)){ currentInviteLink=Uri.parse(clipText); - defaultServerButton.setText(getString(R.string.join_server_x_with_invite, currentInviteLink.getHost())); + defaultServerButton.setText(getString(R.string.join_server_x_with_invite, HtmlParser.normalizeDomain(Objects.requireNonNull(currentInviteLink.getHost())))); } }else{ loadingDefaultServer=true; @@ -315,7 +316,7 @@ public class SplashFragment extends AppKitFragment{ if(defaultServerButton!=null && getActivity()!=null && currentInviteLink==null){ defaultServerButton.setTextVisible(true); defaultServerProgress.setVisibility(View.GONE); - defaultServerButton.setText(getString(R.string.join_default_server, chosenDefaultServer)); + defaultServerButton.setText(getString(R.string.join_default_server, HtmlParser.normalizeDomain(chosenDefaultServer))); } } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/LinkCardStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/LinkCardStatusDisplayItem.java index 81bd7f148..f02af8592 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/LinkCardStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/LinkCardStatusDisplayItem.java @@ -17,8 +17,11 @@ import org.joinmastodon.android.model.Card; import org.joinmastodon.android.model.Status; import org.joinmastodon.android.ui.OutlineProviders; import org.joinmastodon.android.ui.drawables.BlurhashCrossfadeDrawable; +import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.ui.utils.UiUtils; +import java.util.Objects; + import me.grishka.appkit.imageloader.ImageLoaderViewHolder; import me.grishka.appkit.imageloader.requests.ImageLoaderRequest; import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest; @@ -82,9 +85,7 @@ public class LinkCardStatusDisplayItem extends StatusDisplayItem{ description.setText(card.description); description.setVisibility(TextUtils.isEmpty(card.description) ? View.GONE : View.VISIBLE); } - String cardDomain=Uri.parse(card.url).getHost(); - if(cardDomain.startsWith("www.")) - cardDomain=cardDomain.substring(4); + String cardDomain=HtmlParser.normalizeDomain(Objects.requireNonNull(Uri.parse(card.url).getHost())); if(isLarge && !TextUtils.isEmpty(card.authorName)){ domain.setText(itemView.getContext().getString(R.string.article_by_author, card.authorName)+" ยท "+cardDomain); }else{ diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java index e09d1b4ec..34ae42898 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java @@ -263,4 +263,10 @@ public class HtmlParser{ public static boolean isValidInviteUrl(String url){ return url.startsWith("https://") && INVITE_LINK_PATH.matcher(url).find(); } + + public static String normalizeDomain(String domain){ + if(domain.startsWith("www.")) + domain=domain.substring(4); + return domain; + } }