open externally opened content in main activity
closes sk22#533
This commit is contained in:
@@ -42,7 +42,17 @@ public class ExternalShareActivity extends FragmentStackActivity{
|
|||||||
new AccountSwitcherSheet(this, null, true, isMastodonURL, (accountId, open) -> {
|
new AccountSwitcherSheet(this, null, true, isMastodonURL, (accountId, open) -> {
|
||||||
AccountSessionManager.getInstance().setLastActiveAccountID(accountId);
|
AccountSessionManager.getInstance().setLastActiveAccountID(accountId);
|
||||||
if (open) {
|
if (open) {
|
||||||
UiUtils.openURL(this, AccountSessionManager.getInstance().getLastActiveAccountID(), text, false);
|
UiUtils.lookupURL(this, accountId, text, false, (clazz, args) -> {
|
||||||
|
if (clazz == null) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
args.putString("fromExternalShare", clazz.getSimpleName());
|
||||||
|
Intent intent = new Intent(this, MainActivity.class);
|
||||||
|
intent.putExtras(args);
|
||||||
|
finish();
|
||||||
|
startActivity(intent);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
openComposeFragment(accountId);
|
openComposeFragment(accountId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ public class MainActivity extends FragmentStackActivity{
|
|||||||
AccountSession session;
|
AccountSession session;
|
||||||
Bundle args=new Bundle();
|
Bundle args=new Bundle();
|
||||||
Intent intent=getIntent();
|
Intent intent=getIntent();
|
||||||
|
if(intent.hasExtra("fromExternalShare")) {
|
||||||
|
showFragmentForExternalShare(intent.getExtras());
|
||||||
|
return;
|
||||||
|
}
|
||||||
boolean fromNotification = intent.getBooleanExtra("fromNotification", false);
|
boolean fromNotification = intent.getBooleanExtra("fromNotification", false);
|
||||||
boolean hasNotification = intent.hasExtra("notification");
|
boolean hasNotification = intent.hasExtra("notification");
|
||||||
if(fromNotification){
|
if(fromNotification){
|
||||||
@@ -75,7 +79,8 @@ public class MainActivity extends FragmentStackActivity{
|
|||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent){
|
protected void onNewIntent(Intent intent){
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
if(intent.getBooleanExtra("fromNotification", false)){
|
if(intent.hasExtra("fromExternalShare")) showFragmentForExternalShare(intent.getExtras());
|
||||||
|
else if(intent.getBooleanExtra("fromNotification", false)){
|
||||||
String accountID=intent.getStringExtra("accountID");
|
String accountID=intent.getStringExtra("accountID");
|
||||||
AccountSession accountSession;
|
AccountSession accountSession;
|
||||||
try{
|
try{
|
||||||
@@ -124,6 +129,19 @@ public class MainActivity extends FragmentStackActivity{
|
|||||||
showFragment(fragment);
|
showFragment(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showFragmentForExternalShare(Bundle args) {
|
||||||
|
String clazz = args.getString("fromExternalShare");
|
||||||
|
Fragment fragment = switch (clazz) {
|
||||||
|
case "ThreadFragment" -> new ThreadFragment();
|
||||||
|
case "ProfileFragment" -> new ProfileFragment();
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
if (fragment == null) return;
|
||||||
|
args.putBoolean("_can_go_back", true);
|
||||||
|
fragment.setArguments(args);
|
||||||
|
showFragment(fragment);
|
||||||
|
}
|
||||||
|
|
||||||
private void showCompose(){
|
private void showCompose(){
|
||||||
AccountSession session=AccountSessionManager.getInstance().getLastActiveAccount();
|
AccountSession session=AccountSessionManager.getInstance().getLastActiveAccount();
|
||||||
if(session==null || !session.activated)
|
if(session==null || !session.activated)
|
||||||
@@ -153,18 +171,23 @@ public class MainActivity extends FragmentStackActivity{
|
|||||||
(fragmentContainers.get(fragmentContainers.size() - 1)).getId()
|
(fragmentContainers.get(fragmentContainers.size() - 1)).getId()
|
||||||
);
|
);
|
||||||
Bundle currentArgs = currentFragment.getArguments();
|
Bundle currentArgs = currentFragment.getArguments();
|
||||||
if (this.fragmentContainers.size() == 1
|
if (fragmentContainers.size() != 1
|
||||||
&& currentArgs != null
|
|| currentArgs == null
|
||||||
&& currentArgs.getBoolean("_can_go_back", false)
|
|| !currentArgs.getBoolean("_can_go_back", false)) {
|
||||||
&& currentArgs.containsKey("account")) {
|
super.onBackPressed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (currentArgs.getBoolean("_finish_on_back", false)) {
|
||||||
|
finish();
|
||||||
|
} else if (currentArgs.containsKey("account")) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString("account", currentArgs.getString("account"));
|
args.putString("account", currentArgs.getString("account"));
|
||||||
args.putString("tab", "notifications");
|
if (getIntent().getBooleanExtra("fromNotification", false)) {
|
||||||
|
args.putString("tab", "notifications");
|
||||||
|
}
|
||||||
Fragment fragment=new HomeFragment();
|
Fragment fragment=new HomeFragment();
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
showFragmentClearingBackStack(fragment);
|
showFragmentClearingBackStack(fragment);
|
||||||
} else {
|
|
||||||
super.onBackPressed();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import static org.joinmastodon.android.GlobalUserPreferences.trueBlackTheme;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Fragment;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
@@ -110,6 +111,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -1080,6 +1082,13 @@ public class UiUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void openURL(Context context, String accountID, String url, boolean launchBrowser) {
|
public static void openURL(Context context, String accountID, String url, boolean launchBrowser) {
|
||||||
|
lookupURL(context, accountID, url, launchBrowser, (clazz, args) -> {
|
||||||
|
if (clazz == null) return;
|
||||||
|
Nav.go((Activity) context, clazz, args);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void 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())) {
|
||||||
@@ -1091,13 +1100,14 @@ public class UiUtils {
|
|||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString("account", accountID);
|
args.putString("account", accountID);
|
||||||
args.putParcelable("status", Parcels.wrap(result));
|
args.putParcelable("status", Parcels.wrap(result));
|
||||||
Nav.go((Activity) context, ThreadFragment.class, args);
|
go.accept(ThreadFragment.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(ErrorResponse error) {
|
public void onError(ErrorResponse error) {
|
||||||
error.showToast(context);
|
error.showToast(context);
|
||||||
if (launchBrowser) launchWebBrowser(context, url);
|
if (launchBrowser) launchWebBrowser(context, url);
|
||||||
|
go.accept(null, null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.wrapProgress((Activity) context, R.string.loading, true,
|
.wrapProgress((Activity) context, R.string.loading, true,
|
||||||
@@ -1113,27 +1123,26 @@ public class UiUtils {
|
|||||||
args.putString("account", accountID);
|
args.putString("account", accountID);
|
||||||
if (!results.statuses.isEmpty()) {
|
if (!results.statuses.isEmpty()) {
|
||||||
args.putParcelable("status", Parcels.wrap(results.statuses.get(0)));
|
args.putParcelable("status", Parcels.wrap(results.statuses.get(0)));
|
||||||
Nav.go((Activity) context, ThreadFragment.class, args);
|
go.accept(ThreadFragment.class, args);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Optional<Account> account = results.accounts.stream()
|
Optional<Account> account = results.accounts.stream()
|
||||||
.filter(a -> uri.equals(Uri.parse(a.url))).findAny();
|
.filter(a -> uri.equals(Uri.parse(a.url))).findAny();
|
||||||
if (account.isPresent()) {
|
if (account.isPresent()) {
|
||||||
args.putParcelable("profileAccount", Parcels.wrap(account.get()));
|
args.putParcelable("profileAccount", Parcels.wrap(account.get()));
|
||||||
Nav.go((Activity) context, ProfileFragment.class, args);
|
go.accept(ProfileFragment.class, args);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (launchBrowser) {
|
|
||||||
launchWebBrowser(context, url);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (launchBrowser) launchWebBrowser(context, url);
|
||||||
Toast.makeText(context, R.string.sk_resource_not_found, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, R.string.sk_resource_not_found, Toast.LENGTH_SHORT).show();
|
||||||
|
go.accept(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(ErrorResponse error) {
|
public void onError(ErrorResponse error) {
|
||||||
error.showToast(context);
|
error.showToast(context);
|
||||||
if (launchBrowser) launchWebBrowser(context, url);
|
if (launchBrowser) launchWebBrowser(context, url);
|
||||||
|
go.accept(null, null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.wrapProgress((Activity) context, R.string.loading, true,
|
.wrapProgress((Activity) context, R.string.loading, true,
|
||||||
@@ -1142,7 +1151,8 @@ public class UiUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
launchWebBrowser(context, url);
|
if (launchBrowser) launchWebBrowser(context, url);
|
||||||
|
go.accept(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyText(View v, String text) {
|
public static void copyText(View v, String text) {
|
||||||
|
|||||||
Reference in New Issue
Block a user