fixed calls moment

This commit is contained in:
gdlbo
2023-01-21 15:58:37 +03:00
parent acf3a77fe7
commit afef886293
3 changed files with 83 additions and 56 deletions
@@ -1,31 +1,43 @@
package ru.vtosters.lite.hooks;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.view.View;
import com.vk.im.engine.models.dialogs.Dialog;
import com.vtosters.lite.api.ExtendedUserProfile;
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserID;
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
public class CallsHook {
public static void forwardToVkOffApps(View view, ExtendedUserProfile p) {
call(view.getContext(), AccountManagerUtils.getUserID(p));
}
public static void forwardToVkOffApps(View view, Dialog dl) {
call(view.getContext(), dl.getId());
}
public static void call(Context ctx, int id) {
// FIXME: add com.vk.calls, right now it doesn't support intent
var callsAvailable = checkPackage("com.vk.im") || checkPackage("com.vkontakte.android");
var vkim = checkPackage("com.vk.im");
var vk = checkPackage("com.vkontakte.android");
var callsAvailable = vkim || vk;
if (!callsAvailable) {
sendToast("Установите VK мессенджер или официальный VK клиент");
AndroidUtils.sendToast("Установите VK мессенджер или официальный VK клиент");
return;
}
var link = "https://vk.com/call?id=" + getUserID(p);
var startCall = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
view.getContext().startActivity(startCall);
var link = "https://vk.com/call?id=" + id;
var startCall = new Intent(Intent.ACTION_VIEW, Uri.parse(link)).setPackage(vk ? "com.vkontakte.android" : "com.vk.im");
ctx.startActivity(startCall);
}
private static Boolean checkPackage(String packageName) {
try {
var pm = getGlobalContext().getPackageManager();
var pm = AndroidUtils.getGlobalContext().getPackageManager();
return pm.getApplicationInfo(packageName, 0).enabled;
} catch (PackageManager.NameNotFoundException e) {
return false;
@@ -146,7 +146,8 @@ public class Preferences {
}
public static boolean calls() {
return getBoolValue("calls", false);
// return getBoolValue("calls", false);
return true;
}
public static boolean dev() {