diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 134c48d..27b8f63 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -193,7 +193,11 @@ android:configChanges="orientation|screenSize" android:label="@string/app_name" android:theme="@style/AppTheme" /> - + . */ + + +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 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 getAppInfo() { + ArrayList 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; + } + +} diff --git a/app/src/main/java/app/fedilab/nitterizeme/activities/MainActivity.java b/app/src/main/java/app/fedilab/nitterizeme/activities/MainActivity.java index 55e226b..4377655 100644 --- a/app/src/main/java/app/fedilab/nitterizeme/activities/MainActivity.java +++ b/app/src/main/java/app/fedilab/nitterizeme/activities/MainActivity.java @@ -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 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 getAppInfo() { - ArrayList 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; } } diff --git a/app/src/main/java/app/fedilab/nitterizeme/activities/TransformActivity.java b/app/src/main/java/app/fedilab/nitterizeme/activities/TransformActivity.java index 2821c13..3f9b45c 100644 --- a/app/src/main/java/app/fedilab/nitterizeme/activities/TransformActivity.java +++ b/app/src/main/java/app/fedilab/nitterizeme/activities/TransformActivity.java @@ -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 { diff --git a/app/src/main/java/app/fedilab/nitterizeme/helpers/Utils.java b/app/src/main/java/app/fedilab/nitterizeme/helpers/Utils.java index 220756b..78f7ca3 100644 --- a/app/src/main/java/app/fedilab/nitterizeme/helpers/Utils.java +++ b/app/src/main/java/app/fedilab/nitterizeme/helpers/Utils.java @@ -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 { diff --git a/app/src/main/res/drawable/ic_expand_less.xml b/app/src/main/res/drawable/ic_apps.xml similarity index 59% rename from app/src/main/res/drawable/ic_expand_less.xml rename to app/src/main/res/drawable/ic_apps.xml index 4ff5565..2d7d796 100644 --- a/app/src/main/res/drawable/ic_expand_less.xml +++ b/app/src/main/res/drawable/ic_apps.xml @@ -6,5 +6,5 @@ android:viewportHeight="24.0"> + 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" /> diff --git a/app/src/main/res/layout/activity_check_app.xml b/app/src/main/res/layout/activity_check_app.xml new file mode 100644 index 0000000..f824845 --- /dev/null +++ b/app/src/main/res/layout/activity_check_app.xml @@ -0,0 +1,29 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index 9eda4f2..6b92d6c 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -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">