Add activity for checking what apps manage links

This commit is contained in:
Thomas 2020-04-15 18:19:19 +02:00
parent c428b73439
commit 10df98119a
9 changed files with 285 additions and 205 deletions

View File

@ -193,7 +193,11 @@
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:theme="@style/AppTheme" />
<activity
android:name=".activities.CheckAppActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:theme="@style/AppTheme" />
<activity
android:name="app.fedilab.nitterizeme.activities.WebviewPlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"

View File

@ -0,0 +1,235 @@
package app.fedilab.nitterizeme.activities;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of UntrackMe
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* UntrackMe is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with UntrackMe; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import app.fedilab.nitterizeme.R;
import app.fedilab.nitterizeme.adapters.AppInfoAdapter;
import app.fedilab.nitterizeme.entities.AppInfo;
public class CheckAppActivity extends AppCompatActivity {
//Supported domains
public static String[] twitter_domains = {
"twitter.com",
"mobile.twitter.com",
"www.twitter.com",
"pbs.twimg.com",
"pic.twitter.com"
};
public static String[] instagram_domains = {
"instagram.com",
"www.instagram.com",
"m.instagram.com",
};
public static String[] youtube_domains = {
"www.youtube.com",
"youtube.com",
"m.youtube.com",
"youtu.be",
"youtube-nocookie.com"
};
public static String[] shortener_domains = {
"t.co",
"nyti.ms",
"bit.ly",
"tinyurl.com",
"goo.gl",
"ow.ly",
"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",
"invidious.13ad.de",
"yewtu.be"
};
public static String[] nitter_instances = {
"nitter.net",
"nitter.snopyta.org",
"nitter.42l.fr",
"nitter.13ad.de",
"tw.openalgeria.org",
"nitter.pussthecat.org",
"nitter.mastodont.cat",
"nitter.dark.fail",
"nitter.tedomum.net"
};
public static String[] bibliogram_instances = {
"bibliogram.art",
"bibliogram.snopyta.org",
"bibliogram.dsrev.ru",
"bibliogram.pussthecat.org"
};
private RecyclerView list_apps;
private String[] domains;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_app);
setTitle(R.string.check_apps);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
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;
i++;
}
for (String host : youtube_domains) {
domains[i] = host;
i++;
}
for (String host : instagram_domains) {
domains[i] = host;
i++;
}
for (String host : shortener_domains) {
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++;
}
list_apps = findViewById(R.id.list_apps);
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(CheckAppActivity.this);
list_apps.setLayoutManager(mLayoutManager);
list_apps.setNestedScrollingEnabled(false);
}
@Override
protected void onResume() {
super.onResume();
if (list_apps != null) {
ArrayList<AppInfo> appInfos = getAppInfo();
AppInfoAdapter appInfoAdapter = new AppInfoAdapter(appInfos);
list_apps.setAdapter(appInfoAdapter);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* Allow to get info about application that opens the link by default
*
* @param url String url for test
* @return ApplicationInfo info about the application
*/
ApplicationInfo getDefaultApp(String url) {
final Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
browserIntent.setData(Uri.parse(url));
final ResolveInfo defaultResolution = getPackageManager().resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (defaultResolution != null) {
final ActivityInfo activity = defaultResolution.activityInfo;
if (!activity.name.equals("com.android.internal.app.ResolverActivity") && !activity.packageName.equals("com.huawei.android.internal.app")) {
return activity.applicationInfo;
}
}
return null;
}
private ArrayList<AppInfo> getAppInfo() {
ArrayList<AppInfo> appInfos = new ArrayList<>();
int j = 0;
for (String domain : domains) {
if (j == 0) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle("Twitter");
appInfos.add(appInfo);
} else if (j == twitter_domains.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle("YouTube");
appInfos.add(appInfo);
} else if (j == twitter_domains.length + youtube_domains.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle("Instagram");
appInfos.add(appInfo);
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle(getString(R.string.shortener_services));
appInfos.add(appInfo);
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length + shortener_domains.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle(getString(R.string.invidious_instances));
appInfos.add(appInfo);
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length + shortener_domains.length + invidious_instances.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle(getString(R.string.nitter_instances));
appInfos.add(appInfo);
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length + shortener_domains.length + invidious_instances.length + nitter_instances.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle(getString(R.string.bibliogram_instances));
appInfos.add(appInfo);
}
AppInfo appInfo = new AppInfo();
appInfo.setDomain(domain);
appInfo.setApplicationInfo(getDefaultApp("https://" + domain + "/"));
appInfos.add(appInfo);
j++;
}
return appInfos;
}
}

View File

@ -17,10 +17,6 @@ package app.fedilab.nitterizeme.activities;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
@ -36,18 +32,13 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;
import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.Group;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputEditText;
import java.util.ArrayList;
import java.util.Objects;
import app.fedilab.nitterizeme.R;
import app.fedilab.nitterizeme.adapters.AppInfoAdapter;
import app.fedilab.nitterizeme.entities.AppInfo;
public class MainActivity extends AppCompatActivity {
@ -68,67 +59,7 @@ public class MainActivity extends AppCompatActivity {
public static String DEFAULT_BIBLIOGRAM_HOST = "bibliogram.art";
public static String SET_GEO_URIS = "set_geo_uris";
public static String SET_EMBEDDED_PLAYER = "set_embedded_player";
//Supported domains
public static String[] twitter_domains = {
"twitter.com",
"mobile.twitter.com",
"www.twitter.com",
"pbs.twimg.com",
"pic.twitter.com"
};
public static String[] instagram_domains = {
"instagram.com",
"www.instagram.com",
"m.instagram.com",
};
public static String[] youtube_domains = {
"www.youtube.com",
"youtube.com",
"m.youtube.com",
"youtu.be",
"youtube-nocookie.com"
};
public static String[] shortener_domains = {
"t.co",
"nyti.ms",
"bit.ly",
"tinyurl.com",
"goo.gl",
"ow.ly",
"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",
"invidious.13ad.de",
"yewtu.be"
};
public static String[] nitter_instances = {
"nitter.net",
"nitter.snopyta.org",
"nitter.42l.fr",
"nitter.13ad.de",
"tw.openalgeria.org",
"nitter.pussthecat.org",
"nitter.mastodont.cat",
"nitter.dark.fail",
"nitter.tedomum.net"
};
public static String[] bibliogram_instances = {
"bibliogram.art",
"bibliogram.snopyta.org",
"bibliogram.dsrev.ru",
"bibliogram.pussthecat.org"
};
private RecyclerView list_apps;
private String[] domains;
private String nitterHost;
private String invidiousHost;
@ -144,36 +75,6 @@ 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 + invidious_instances.length + nitter_instances.length + bibliogram_instances.length];
int i = 0;
for (String host : twitter_domains) {
domains[i] = host;
i++;
}
for (String host : youtube_domains) {
domains[i] = host;
i++;
}
for (String host : instagram_domains) {
domains[i] = host;
i++;
}
for (String host : shortener_domains) {
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);
@ -233,7 +134,7 @@ public class MainActivity extends AppCompatActivity {
CheckBox enable_geo_uris = findViewById(R.id.enable_geo_uris);
CheckBox enable_embed_player = findViewById(R.id.enable_embed_player);
list_apps = findViewById(R.id.list_apps);
nitterHost = sharedpreferences.getString(SET_NITTER_HOST, null);
invidiousHost = sharedpreferences.getString(SET_INVIDIOUS_HOST, null);
bibliogramHost = sharedpreferences.getString(SET_BIBLIOGRAM_HOST, null);
@ -451,15 +352,8 @@ public class MainActivity extends AppCompatActivity {
ImageButton buttonExpand = findViewById(R.id.button_expand);
buttonExpand.setOnClickListener(v -> {
if (list_apps.getVisibility() == View.VISIBLE) {
list_apps.setVisibility(View.GONE);
buttonExpand.setContentDescription(getString(R.string.display_supported_links));
buttonExpand.setImageResource(R.drawable.ic_expand_more);
} else {
list_apps.setVisibility(View.VISIBLE);
buttonExpand.setContentDescription(getString(R.string.hide_supported_links));
buttonExpand.setImageResource(R.drawable.ic_expand_less);
}
Intent intent = new Intent(MainActivity.this, CheckAppActivity.class);
startActivity(intent);
});
ImageButton buttonPing = findViewById(R.id.instances);
@ -538,33 +432,10 @@ public class MainActivity extends AppCompatActivity {
}
);
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(MainActivity.this);
list_apps.setLayoutManager(mLayoutManager);
list_apps.setNestedScrollingEnabled(false);
}
/**
* Allow to get info about application that opens the link by default
*
* @param url String url for test
* @return ApplicationInfo info about the application
*/
ApplicationInfo getDefaultApp(String url) {
final Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
browserIntent.setData(Uri.parse(url));
final ResolveInfo defaultResolution = getPackageManager().resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (defaultResolution != null) {
final ActivityInfo activity = defaultResolution.activityInfo;
if (!activity.name.equals("com.android.internal.app.ResolverActivity") && !activity.packageName.equals("com.huawei.android.internal.app")) {
return activity.applicationInfo;
}
}
return null;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
@ -588,11 +459,6 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onResume() {
super.onResume();
if (list_apps != null) {
ArrayList<AppInfo> appInfos = getAppInfo();
AppInfoAdapter appInfoAdapter = new AppInfoAdapter(appInfos);
list_apps.setAdapter(appInfoAdapter);
}
TextInputEditText nitter_instance = findViewById(R.id.nitter_instance);
TextInputEditText invidious_instance = findViewById(R.id.invidious_instance);
TextInputEditText bibliogram_instance = findViewById(R.id.bibliogram_instance);
@ -617,48 +483,5 @@ public class MainActivity extends AppCompatActivity {
bibliogram_instance.setText(bibliogramHost);
current_instance_bibliogram.setText(bibliogramHost);
}
}
private ArrayList<AppInfo> getAppInfo() {
ArrayList<AppInfo> appInfos = new ArrayList<>();
int j = 0;
for (String domain : domains) {
if (j == 0) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle("Twitter");
appInfos.add(appInfo);
} else if (j == twitter_domains.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle("YouTube");
appInfos.add(appInfo);
} else if (j == twitter_domains.length + youtube_domains.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle("Instagram");
appInfos.add(appInfo);
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle(getString(R.string.shortener_services));
appInfos.add(appInfo);
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length + shortener_domains.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle(getString(R.string.invidious_instances));
appInfos.add(appInfo);
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length + shortener_domains.length + invidious_instances.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle(getString(R.string.nitter_instances));
appInfos.add(appInfo);
} else if (j == twitter_domains.length + youtube_domains.length + instagram_domains.length + shortener_domains.length + invidious_instances.length + nitter_instances.length) {
AppInfo appInfo = new AppInfo();
appInfo.setTitle(getString(R.string.bibliogram_instances));
appInfos.add(appInfo);
}
AppInfo appInfo = new AppInfo();
appInfo.setDomain(domain);
appInfo.setApplicationInfo(getDefaultApp("https://" + domain + "/"));
appInfos.add(appInfo);
j++;
}
return appInfos;
}
}

View File

@ -51,17 +51,17 @@ import java.util.regex.Pattern;
import app.fedilab.nitterizeme.R;
import app.fedilab.nitterizeme.helpers.Utils;
import static app.fedilab.nitterizeme.activities.CheckAppActivity.bibliogram_instances;
import static app.fedilab.nitterizeme.activities.CheckAppActivity.instagram_domains;
import static app.fedilab.nitterizeme.activities.CheckAppActivity.invidious_instances;
import static app.fedilab.nitterizeme.activities.CheckAppActivity.nitter_instances;
import static app.fedilab.nitterizeme.activities.CheckAppActivity.shortener_domains;
import static app.fedilab.nitterizeme.activities.CheckAppActivity.twitter_domains;
import static app.fedilab.nitterizeme.activities.CheckAppActivity.youtube_domains;
import static app.fedilab.nitterizeme.activities.MainActivity.SET_BIBLIOGRAM_ENABLED;
import static app.fedilab.nitterizeme.activities.MainActivity.SET_EMBEDDED_PLAYER;
import static app.fedilab.nitterizeme.activities.MainActivity.SET_INVIDIOUS_ENABLED;
import static app.fedilab.nitterizeme.activities.MainActivity.SET_NITTER_ENABLED;
import static app.fedilab.nitterizeme.activities.MainActivity.bibliogram_instances;
import static app.fedilab.nitterizeme.activities.MainActivity.instagram_domains;
import static app.fedilab.nitterizeme.activities.MainActivity.invidious_instances;
import static app.fedilab.nitterizeme.activities.MainActivity.nitter_instances;
import static app.fedilab.nitterizeme.activities.MainActivity.shortener_domains;
import static app.fedilab.nitterizeme.activities.MainActivity.twitter_domains;
import static app.fedilab.nitterizeme.activities.MainActivity.youtube_domains;
public class TransformActivity extends Activity {

View File

@ -36,7 +36,7 @@ import java.util.regex.Pattern;
import javax.net.ssl.HttpsURLConnection;
import static android.content.Context.DOWNLOAD_SERVICE;
import static app.fedilab.nitterizeme.activities.MainActivity.shortener_domains;
import static app.fedilab.nitterizeme.activities.CheckAppActivity.shortener_domains;
public class Utils {

View File

@ -6,5 +6,5 @@
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,8l-6,6 1.41,1.41L12,10.83l4.59,4.58L18,14z" />
android:pathData="M4,8h4L8,4L4,4v4zM10,20h4v-4h-4v4zM4,20h4v-4L4,16v4zM4,14h4v-4L4,10v4zM10,14h4v-4h-4v4zM16,4v4h4L20,4h-4zM10,8h4L14,4h-4v4zM16,14h4v-4h-4v4zM16,20h4v-4h-4v4z" />
</vector>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?><!--
/* Copyright 2020 Thomas Schneider
*
* This file is a part of UntrackMe
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* UntrackMe is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with UntrackMe; if not,
* see <http://www.gnu.org/licenses>. */
-->
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.CheckAppActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_apps"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -638,7 +638,7 @@
style="@style/containerCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/list_apps"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/osm_container">
<Button
@ -679,7 +679,7 @@
android:layout_height="50dp"
android:layout_margin="5dp"
android:contentDescription="@string/display_supported_links"
android:src="@drawable/ic_expand_more"
android:src="@drawable/ic_apps"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="1"
@ -688,17 +688,6 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_apps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:minHeight="2100dp"
android:overScrollMode="never"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/buttons_container" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -30,7 +30,6 @@
<string name="redirect_gm_to_geo_uri">Redirect Google Map to Geo URI</string>
<string name="configure">Configure</string>
<string name="display_supported_links">Display supported links</string>
<string name="hide_supported_links">Hide supported links</string>
<string name="use_geo_uri">Use geo URI</string>
<string name="how_to">How-to</string>
<string name="shortened_detected">Shortened URL</string>
@ -56,4 +55,5 @@
<string name="share">Share</string>
<string name="download">Download</string>
<string name="share_with">Share with</string>
<string name="check_apps">Check apps</string>
</resources>