Add buff.ly unshorten support

This commit is contained in:
Thomas 2020-04-02 15:46:04 +02:00
parent f0cc359d27
commit c6460840f8
4 changed files with 342 additions and 15 deletions

View File

@ -34,10 +34,8 @@
<!-- t.co -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="t.co"
android:pathPattern=".*"
@ -57,10 +55,8 @@
<!-- nyti.ms -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="nyti.ms"
android:pathPattern=".*"
@ -80,10 +76,8 @@
<!-- bit.ly -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="bit.ly"
android:pathPattern=".*"
@ -146,7 +140,6 @@
android:host="goo.gl"
android:mimeType="text/plain" />
</intent-filter>
<!-- ow.ly -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@ -170,7 +163,6 @@
android:host="ow.ly"
android:mimeType="text/plain" />
</intent-filter>
<!-- bl.ink -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@ -194,8 +186,6 @@
android:host="bl.ink"
android:mimeType="text/plain" />
</intent-filter>
<!-- buff.ly -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@ -342,10 +332,8 @@
<!-- twitter.com -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="twitter.com"
android:pathPattern=".*"
@ -495,6 +483,238 @@
android:mimeType="text/plain"
android:pathPattern="/maps/place/.*" />
</intent-filter>
<!-- INSTANCES FOR REDIRECT TO THE PREFERRED ONES -->
<!-- NITTER INSTANCES -->
<!-- nitter.net -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="nitter.net"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="nitter.net"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- nitter.snopyta.org -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="nitter.snopyta.org"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="nitter.snopyta.org"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- nitter.42l.fr -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="nitter.42l.fr"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="nitter.42l.fr"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- nitter.nixnet.services -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="nitter.nixnet.services"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="nitter.nixnet.services"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- nitter.13ad.de -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="nitter.13ad.de"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="nitter.13ad.de"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- tw.openalgeria.org -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="tw.openalgeria.org"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="tw.openalgeria.org"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- nitter.pussthecat.org -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="nitter.pussthecat.org"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="nitter.pussthecat.org"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- INVIDIOUS INSTANCES -->
<!-- invidio.us -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="invidio.us"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="invidio.us"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- invidious.snopyta.org -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="invidious.snopyta.org"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="invidious.snopyta.org"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- invidiou.sh -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="invidiou.sh"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="invidiou.sh"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- invidious.toot.koeln -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="invidious.toot.koeln"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="invidious.toot.koeln"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- invidious.ggc-project.de -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="invidious.ggc-project.de"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="invidious.ggc-project.de"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- BIBLIOGRAM INSTANCES -->
<!-- bibliogram.art -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="bibliogram.art"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="bibliogram.art"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- bibliogram.snopyta.org -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="bibliogram.snopyta.org"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="bibliogram.snopyta.org"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- bibliogram.dsrev.ru -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="bibliogram.dsrev.ru"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="bibliogram.dsrev.ru"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
<!-- bibliogram.pussthecat.org -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="bibliogram.pussthecat.org"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="bibliogram.pussthecat.org"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
</activity>
<activity
android:name="app.fedilab.nitterizeme.InstanceActivity"

View File

@ -91,6 +91,30 @@ public class MainActivity extends AppCompatActivity {
"bl.ink",
"buff.ly"
};
//Supported instances to redirect one instance to another faster for the user
public static String[] invidious_instances = {
"invidio.us",
"invidious.snopyta.org",
"invidiou.sh",
"invidious.toot.koeln",
"invidious.ggc-project.de"
};
public static String[] nitter_instances = {
"nitter.net",
"nitter.snopyta.org",
"nitter.42l.fr",
"nitter.13ad.de",
"tw.openalgeria.org",
"nitter.pussthecat.org"
};
public static String[] bibliogram_instances = {
"bibliogram.art",
"bibliogram.snopyta.org",
"bibliogram.dsrev.ru",
"bibliogram.pussthecat.org"
};
private AppInfoAdapter appInfoAdapter;
private RecyclerView list_apps;
private String[] domains;
@ -109,7 +133,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 + instagram_domains.length];
domains = new String[twitter_domains.length + youtube_domains.length + shortener_domains.length + instagram_domains.length + invidious_instances.length + nitter_instances.length + bibliogram_instances.length];
int i = 0;
for (String host : twitter_domains) {
domains[i] = host;
@ -127,6 +151,18 @@ public class MainActivity extends AppCompatActivity {
domains[i] = host;
i++;
}
for (String host : invidious_instances) {
domains[i] = host;
i++;
}
for (String host : nitter_instances) {
domains[i] = host;
i++;
}
for (String host : bibliogram_instances) {
domains[i] = host;
i++;
}
SharedPreferences sharedpreferences = getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);

View File

@ -19,6 +19,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
@ -26,6 +27,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcelable;
import android.util.Log;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
@ -47,7 +49,10 @@ 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.bibliogram_instances;
import static app.fedilab.nitterizeme.MainActivity.instagram_domains;
import static app.fedilab.nitterizeme.MainActivity.invidious_instances;
import static app.fedilab.nitterizeme.MainActivity.nitter_instances;
import static app.fedilab.nitterizeme.MainActivity.shortener_domains;
import static app.fedilab.nitterizeme.MainActivity.twitter_domains;
import static app.fedilab.nitterizeme.MainActivity.youtube_domains;
@ -70,6 +75,7 @@ public class TransformActivity extends Activity {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(MainActivity.APP_PREFS, Context.MODE_PRIVATE);
Intent intent = getIntent();
Log.v(MainActivity.TAG,"intent: " + intent);
if (intent != null && intent.getStringExtra("nitterizeme") != null) {
finish();
return;
@ -77,9 +83,12 @@ public class TransformActivity extends Activity {
notShortnedURLDialog = new ArrayList<>();
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<ResolveInfo> activities = getPackageManager().queryIntentActivities(intent, 0);
ArrayList<Intent> 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();
}

View File

@ -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