From 9a64dd60b00bd58debaec434fdb368b5f093621f Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 16 Nov 2022 17:22:26 +0100 Subject: [PATCH] Open link with the app. --- app/src/main/AndroidManifest.xml | 12 ++++ .../app/fedilab/android/BaseMainActivity.java | 72 ++++++++++++++++++- .../app/fedilab/android/helper/Helper.java | 29 ++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1b449cdeb..e2f3019bd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -56,6 +56,18 @@ + + + + + + + + + 0) { //It's a toot + CrossActionHelper.fetchRemoteStatus(BaseMainActivity.this, currentAccount, url, new CrossActionHelper.Callback() { + @Override + public void federatedStatus(Status status) { + Intent intent = new Intent(BaseMainActivity.this, ContextActivity.class); + intent.putExtra(Helper.ARG_STATUS, status); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + + @Override + public void federatedAccount(app.fedilab.android.client.entities.api.Account account) { + } + }); + } else {//It's an account + CrossActionHelper.fetchRemoteAccount(BaseMainActivity.this, currentAccount, matcherLink.group(2) + "@" + matcherLink.group(1), new CrossActionHelper.Callback() { + @Override + public void federatedStatus(Status status) { + } + + @Override + public void federatedAccount(app.fedilab.android.client.entities.api.Account account) { + Intent intent = new Intent(BaseMainActivity.this, ProfileActivity.class); + Bundle b = new Bundle(); + b.putSerializable(Helper.ARG_ACCOUNT, account); + intent.putExtras(b); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + }); + } + } else { + Helper.forwardToBrowser(BaseMainActivity.this, intent); + } + } else { + Helper.forwardToBrowser(BaseMainActivity.this, intent); + } + } + intent.replaceExtras(new Bundle()); + intent.setAction(""); + intent.setData(null); + intent.setFlags(0); } private void manageFilters(int position) { diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 3f74cd0d8..7a71a73b4 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -26,11 +26,13 @@ import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; +import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; @@ -53,6 +55,7 @@ import android.os.CountDownTimer; import android.os.Environment; import android.os.Handler; import android.os.Looper; +import android.os.Parcelable; import android.provider.MediaStore; import android.provider.OpenableColumns; import android.text.TextUtils; @@ -1914,6 +1917,32 @@ public class Helper { Runtime.getRuntime().exit(0); } + + public static void forwardToBrowser(Activity activity, Intent i) { + Intent intent = new Intent(); + intent.setAction(android.content.Intent.ACTION_VIEW); + intent.setDataAndType(i.getData(), i.getType()); + List activities = activity.getPackageManager().queryIntentActivities(intent, 0); + ArrayList targetIntents = new ArrayList<>(); + String thisPackageName = activity.getPackageName(); + for (ResolveInfo currentInfo : activities) { + String packageName = currentInfo.activityInfo.packageName; + if (!thisPackageName.equals(packageName)) { + Intent targetIntent = new Intent(android.content.Intent.ACTION_VIEW); + targetIntent.setDataAndType(intent.getData(), intent.getType()); + targetIntent.setPackage(intent.getPackage()); + targetIntent.setComponent(new ComponentName(packageName, currentInfo.activityInfo.name)); + targetIntents.add(targetIntent); + } + } + if (targetIntents.size() > 0) { + Intent chooserIntent = Intent.createChooser(targetIntents.remove(0), activity.getString(R.string.open_with)); + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetIntents.toArray(new Parcelable[]{})); + activity.startActivity(chooserIntent); + } + } + + //Enum that described actions to replace inside a toot content public enum PatternType { MENTION,