mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
Search for telegram package only on demand
This commit is contained in:
parent
80044b5daf
commit
9431d72e72
@ -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.dataBox;
|
||||
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.notificationManager;
|
||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||
import static awais.instagrabber.utils.Utils.telegramPackage;
|
||||
|
||||
public final class InstaGrabberApplication extends MultiDexApplication {
|
||||
private static final String TAG = "InstaGrabberApplication";
|
||||
@ -61,8 +59,6 @@ public final class InstaGrabberApplication extends MultiDexApplication {
|
||||
|
||||
final Context appContext = getApplicationContext();
|
||||
|
||||
telegramPackage = getInstalledTelegramPackage(appContext);
|
||||
|
||||
if (dataBox == null)
|
||||
dataBox = DataBox.getInstance(appContext);
|
||||
|
||||
|
@ -37,10 +37,10 @@ public final class AboutDialog extends BottomSheetDialogFragment {
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
if (v == btnTelegram) {
|
||||
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"));
|
||||
} else
|
||||
intent.setData(Uri.parse("https://instagrabber.austinhuang.me"));
|
||||
|
@ -59,12 +59,13 @@ public final class Utils {
|
||||
public static NotificationManagerCompat notificationManager;
|
||||
public static final MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
|
||||
public static boolean isChannelCreated = false;
|
||||
public static String telegramPackage;
|
||||
public static ClipboardManager clipboardManager;
|
||||
public static DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
|
||||
public static SimpleDateFormat datetimeParser;
|
||||
public static SimpleCache simpleCache;
|
||||
|
||||
private static String telegramPackage;
|
||||
|
||||
public static int convertDpToPx(final float dp) {
|
||||
if (displayMetrics == null)
|
||||
displayMetrics = Resources.getSystem().getDisplayMetrics();
|
||||
@ -282,7 +283,9 @@ public final class Utils {
|
||||
}
|
||||
|
||||
@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 = {
|
||||
"org.telegram.messenger",
|
||||
"org.thunderdog.challegram",
|
||||
@ -298,7 +301,6 @@ public final class Utils {
|
||||
"ml.parsgram",
|
||||
"com.ringtoon.app.tl",
|
||||
};
|
||||
|
||||
final PackageManager packageManager = context.getPackageManager();
|
||||
for (final String pkg : packages) {
|
||||
try {
|
||||
@ -306,13 +308,13 @@ public final class Utils {
|
||||
if (packageInfo.applicationInfo.enabled) return pkg;
|
||||
} catch (final Exception e) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user