Browse Source

Search for telegram package only on demand

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
9431d72e72
  1. 4
      app/src/main/java/awais/instagrabber/InstaGrabberApplication.java
  2. 8
      app/src/main/java/awais/instagrabber/dialogs/AboutDialog.java
  3. 16
      app/src/main/java/awais/instagrabber/utils/Utils.java

4
app/src/main/java/awais/instagrabber/InstaGrabberApplication.java

@ -25,11 +25,9 @@ import static awais.instagrabber.utils.CookieUtils.NET_COOKIE_MANAGER;
import static awais.instagrabber.utils.Utils.clipboardManager; import static awais.instagrabber.utils.Utils.clipboardManager;
import static awais.instagrabber.utils.Utils.dataBox; import static awais.instagrabber.utils.Utils.dataBox;
import static awais.instagrabber.utils.Utils.datetimeParser; import static awais.instagrabber.utils.Utils.datetimeParser;
import static awais.instagrabber.utils.Utils.getInstalledTelegramPackage;
import static awais.instagrabber.utils.Utils.logCollector; import static awais.instagrabber.utils.Utils.logCollector;
import static awais.instagrabber.utils.Utils.notificationManager; import static awais.instagrabber.utils.Utils.notificationManager;
import static awais.instagrabber.utils.Utils.settingsHelper; import static awais.instagrabber.utils.Utils.settingsHelper;
import static awais.instagrabber.utils.Utils.telegramPackage;
public final class InstaGrabberApplication extends MultiDexApplication { public final class InstaGrabberApplication extends MultiDexApplication {
private static final String TAG = "InstaGrabberApplication"; private static final String TAG = "InstaGrabberApplication";
@ -61,8 +59,6 @@ public final class InstaGrabberApplication extends MultiDexApplication {
final Context appContext = getApplicationContext(); final Context appContext = getApplicationContext();
telegramPackage = getInstalledTelegramPackage(appContext);
if (dataBox == null) if (dataBox == null)
dataBox = DataBox.getInstance(appContext); dataBox = DataBox.getInstance(appContext);

8
app/src/main/java/awais/instagrabber/dialogs/AboutDialog.java

@ -37,10 +37,10 @@ public final class AboutDialog extends BottomSheetDialogFragment {
final Intent intent = new Intent(Intent.ACTION_VIEW); final Intent intent = new Intent(Intent.ACTION_VIEW);
if (v == btnTelegram) { if (v == btnTelegram) {
intent.setData(Uri.parse("https://t.me/grabber_app")); intent.setData(Uri.parse("https://t.me/grabber_app"));
if (!TextUtils.isEmpty(Utils.telegramPackage))
intent.setPackage(Utils.telegramPackage);
}
else if (v == btnMatrix) {
final String telegramPackage = Utils.getInstalledTelegramPackage(getContext());
if (!TextUtils.isEmpty(telegramPackage))
intent.setPackage(telegramPackage);
} else if (v == btnMatrix) {
intent.setData(Uri.parse("https://matrix.to/#/#instagrabber:matrix.org")); intent.setData(Uri.parse("https://matrix.to/#/#instagrabber:matrix.org"));
} else } else
intent.setData(Uri.parse("https://instagrabber.austinhuang.me")); intent.setData(Uri.parse("https://instagrabber.austinhuang.me"));

16
app/src/main/java/awais/instagrabber/utils/Utils.java

@ -59,12 +59,13 @@ public final class Utils {
public static NotificationManagerCompat notificationManager; public static NotificationManagerCompat notificationManager;
public static final MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); public static final MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
public static boolean isChannelCreated = false; public static boolean isChannelCreated = false;
public static String telegramPackage;
public static ClipboardManager clipboardManager; public static ClipboardManager clipboardManager;
public static DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics(); public static DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
public static SimpleDateFormat datetimeParser; public static SimpleDateFormat datetimeParser;
public static SimpleCache simpleCache; public static SimpleCache simpleCache;
private static String telegramPackage;
public static int convertDpToPx(final float dp) { public static int convertDpToPx(final float dp) {
if (displayMetrics == null) if (displayMetrics == null)
displayMetrics = Resources.getSystem().getDisplayMetrics(); displayMetrics = Resources.getSystem().getDisplayMetrics();
@ -282,7 +283,9 @@ public final class Utils {
} }
@Nullable @Nullable
public static String getInstalledTelegramPackage(@NonNull final Context context) {
public static String getInstalledTelegramPackage(@Nullable final Context context) {
if (telegramPackage != null) return telegramPackage;
if (context == null) return null;
final String[] packages = { final String[] packages = {
"org.telegram.messenger", "org.telegram.messenger",
"org.thunderdog.challegram", "org.thunderdog.challegram",
@ -298,7 +301,6 @@ public final class Utils {
"ml.parsgram", "ml.parsgram",
"com.ringtoon.app.tl", "com.ringtoon.app.tl",
}; };
final PackageManager packageManager = context.getPackageManager(); final PackageManager packageManager = context.getPackageManager();
for (final String pkg : packages) { for (final String pkg : packages) {
try { try {
@ -306,13 +308,13 @@ public final class Utils {
if (packageInfo.applicationInfo.enabled) return pkg; if (packageInfo.applicationInfo.enabled) return pkg;
} catch (final Exception e) { } catch (final Exception e) {
try { try {
if (packageManager.getApplicationInfo(pkg, 0).enabled) return pkg;
} catch (final Exception e1) {
// meh
if (packageManager.getApplicationInfo(pkg, 0).enabled) {
telegramPackage = pkg;
return pkg;
} }
} catch (final Exception ignored) {}
} }
} }
return null; return null;
} }

Loading…
Cancel
Save