fix issues with external share
closes sk22#550
This commit is contained in:
@@ -9,6 +9,7 @@ import android.text.TextUtils;
|
|||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
import org.joinmastodon.android.api.session.AccountSession;
|
import org.joinmastodon.android.api.session.AccountSession;
|
||||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
import org.joinmastodon.android.fragments.ComposeFragment;
|
import org.joinmastodon.android.fragments.ComposeFragment;
|
||||||
@@ -43,7 +44,7 @@ public class ExternalShareActivity extends FragmentStackActivity{
|
|||||||
finish();
|
finish();
|
||||||
} else if (isOpenable || sessions.size() > 1) {
|
} else if (isOpenable || sessions.size() > 1) {
|
||||||
AccountSwitcherSheet sheet = new AccountSwitcherSheet(this, null, true, isOpenable);
|
AccountSwitcherSheet sheet = new AccountSwitcherSheet(this, null, true, isOpenable);
|
||||||
if (isOpenable) sheet.setOnClick((accountId, open) -> {
|
sheet.setOnClick((accountId, open) -> {
|
||||||
if (open && text.isPresent()) {
|
if (open && text.isPresent()) {
|
||||||
BiConsumer<Class<? extends Fragment>, Bundle> callback = (clazz, args) -> {
|
BiConsumer<Class<? extends Fragment>, Bundle> callback = (clazz, args) -> {
|
||||||
if (clazz == null) {
|
if (clazz == null) {
|
||||||
@@ -59,8 +60,17 @@ public class ExternalShareActivity extends FragmentStackActivity{
|
|||||||
finish();
|
finish();
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
};
|
};
|
||||||
if (isFediUrl) UiUtils.lookupURL(this, accountId, text.get(), false, callback);
|
|
||||||
else UiUtils.lookupAccountHandle(this, accountId, fediHandle.get(), callback);
|
fediHandle
|
||||||
|
.<MastodonAPIRequest<?>>map(handle ->
|
||||||
|
UiUtils.lookupAccountHandle(this, accountId, handle, callback))
|
||||||
|
.or(() -> Optional.ofNullable(
|
||||||
|
UiUtils.lookupURL(this, accountId, text.get(), false, callback)))
|
||||||
|
.ifPresent(req ->
|
||||||
|
req.wrapProgress(this, R.string.loading, true, d -> {
|
||||||
|
UiUtils.transformDialogForLookup(this, accountId, isFediUrl ? text.get() : null, d);
|
||||||
|
d.setOnDismissListener((ev) -> finish());
|
||||||
|
}));
|
||||||
} else {
|
} else {
|
||||||
openComposeFragment(accountId);
|
openComposeFragment(accountId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ public class MainActivity extends FragmentStackActivity implements ProvidesAssis
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showFragmentForExternalShare(Bundle args) {
|
private void showFragmentForExternalShare(Bundle args) {
|
||||||
String clazz = args.getString("fromExternalShare");
|
String className = args.getString("fromExternalShare");
|
||||||
Fragment fragment = switch (clazz) {
|
Fragment fragment = switch (className) {
|
||||||
case "ThreadFragment" -> new ThreadFragment();
|
case "ThreadFragment" -> new ThreadFragment();
|
||||||
case "ProfileFragment" -> new ProfileFragment();
|
case "ProfileFragment" -> new ProfileFragment();
|
||||||
default -> null;
|
default -> null;
|
||||||
|
|||||||
@@ -75,8 +75,7 @@ public class AccountSwitcherSheet extends BottomSheet{
|
|||||||
this.fragment=fragment;
|
this.fragment=fragment;
|
||||||
this.externalShare = externalShare;
|
this.externalShare = externalShare;
|
||||||
this.openInApp = openInApp;
|
this.openInApp = openInApp;
|
||||||
this.onClick = onClick;
|
|
||||||
|
|
||||||
accounts=AccountSessionManager.getInstance().getLoggedInAccounts().stream().map(WrappedAccount::new).collect(Collectors.toList());
|
accounts=AccountSessionManager.getInstance().getLoggedInAccounts().stream().map(WrappedAccount::new).collect(Collectors.toList());
|
||||||
|
|
||||||
list=new UsableRecyclerView(activity);
|
list=new UsableRecyclerView(activity);
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ import org.joinmastodon.android.E;
|
|||||||
import org.joinmastodon.android.GlobalUserPreferences;
|
import org.joinmastodon.android.GlobalUserPreferences;
|
||||||
import org.joinmastodon.android.MastodonApp;
|
import org.joinmastodon.android.MastodonApp;
|
||||||
import org.joinmastodon.android.R;
|
import org.joinmastodon.android.R;
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
import org.joinmastodon.android.api.MastodonErrorResponse;
|
import org.joinmastodon.android.api.MastodonErrorResponse;
|
||||||
import org.joinmastodon.android.api.StatusInteractionController;
|
import org.joinmastodon.android.api.StatusInteractionController;
|
||||||
import org.joinmastodon.android.api.requests.accounts.SetAccountBlocked;
|
import org.joinmastodon.android.api.requests.accounts.SetAccountBlocked;
|
||||||
@@ -1095,7 +1096,7 @@ public class UiUtils {
|
|||||||
openURL(context, accountID, url, true);
|
openURL(context, accountID, url, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void transformDialogForLookup(Context context, String accountID, @Nullable String url, ProgressDialog dialog) {
|
public static void transformDialogForLookup(Context context, String accountID, @Nullable String url, ProgressDialog dialog) {
|
||||||
if (accountID != null) {
|
if (accountID != null) {
|
||||||
dialog.setTitle(context.getString(R.string.sk_loading_resource_on_instance_title, getInstanceName(accountID)));
|
dialog.setTitle(context.getString(R.string.sk_loading_resource_on_instance_title, getInstanceName(accountID)));
|
||||||
} else {
|
} else {
|
||||||
@@ -1114,7 +1115,8 @@ public class UiUtils {
|
|||||||
lookupURL(context, accountID, url, launchBrowser, (clazz, args) -> {
|
lookupURL(context, accountID, url, launchBrowser, (clazz, args) -> {
|
||||||
if (clazz == null) return;
|
if (clazz == null) return;
|
||||||
Nav.go((Activity) context, clazz, args);
|
Nav.go((Activity) context, clazz, args);
|
||||||
});
|
}).wrapProgress((Activity) context, R.string.loading, true, d ->
|
||||||
|
transformDialogForLookup(context, accountID, url, d));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean acctMatches(String accountID, String acct, String queriedUsername, @Nullable String queriedDomain) {
|
public static boolean acctMatches(String accountID, String acct, String queriedUsername, @Nullable String queriedDomain) {
|
||||||
@@ -1143,9 +1145,9 @@ public class UiUtils {
|
|||||||
() -> go.accept(null, null)
|
() -> go.accept(null, null)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
public static void lookupAccountHandle(Context context, String accountID, Pair<String, Optional<String>> queryHandle, BiConsumer<Class<? extends Fragment>, Bundle> go) {
|
public static MastodonAPIRequest<SearchResults> lookupAccountHandle(Context context, String accountID, Pair<String, Optional<String>> queryHandle, BiConsumer<Class<? extends Fragment>, Bundle> go) {
|
||||||
String fullHandle = ("@" + queryHandle.first) + (queryHandle.second.map(domain -> "@" + domain).orElse(""));
|
String fullHandle = ("@" + queryHandle.first) + (queryHandle.second.map(domain -> "@" + domain).orElse(""));
|
||||||
new GetSearchResults(fullHandle, GetSearchResults.Type.ACCOUNTS, true)
|
return new GetSearchResults(fullHandle, GetSearchResults.Type.ACCOUNTS, true)
|
||||||
.setCallback(new Callback<>() {
|
.setCallback(new Callback<>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(SearchResults results) {
|
public void onSuccess(SearchResults results) {
|
||||||
@@ -1176,12 +1178,12 @@ public class UiUtils {
|
|||||||
}).exec(accountID);
|
}).exec(accountID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void lookupURL(Context context, String accountID, String url, boolean launchBrowser, BiConsumer<Class<? extends Fragment>, Bundle> go) {
|
public static MastodonAPIRequest<?> lookupURL(Context context, String accountID, String url, boolean launchBrowser, BiConsumer<Class<? extends Fragment>, Bundle> go) {
|
||||||
Uri uri = Uri.parse(url);
|
Uri uri = Uri.parse(url);
|
||||||
List<String> path = uri.getPathSegments();
|
List<String> path = uri.getPathSegments();
|
||||||
if (accountID != null && "https".equals(uri.getScheme())) {
|
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())) {
|
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))
|
return new GetStatusByID(path.get(1))
|
||||||
.setCallback(new Callback<>() {
|
.setCallback(new Callback<>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Status result) {
|
public void onSuccess(Status result) {
|
||||||
@@ -1198,12 +1200,9 @@ public class UiUtils {
|
|||||||
go.accept(null, null);
|
go.accept(null, null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.wrapProgress((Activity) context, R.string.loading, true,
|
|
||||||
d -> transformDialogForLookup(context, accountID, url, d))
|
|
||||||
.exec(accountID);
|
.exec(accountID);
|
||||||
return;
|
|
||||||
} else if (looksLikeFediverseUrl(url)) {
|
} else if (looksLikeFediverseUrl(url)) {
|
||||||
new GetSearchResults(url, null, true)
|
return new GetSearchResults(url, null, true)
|
||||||
.setCallback(new Callback<>() {
|
.setCallback(new Callback<>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(SearchResults results) {
|
public void onSuccess(SearchResults results) {
|
||||||
@@ -1233,14 +1232,12 @@ public class UiUtils {
|
|||||||
go.accept(null, null);
|
go.accept(null, null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.wrapProgress((Activity) context, R.string.loading, true,
|
|
||||||
d -> transformDialogForLookup(context, accountID, url, d))
|
|
||||||
.exec(accountID);
|
.exec(accountID);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (launchBrowser) launchWebBrowser(context, url);
|
if (launchBrowser) launchWebBrowser(context, url);
|
||||||
go.accept(null, null);
|
go.accept(null, null);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyText(View v, String text) {
|
public static void copyText(View v, String text) {
|
||||||
|
|||||||
Reference in New Issue
Block a user