From c6460840f8074f05bbe8c7d219ec84d7b1063f25 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 2 Apr 2020 15:46:04 +0200 Subject: [PATCH] Add buff.ly unshorten support --- app/src/main/AndroidManifest.xml | 244 +++++++++++++++++- .../app/fedilab/nitterizeme/MainActivity.java | 38 ++- .../nitterizeme/TransformActivity.java | 74 +++++- .../metadata/android/en-US/changelogs/11.txt | 1 + 4 files changed, 342 insertions(+), 15 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2525308..f7beb3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,10 +34,8 @@ - - - - - - - @@ -170,7 +163,6 @@ android:host="ow.ly" android:mimeType="text/plain" /> - @@ -194,8 +186,6 @@ android:host="bl.ink" android:mimeType="text/plain" /> - - @@ -342,10 +332,8 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (); assert intent != null; //Dealing with URLs + + Log.v(MainActivity.TAG,"intent: " + intent); if (Objects.requireNonNull(intent.getAction()).equals(Intent.ACTION_VIEW)) { String url = Objects.requireNonNull(intent.getData()).toString(); + Log.v(MainActivity.TAG,"url: " + url); URL url_; String host = null; try { @@ -220,9 +229,11 @@ public class TransformActivity extends Activity { //Twitter URLs else if (Arrays.asList(twitter_domains).contains(host)) { boolean nitter_enabled = sharedpreferences.getBoolean(SET_NITTER_ENABLED, true); + Log.v(MainActivity.TAG,"nitter_enabled: " + nitter_enabled); if (nitter_enabled) { Intent delegate = new Intent(Intent.ACTION_VIEW); String transformedURL = transformUrl(url); + Log.v(MainActivity.TAG,"urlT: " + url); if (transformedURL != null) { delegate.setData(Uri.parse(transformUrl(url))); delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -296,6 +307,61 @@ public class TransformActivity extends Activity { forwardToBrowser(intent); } } + //Transform an Invidious URL from an instance to another one selected by the end user. + else if (Arrays.asList(invidious_instances).contains(host)) { + boolean invidious_enabled = sharedpreferences.getBoolean(SET_INVIDIOUS_ENABLED, true); + if (invidious_enabled) { + String invidiousHost = sharedpreferences.getString(MainActivity.SET_INVIDIOUS_HOST, MainActivity.DEFAULT_INVIDIOUS_HOST).toLowerCase(); + String transformedURL = url; + if( host != null && host.compareTo(invidiousHost) != 0 ){ + transformedURL = url.replace(host, invidiousHost); + } + Intent delegate = new Intent(Intent.ACTION_VIEW); + delegate.setData(Uri.parse(transformedURL)); + delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + if (delegate.resolveActivity(getPackageManager()) != null) { + startActivity(delegate); + finish(); + } + } else { + forwardToBrowser(intent); + } + } + //Transform a Nitter URL from an instance to another one selected by the end user. + else if (Arrays.asList(nitter_instances).contains(host)) { + boolean nitter_enabled = sharedpreferences.getBoolean(SET_NITTER_ENABLED, true); + if (nitter_enabled) { + String nitterHost = sharedpreferences.getString(MainActivity.SET_NITTER_HOST, MainActivity.DEFAULT_NITTER_HOST).toLowerCase(); + String transformedURL = url; + if( host != null && host.compareTo(nitterHost) != 0 ){ + transformedURL = url.replace(host, nitterHost); + } + intent.setData(Uri.parse(transformedURL)); + forwardToBrowser(intent); + } else { + forwardToBrowser(intent); + } + } + //Transform a Bibliogram URL from an instance to another one selected by the end user. + else if (Arrays.asList(bibliogram_instances).contains(host)) { + boolean bibliogram_enabled = sharedpreferences.getBoolean(SET_BIBLIOGRAM_ENABLED, true); + if (bibliogram_enabled) { + String bibliogramHost = sharedpreferences.getString(MainActivity.SET_BIBLIOGRAM_HOST, MainActivity.DEFAULT_BIBLIOGRAM_HOST).toLowerCase(); + String transformedURL = url; + if( host != null && host.compareTo(bibliogramHost) != 0 ){ + transformedURL = url.replace(host, bibliogramHost); + } + Intent delegate = new Intent(Intent.ACTION_VIEW); + delegate.setData(Uri.parse(transformedURL)); + delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + if (delegate.resolveActivity(getPackageManager()) != null) { + startActivity(delegate); + finish(); + } + } else { + forwardToBrowser(intent); + } + } } //It's a sharing intent @@ -320,7 +386,11 @@ public class TransformActivity extends Activity { private void forwardToBrowser(Intent i) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); - intent.setDataAndType(i.getData(), i.getType()); + String type = i.getType(); + if( type == null) { + type = "text/html"; + } + intent.setDataAndType(i.getData(), type); List activities = getPackageManager().queryIntentActivities(intent, 0); ArrayList targetIntents = new ArrayList<>(); String thisPackageName = getApplicationContext().getPackageName(); @@ -340,8 +410,8 @@ public class TransformActivity extends Activity { Intent chooserIntent = Intent.createChooser(targetIntents.remove(0), getString(R.string.open_with)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetIntents.toArray(new Parcelable[]{})); startActivity(chooserIntent); - finish(); } + finish(); } diff --git a/fastlane/metadata/android/en-US/changelogs/11.txt b/fastlane/metadata/android/en-US/changelogs/11.txt index 8f44426..06aa4b4 100644 --- a/fastlane/metadata/android/en-US/changelogs/11.txt +++ b/fastlane/metadata/android/en-US/changelogs/11.txt @@ -1,2 +1,3 @@ Added: +- Allow to redirect Invidious, Nitter and Bibliogram links from an instance to your selected one. - Unshorten support for buff.ly \ No newline at end of file