resolve fediverse links in app
closes sk22#177 closes sk22#96
This commit is contained in:
parent
f46ce5576c
commit
7c789746ce
|
@ -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<T> extends APIRequest<T>{
|
|||
}
|
||||
|
||||
public MastodonAPIRequest<T> wrapProgress(Activity activity, @StringRes int message, boolean cancelable){
|
||||
return wrapProgress(activity, message, cancelable, null);
|
||||
}
|
||||
|
||||
public MastodonAPIRequest<T> wrapProgress(Activity activity, @StringRes int message, boolean cancelable, Consumer<ProgressDialog> 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());
|
||||
}
|
||||
|
|
|
@ -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<ProgressDialog> 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<String> 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]+$")){
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name" translatable="false">Moshidon</string>
|
||||
<string name="app_name" translatable="false">Mastodon</string>
|
||||
|
||||
<string name="get_started">Get started</string>
|
||||
<string name="get_started">Create account</string>
|
||||
<string name="already_have_account">I already have an account</string>
|
||||
<string name="log_in">Log in</string>
|
||||
<string name="next">Next</string>
|
||||
|
@ -398,17 +398,6 @@
|
|||
<string name="remove_bookmark">Remove bookmark</string>
|
||||
<string name="bookmarks">Bookmarks</string>
|
||||
<string name="your_favorites">Your Favorites</string>
|
||||
<string name="settings_always_reveal_content_warnings">Always reveal content warnings</string>
|
||||
<string name="disable_marquee">Disable scrolling text in title bars</string>
|
||||
<string name="settings_contribute_fork">Contribute to Moshidon</string>
|
||||
<!-- <string name="settings_color_picker">Color theme:</string>-->
|
||||
<!-- <string name="pink_color">Pink</string>-->
|
||||
<!-- <string name="purple_color">Purple</string>-->
|
||||
<!-- <string name="green_color">Green</string>-->
|
||||
<!-- <string name="blue_color">Blue</string>-->
|
||||
<!-- <string name="orange_color">Orange</string>-->
|
||||
<!-- <string name="yellow_color">Yellow</string>-->
|
||||
<string name="translate">Translate</string>
|
||||
<string name="login_title">Welcome Back</string>
|
||||
<string name="login_subtitle">Log in with the server where you created your account.</string>
|
||||
<string name="server_url">Server URL</string>
|
||||
|
@ -433,9 +422,5 @@
|
|||
<string name="not_accepting_new_members">Not accepting new members</string>
|
||||
<string name="category_special_interests">Special Interests</string>
|
||||
<string name="signup_passwords_dont_match">Passwords don\'t match</string>
|
||||
<string name="post_language">Language: %s</string>
|
||||
<string name="available_languages">Available languages</string>
|
||||
<string name="language_name">%s (%s)</string>
|
||||
<string name="clear_recent_languages">Clear recent languages</string>
|
||||
<string name="confirm_clear_recent_languages">Are you sure you want to clear your recently used languages?</string>
|
||||
<string name="loading_fediverse_resource_title">Looking it up on the Fediverse…</string>
|
||||
</resources>
|
Loading…
Reference in New Issue