diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIRequest.java b/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIRequest.java index ad9a6254e..44a740401 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIRequest.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIRequest.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.function.Consumer; import androidx.annotation.CallSuper; import androidx.annotation.StringRes; @@ -101,9 +102,14 @@ public abstract class MastodonAPIRequest extends APIRequest{ } public MastodonAPIRequest wrapProgress(Activity activity, @StringRes int message, boolean cancelable){ + return wrapProgress(activity, message, cancelable, null); + } + + public MastodonAPIRequest wrapProgress(Activity activity, @StringRes int message, boolean cancelable, Consumer transform){ progressDialog=new ProgressDialog(activity); progressDialog.setMessage(activity.getString(message)); progressDialog.setCancelable(cancelable); + if (transform != null) transform.accept(progressDialog); if(cancelable){ progressDialog.setOnCancelListener(dialog->cancel()); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java index bea5dacc9..f82f0b4fb 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java @@ -5,10 +5,12 @@ import static org.joinmastodon.android.GlobalUserPreferences.trueBlackTheme; import android.annotation.SuppressLint; import android.app.Activity; +import android.app.ProgressDialog; import android.content.ActivityNotFoundException; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.res.ColorStateList; import android.content.res.Configuration; @@ -16,6 +18,7 @@ import android.content.res.TypedArray; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.InsetDrawable; @@ -49,6 +52,7 @@ import org.joinmastodon.android.api.requests.accounts.SetAccountMuted; import org.joinmastodon.android.api.requests.accounts.SetDomainBlocked; import org.joinmastodon.android.api.requests.accounts.AuthorizeFollowRequest; import org.joinmastodon.android.api.requests.accounts.RejectFollowRequest; +import org.joinmastodon.android.api.requests.search.GetSearchResults; import org.joinmastodon.android.api.requests.statuses.DeleteStatus; import org.joinmastodon.android.api.requests.statuses.GetStatusByID; import org.joinmastodon.android.api.requests.statuses.SetStatusPinned; @@ -67,6 +71,7 @@ import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.Emoji; import org.joinmastodon.android.model.ListTimeline; import org.joinmastodon.android.model.Relationship; +import org.joinmastodon.android.model.SearchResults; import org.joinmastodon.android.model.Status; import org.joinmastodon.android.ui.M3AlertDialogBuilder; import org.joinmastodon.android.ui.text.CustomEmojiSpan; @@ -676,12 +681,20 @@ public class UiUtils{ return theme==GlobalUserPreferences.ThemePreference.DARK; } - public static void openURL(Context context, @Nullable String accountID, String url){ + public static void openURL(Context context, String accountID, String url){ + Consumer transformDialogForLookup = dialog -> { + dialog.setTitle(R.string.loading_fediverse_resource_title); + dialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.cancel), (d, which) -> d.cancel()); + dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.open_in_browser), (d, which) -> { + d.cancel(); + launchWebBrowser(context, url); + }); + }; + Uri uri=Uri.parse(url); - if(accountID!=null && "https".equals(uri.getScheme()) && AccountSessionManager.getInstance().getAccount(accountID).domain.equalsIgnoreCase(uri.getAuthority())){ - List path=uri.getPathSegments(); - // Match URLs like https://mastodon.social/@Gargron/108132679274083591 - if(path.size()==2 && path.get(0).matches("^@[a-zA-Z0-9_]+$") && path.get(1).matches("^[0-9]+$")){ + List path=uri.getPathSegments(); + if(accountID!=null && "https".equals(uri.getScheme())){ + if(path.size()==2 && path.get(0).matches("^@[a-zA-Z0-9_]+$") && path.get(1).matches("^[0-9]+$") && AccountSessionManager.getInstance().getAccount(accountID).domain.equalsIgnoreCase(uri.getAuthority())){ new GetStatusByID(path.get(1)) .setCallback(new Callback<>(){ @Override @@ -698,7 +711,34 @@ public class UiUtils{ launchWebBrowser(context, url); } }) - .wrapProgress((Activity)context, R.string.loading, true) + .wrapProgress((Activity)context, R.string.loading, true, transformDialogForLookup) + .exec(accountID); + return; + } else { + new GetSearchResults(url, null, true) + .setCallback(new Callback<>() { + @Override + public void onSuccess(SearchResults results) { + Bundle args=new Bundle(); + args.putString("account", accountID); + if (!results.statuses.isEmpty()) { + args.putParcelable("status", Parcels.wrap(results.statuses.get(0))); + Nav.go((Activity) context, ThreadFragment.class, args); + } else if (!results.accounts.isEmpty()) { + args.putParcelable("profileAccount", Parcels.wrap(results.accounts.get(0))); + Nav.go((Activity) context, ProfileFragment.class, args); + } else { + launchWebBrowser(context, url); + } + } + + @Override + public void onError(ErrorResponse error) { + error.showToast(context); + launchWebBrowser(context, url); + } + }) + .wrapProgress((Activity)context, R.string.loading, true, transformDialogForLookup) .exec(accountID); return; } diff --git a/mastodon/src/main/res/values/strings.xml b/mastodon/src/main/res/values/strings.xml index ab17e434e..6a3a59c65 100644 --- a/mastodon/src/main/res/values/strings.xml +++ b/mastodon/src/main/res/values/strings.xml @@ -1,8 +1,8 @@ - Moshidon + Mastodon - Get started + Create account I already have an account Log in Next @@ -398,17 +398,6 @@ Remove bookmark Bookmarks Your Favorites - Always reveal content warnings - Disable scrolling text in title bars - Contribute to Moshidon - - - - - - - - Translate Welcome Back Log in with the server where you created your account. Server URL @@ -433,9 +422,5 @@ Not accepting new members Special Interests Passwords don\'t match - Language: %s - Available languages - %s (%s) - Clear recent languages - Are you sure you want to clear your recently used languages? + Looking it up on the Fediverse… \ No newline at end of file