diff --git a/app/src/main/java/ru/vtosters/lite/audio/gcm/GCMFix.java b/app/src/main/java/ru/vtosters/lite/audio/gcm/GCMFix.java index 7df4ad8f6..abf8c2cab 100644 --- a/app/src/main/java/ru/vtosters/lite/audio/gcm/GCMFix.java +++ b/app/src/main/java/ru/vtosters/lite/audio/gcm/GCMFix.java @@ -51,23 +51,15 @@ public class GCMFix{ public static String requestToken(){ String xappide; try { - String[] aidarr = {"3974055026275073921", "4418584909973341826", "4585634953328772978"}; - int r = new Random().nextInt(aidarr.length - 1); - String aid = "AidLogin " + aidarr[r] + ":" + new String[] {"1932960345884890854", "6594645578425092292", "1792344590975444730"}[r]; + String aid = getRandomAid(); String pub2 = genNewKey(); String sig = getSig(pub2); - String xappide2 = null; - byte[] bytes = pair.getPublic().getEncoded(); try { - bytes = MessageDigest.getInstance("SHA1").digest(bytes); - } catch (NoSuchAlgorithmException e) { - xappide2 = ""; - } - if (xappide2 == null) { + byte[] bytes = MessageDigest.getInstance("SHA1").digest(pair.getPublic().getEncoded()); bytes[0] = (byte) (((bytes[0] & 15) + 112) & 255); xappide = Base64.encodeToString(bytes, 2).substring(0, 11); - } else { - xappide = xappide2; + } catch (NoSuchAlgorithmException e) { + xappide = ""; } AtomicBoolean wait = new AtomicBoolean(false); StringBuilder sb = new StringBuilder(); @@ -176,6 +168,13 @@ public class GCMFix{ con.getInputStream().close(); } + private static String getRandomAid() { + var arr1 = new String[]{ "3974055026275073921", "4418584909973341826", "4585634953328772978" }; + var arr2 = new String[]{ "1932960345884890854", "6594645578425092292", "1792344590975444730" }; + int r = new Random().nextInt(2); + return "AidLogin " + arr1[r] + ":" + arr2[r]; + } + private static String genNewKey(){ try { KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA"); diff --git a/app/src/main/java/ru/vtosters/lite/downloaders/VideoDownloader.java b/app/src/main/java/ru/vtosters/lite/downloaders/VideoDownloader.java index bc9bedcf0..5c2c4e1ee 100644 --- a/app/src/main/java/ru/vtosters/lite/downloaders/VideoDownloader.java +++ b/app/src/main/java/ru/vtosters/lite/downloaders/VideoDownloader.java @@ -2,6 +2,7 @@ package ru.vtosters.lite.downloaders; import static ru.vtosters.lite.net.Request.makeRequest; import static ru.vtosters.lite.utils.Globals.getContext; +import static ru.vtosters.lite.utils.Globals.getIdentifier; import static ru.vtosters.lite.utils.Globals.getString; import static ru.vtosters.lite.utils.Globals.getUserToken; @@ -25,29 +26,37 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import com.vtosters.lite.R; + +import ru.vtosters.lite.utils.ExternalLinkHandler; +import ru.vtosters.lite.utils.Preferences; + public class VideoDownloader{ - private static final int action_id = 1488; + private static final int DOWNLOAD_ID = 0; + private static final int OPEN_EXTERNAL_LINK_ID = 1; public static boolean onClick(int id, VideoFile video, Context ctx){ - if (id == action_id) { + if (id == DOWNLOAD_ID) { downloadVideo(video, ctx); return true; + } else if (id == OPEN_EXTERNAL_LINK_ID) { + ExternalLinkHandler.parseVideoFile(video, ctx); } return false; } public static void injectAction(ArrayList list, VideoFile video){ if (!video.U && !video.I1()) { - MenuBottomSheetAction downloadAction = new MenuBottomSheetAction( - action_id, - com.vtosters.lite.R.drawable.ic_download_outline_24, - com.vtosters.lite.R.string.download, - 9 - ); - list.add(downloadAction); + addAction(list, DOWNLOAD_ID, R.drawable.ic_download_outline_24, R.string.download, 9); + if (Preferences.isEnableExternalOpening()) + addAction(list, OPEN_EXTERNAL_LINK_ID, R.drawable.ic_link_outline_28, getIdentifier("interfacevideoext", "string"), 9); } } + private static void addAction(List actions, int... ints) { + actions.add(new MenuBottomSheetAction(ints[0], ints[1], ints[2], ints[3])); + } + public static void downloadVideo(VideoFile videoFile, Context context){ final List list = new ArrayList<>(); final List urls = new ArrayList<>(); diff --git a/app/src/main/java/ru/vtosters/lite/utils/ExternalLinkHandler.java b/app/src/main/java/ru/vtosters/lite/utils/ExternalLinkHandler.java index 8238b5c26..f786cc963 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/ExternalLinkHandler.java +++ b/app/src/main/java/ru/vtosters/lite/utils/ExternalLinkHandler.java @@ -1,6 +1,7 @@ package ru.vtosters.lite.utils; import static ru.vtosters.lite.utils.Globals.getContext; +import static ru.vtosters.lite.utils.Globals.getCurrentActivity; import static ru.vtosters.lite.utils.Globals.isEmpty; import static ru.vtosters.lite.utils.Preferences.isEnableExternalOpening; @@ -29,8 +30,11 @@ public class ExternalLinkHandler{ ); private static final Map qualities = new HashMap<>(); - public static boolean parseVideoFile(VideoFile file){ - var context = getContext(); + public static boolean parseVideoFile(VideoFile file) { + return parseVideoFile(file, getContext()); + } + + public static boolean parseVideoFile(VideoFile file, Context context) { if (checkYoutubeLink(file)) { try { Intent intent = new Intent(Intent.ACTION_VIEW);