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.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);
|
||||||
|
|
||||||
|
@ -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))
|
final String telegramPackage = Utils.getInstalledTelegramPackage(getContext());
|
||||||
intent.setPackage(Utils.telegramPackage);
|
if (!TextUtils.isEmpty(telegramPackage))
|
||||||
}
|
intent.setPackage(telegramPackage);
|
||||||
else if (v == btnMatrix) {
|
} 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"));
|
||||||
|
@ -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;
|
if (packageManager.getApplicationInfo(pkg, 0).enabled) {
|
||||||
} catch (final Exception e1) {
|
telegramPackage = pkg;
|
||||||
// meh
|
return pkg;
|
||||||
|
}
|
||||||
|
} catch (final Exception ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user