From 10ced0b09c386429602d089d8b369791b64af099 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 19 Feb 2020 08:52:36 +0100 Subject: [PATCH] Fix #3 - Support Bibliogram --- .../app/fedilab/nitterizeme/MainActivity.java | 2 +- .../nitterizeme/TransformActivity.java | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/app/fedilab/nitterizeme/MainActivity.java b/app/src/main/java/app/fedilab/nitterizeme/MainActivity.java index acde53f..8e2f0ad 100644 --- a/app/src/main/java/app/fedilab/nitterizeme/MainActivity.java +++ b/app/src/main/java/app/fedilab/nitterizeme/MainActivity.java @@ -101,7 +101,7 @@ public class MainActivity extends AppCompatActivity { Objects.requireNonNull(getSupportActionBar()).setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - domains = new String[twitter_domains.length + youtube_domains.length + shortener_domains.length]; + domains = new String[twitter_domains.length + youtube_domains.length + shortener_domains.length + instagram_domains.length]; int i = 0; for (String host : twitter_domains) { domains[i] = host; diff --git a/app/src/main/java/app/fedilab/nitterizeme/TransformActivity.java b/app/src/main/java/app/fedilab/nitterizeme/TransformActivity.java index 5eb7ff6..3a6dc87 100644 --- a/app/src/main/java/app/fedilab/nitterizeme/TransformActivity.java +++ b/app/src/main/java/app/fedilab/nitterizeme/TransformActivity.java @@ -44,8 +44,10 @@ import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static app.fedilab.nitterizeme.MainActivity.SET_BIBLIOGRAM_ENABLED; import static app.fedilab.nitterizeme.MainActivity.SET_INVIDIOUS_ENABLED; import static app.fedilab.nitterizeme.MainActivity.SET_NITTER_ENABLED; +import static app.fedilab.nitterizeme.MainActivity.instagram_domains; import static app.fedilab.nitterizeme.MainActivity.shortener_domains; import static app.fedilab.nitterizeme.MainActivity.twitter_domains; import static app.fedilab.nitterizeme.MainActivity.youtube_domains; @@ -56,6 +58,7 @@ public class TransformActivity extends Activity { final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)/(((?!([\"'<])).)*)"); final Pattern nitterPattern = Pattern.compile("(mobile\\.|www\\.)?twitter.com([\\w-/]+)"); + final Pattern bibliogramPattern = Pattern.compile("(m\\.|www\\.)?instagram.com([\\w-/]+)"); final Pattern maps = Pattern.compile("/maps/place/[^@]+@([\\d.,z]{3,}).*"); final Pattern extractPlace = Pattern.compile("/maps/place/(((?!/data).)*)"); private Thread thread; @@ -226,6 +229,24 @@ public class TransformActivity extends Activity { } else { forwardToBrowser(intent); } + } //Instagram URLs + else if (Arrays.asList(instagram_domains).contains(host)) { + boolean bibliogram_enabled = sharedpreferences.getBoolean(SET_BIBLIOGRAM_ENABLED, true); + if (bibliogram_enabled) { + Intent delegate = new Intent(Intent.ACTION_VIEW); + String transformedURL = transformUrl(url); + if (transformedURL != null) { + delegate.setData(Uri.parse(transformUrl(url))); + delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + if (delegate.resolveActivity(getPackageManager()) != null) { + startActivity(delegate); + } + } else { + forwardToBrowser(intent); + } + } else { + forwardToBrowser(intent); + } } //Maps URLs (containing /maps/place like Google Maps links) else if (url.contains("/maps/place")) { @@ -345,6 +366,19 @@ public class TransformActivity extends Activity { } else { return url; } + }else if (Arrays.asList(instagram_domains).contains(host)) { + boolean bibliogram_enabled = sharedpreferences.getBoolean(SET_BIBLIOGRAM_ENABLED, true); + if (bibliogram_enabled) { + Matcher matcher = bibliogramPattern.matcher(url); + while (matcher.find()) { + final String bibliogram_directory = matcher.group(2); + String bibliogramHost = sharedpreferences.getString(MainActivity.SET_BIBLIOGRAM_HOST, MainActivity.DEFAULT_BIBLIOGRAM_HOST).toLowerCase(); + newUrl = "https://" + bibliogramHost + bibliogram_directory; + } + return newUrl; + } else { + return url; + } } else if (url.contains("/maps/place")) { boolean osm_enabled = sharedpreferences.getBoolean(MainActivity.SET_OSM_ENABLED, true); if (osm_enabled) { @@ -455,6 +489,16 @@ public class TransformActivity extends Activity { newUrl = "https://" + nitterHost + nitter_directory; } } + } else if (Arrays.asList(instagram_domains).contains(host)) { + boolean bibliogram_enabled = sharedpreferences.getBoolean(SET_BIBLIOGRAM_ENABLED, true); + if (bibliogram_enabled) { + Matcher matcher = bibliogramPattern.matcher(url); + while (matcher.find()) { + final String bibliogram_directory = matcher.group(2); + String bibliogramHost = sharedpreferences.getString(MainActivity.SET_BIBLIOGRAM_HOST, MainActivity.DEFAULT_BIBLIOGRAM_HOST).toLowerCase(); + newUrl = "https://" + bibliogramHost + bibliogram_directory; + } + } } else if (url.contains("/maps/place/")) { boolean osm_enabled = sharedpreferences.getBoolean(MainActivity.SET_OSM_ENABLED, true); if (osm_enabled) {