Compare commits
284
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52f69c792d | ||
|
|
33f150eb43 | ||
|
|
e165f388f5 | ||
|
|
761ff263be | ||
|
|
8918f203fc | ||
|
|
6039d0cf43 | ||
|
|
af902f945e | ||
|
|
a90d96b00f | ||
|
|
550d3dadd8 | ||
|
|
82720adb61 | ||
|
|
2a3e12b39a | ||
|
|
87407b0007 | ||
|
|
ff2e33d9a2 | ||
|
|
61b6b0a1ec | ||
|
|
9db18f526a | ||
|
|
043253ffff | ||
|
|
756ab2b7c0 | ||
|
|
2ba5aef993 | ||
|
|
ab3bd09ab7 | ||
|
|
7990d269aa | ||
|
|
fffda61a83 | ||
|
|
d817ccd292 | ||
|
|
02de3699cc | ||
|
|
81b214bcff | ||
|
|
5dcf50fdc2 | ||
|
|
81d4f9ec99 | ||
|
|
29596b5dd1 | ||
|
|
b789840498 | ||
|
|
fce6c2b14f | ||
|
|
f2ac2c6a37 | ||
|
|
61881f4e9d | ||
|
|
92f74aa5fb | ||
|
|
0c968de977 | ||
|
|
51efc8f4c6 | ||
|
|
4dbf1756e1 | ||
|
|
8d4d88e099 | ||
|
|
dd953d39e7 | ||
|
|
4902938016 | ||
|
|
54de4fd060 | ||
|
|
6d9f3029d3 | ||
|
|
332fe678b9 | ||
|
|
04eee5cc26 | ||
|
|
bc94f1ac77 | ||
|
|
fc423d5ccd | ||
|
|
f0993bee15 | ||
|
|
22ef4bd646 | ||
|
|
c4cc678c82 | ||
|
|
350c25faff | ||
|
|
89ea35dd82 | ||
|
|
cd858266a8 | ||
|
|
0549b07c49 | ||
|
|
a7fd5536f6 | ||
|
|
1397653b55 | ||
|
|
ec1a0fc2d5 | ||
|
|
b75dca5515 | ||
|
|
f31fade75a | ||
|
|
347e0fb9c4 | ||
|
|
bf1a73f606 | ||
|
|
82e268ffa7 | ||
|
|
f3acbf74a8 | ||
|
|
7126af6240 | ||
|
|
ef2946a700 | ||
|
|
8821574412 | ||
|
|
8257a374da | ||
|
|
3985593842 | ||
|
|
92d8c9a90d | ||
|
|
6f9c325b0d | ||
|
|
1010821cf4 | ||
|
|
012dfa7063 | ||
|
|
01adf656e2 | ||
|
|
bb64ed8d2a | ||
|
|
1ec78a8fbd | ||
|
|
f1436ebbde | ||
|
|
c4efb751c9 | ||
|
|
6e902d4bca | ||
|
|
07b49a4a74 | ||
|
|
c6fdf65137 | ||
|
|
18e2554d5e | ||
|
|
04488314b5 | ||
|
|
3eec52db3b | ||
|
|
132df6080e | ||
|
|
d8f91bc730 | ||
|
|
270c2af5c1 | ||
|
|
99c500ed69 | ||
|
|
8174be1768 | ||
|
|
a88f59bac1 | ||
|
|
1eaa3748c4 | ||
|
|
27836f72f5 | ||
|
|
70e048a1ad | ||
|
|
e915b26918 | ||
|
|
8a6a92f77b | ||
|
|
cb492b5949 | ||
|
|
f15e4c004d | ||
|
|
f7f2cf3e58 | ||
|
|
578fa86f19 | ||
|
|
a9bcb19ebf | ||
|
|
cf6b993172 | ||
|
|
145a6a668b | ||
|
|
6b2752db67 | ||
|
|
58fb6224f4 | ||
|
|
b6406bcebf | ||
|
|
6c7733f1a0 | ||
|
|
5373002666 | ||
|
|
4005ac2ef1 | ||
|
|
30de30cf64 | ||
|
|
0feeacb533 | ||
|
|
de511d15a6 | ||
|
|
dc1be1434a | ||
|
|
6b88996962 | ||
|
|
bb35b2b252 | ||
|
|
b2f1cfea5e | ||
|
|
2748ec6902 | ||
|
|
17b9c7075e | ||
|
|
fd070323b0 | ||
|
|
03a43326b7 | ||
|
|
a0b28b6c12 | ||
|
|
5d46edb91a | ||
|
|
0e751533b5 | ||
|
|
32d5ba792a | ||
|
|
eb96137c3a | ||
|
|
09f7a07226 | ||
|
|
251f9935aa | ||
|
|
a75070f8d3 | ||
|
|
972921a05c | ||
|
|
3b2586ade5 | ||
|
|
58ea05cc9d | ||
|
|
441baac671 | ||
|
|
a1efd38048 | ||
|
|
d8be2fe7b7 | ||
|
|
27fdbf2407 | ||
|
|
fd954f5bab | ||
|
|
3295e40231 | ||
|
|
f88596025f | ||
|
|
9c5f584d1b | ||
|
|
537a3759d0 | ||
|
|
f2fcc5f4d1 | ||
|
|
db651c462a | ||
|
|
4f06fda96d | ||
|
|
1344e88b95 | ||
|
|
23dd5a71e0 | ||
|
|
810e5c72c1 | ||
|
|
045daeea47 | ||
|
|
f45de44c75 | ||
|
|
d2911e5b6b | ||
|
|
576890189c | ||
|
|
5ce6ab3aa8 | ||
|
|
1451e2d3ac | ||
|
|
95958a85e9 | ||
|
|
9f2b3edbe8 | ||
|
|
ee4249c688 | ||
|
|
2f46c193dd | ||
|
|
09807a2954 | ||
|
|
163cd44dcc | ||
|
|
2bdff722d4 | ||
|
|
e206e85324 | ||
|
|
40159a2a9f | ||
|
|
54d59e1f2f | ||
|
|
1b797325f0 | ||
|
|
63c3c0ee32 | ||
|
|
4b6a7aeb84 | ||
|
|
38f65997a6 | ||
|
|
d718851d0c | ||
|
|
b30ad26f54 | ||
|
|
5f5fb650f2 | ||
|
|
76260981c5 | ||
|
|
ceb84ed6f6 | ||
|
|
e8a2c3af56 | ||
|
|
80e78fa2c1 | ||
|
|
7b35501461 | ||
|
|
c9cfc5e749 | ||
|
|
f0a915be05 | ||
|
|
f2b8624cc4 | ||
|
|
ccaa10d224 | ||
|
|
6325d8fe68 | ||
|
|
e243522f95 | ||
|
|
d87a59bcb0 | ||
|
|
724fafc3fd | ||
|
|
8c03ab60fc | ||
|
|
985ced6e3c | ||
|
|
88339feb12 | ||
|
|
2bcf5d1c2d | ||
|
|
77f9c60be7 | ||
|
|
76468d8863 | ||
|
|
c17e604db6 | ||
|
|
1a96f77aa1 | ||
|
|
3fd0757fd4 | ||
|
|
989075a3d2 | ||
|
|
802d88cad7 | ||
|
|
95a0451c6b | ||
|
|
3b83f05bf0 | ||
|
|
c7d350f5b1 | ||
|
|
d3eeaf5f23 | ||
|
|
4dcea46be7 | ||
|
|
96de61fd15 | ||
|
|
47f4c5c911 | ||
|
|
fcbf9238cf | ||
|
|
4a8a2adb4e | ||
|
|
501e39429b | ||
|
|
604d19cc40 | ||
|
|
a29e0dcf4b | ||
|
|
ec551dcb33 | ||
|
|
cc4690965a | ||
|
|
65f32d3686 | ||
|
|
bf15bb93ee | ||
|
|
cb3c537f1d | ||
|
|
bb0c845e74 | ||
|
|
a4c88d0924 | ||
|
|
7f0b6c3c3d | ||
|
|
31eedf4d6d | ||
|
|
bf23cc7305 | ||
|
|
6bef2f1ea9 | ||
|
|
e561356690 | ||
|
|
64d6e4b529 | ||
|
|
34d067d192 | ||
|
|
c50511a12f | ||
|
|
0b748c16e4 | ||
|
|
f88dd17480 | ||
|
|
892e9874cb | ||
|
|
82a24e4abf | ||
|
|
2631757a05 | ||
|
|
b2f7754ec9 | ||
|
|
2175800f33 | ||
|
|
ab16fdcecb | ||
|
|
a34cad6837 | ||
|
|
34b2357a20 | ||
|
|
e47d6acbf1 | ||
|
|
a5bd532570 | ||
|
|
e4124f459f | ||
|
|
03328137df | ||
|
|
906036854c | ||
|
|
1dad82d61c | ||
|
|
0d9f8360ce | ||
|
|
5dc5f001f2 | ||
|
|
b6d26515ce | ||
|
|
f02971e00d | ||
|
|
827bb9d9ce | ||
|
|
4a5a6b58e1 | ||
|
|
fa2a1b083d | ||
|
|
d372b670c0 | ||
|
|
86afcaeacb | ||
|
|
027c7a7151 | ||
|
|
7f304950a8 | ||
|
|
fc44a9b263 | ||
|
|
235b287a36 | ||
|
|
9317e86d66 | ||
|
|
23f1b6c26b | ||
|
|
a7d50bca26 | ||
|
|
92fbd071de | ||
|
|
b7860b857f | ||
|
|
cd0914041d | ||
|
|
9f0230d935 | ||
|
|
a05865c6a8 | ||
|
|
d678ff5e9b | ||
|
|
4829acd869 | ||
|
|
6df6fdf01c | ||
|
|
4a2e73d676 | ||
|
|
4c5a1c5a17 | ||
|
|
1aedacf401 | ||
|
|
9d4bffd8aa | ||
|
|
ede17b31a2 | ||
|
|
e94f93facb | ||
|
|
2460b27af1 | ||
|
|
9cb9bf4167 | ||
|
|
6753dc9a8c | ||
|
|
c257e3a5ce | ||
|
|
a055656424 | ||
|
|
4882315bf4 | ||
|
|
1d8f998a5f | ||
|
|
ff945b76b8 | ||
|
|
2d14c78a90 | ||
|
|
10d1a40bd8 | ||
|
|
78e3757cf4 | ||
|
|
2aef797efe | ||
|
|
20999810ab | ||
|
|
d8c45ffeff | ||
|
|
05d339eeb0 | ||
|
|
e50366da8a | ||
|
|
915b31477b | ||
|
|
9d2878b9dc | ||
|
|
bcfefe777d | ||
|
|
b69e55606a | ||
|
|
2f06d2a008 | ||
|
|
d151d27063 | ||
|
|
ad128f1e7e |
@@ -22,32 +22,36 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v2
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Download tools
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install default-jre
|
||||
sudo apt install python3
|
||||
sudo apt install zipalign
|
||||
chmod +x scripts/apktool.jar
|
||||
chmod +x scripts/apksigner.jar
|
||||
|
||||
- name: Build VTLite
|
||||
run: |
|
||||
bash scripts/buildworkflow.sh
|
||||
|
||||
gradle prepareDexForMerge
|
||||
java -jar scripts/apktool.jar b smali -o smali/VTLite.apk --use-aapt2 -p scripts/framework/
|
||||
zipalign -p -f 4 smali/VTLite.apk smali/VTLite.apk_aligned
|
||||
mv smali/VTLite.apk_aligned smali/VTLite.apk
|
||||
|
||||
- name: Sign and verify the apk
|
||||
run: |
|
||||
java -jar scripts/apksigner.jar sign --ks scripts/debug.keystore --ks-key-alias androiddebugkey --ks-pass pass:android smali/VTLite.apk
|
||||
java -jar scripts/apksigner.jar verify smali/VTLite.apk
|
||||
|
||||
- name: Upload apk to artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: VTLite.apk
|
||||
path: smali/VTLite.apk
|
||||
|
||||
@@ -30,3 +30,4 @@ smali/build/resources.zip
|
||||
smali/assets/version.properties
|
||||
*.keystore
|
||||
gradle.properties
|
||||
scripts/build.sh
|
||||
|
||||
@@ -46,8 +46,7 @@
|
||||
- [Разработка](#разработка)
|
||||
- [Всё необходимое для сборки и компиляции](#всё-необходимое-для-сборки-и-компиляции)
|
||||
- [Необходимые зависимости](#необходимые-зависимости)
|
||||
- [Linux/macOS](#linuxmacos)
|
||||
- [Windows](#windows)
|
||||
- [Linux/MacOS/Windows](#LinuxmacOSWindows)
|
||||
|
||||
|
||||
## Функциональность
|
||||
@@ -122,12 +121,10 @@
|
||||
|
||||
<a href="https://developer.android.com/studio"><img src="https://i.imgur.com/cPvvFDP.png" align="center" width="20" height="23"/> **Android Studio**</a>
|
||||
|
||||
### Linux/macOS
|
||||
Для сборки используется файл `./build.sh`
|
||||
### Linux/macOS/Windows
|
||||
|
||||
<img src="https://i.imgur.com/8BMX8lG.png" width="550" height="368"/>
|
||||
Для сборки необходимо вызвать одну из следующих gradle tasks:
|
||||
|
||||
### Windows
|
||||
Для сборки используется файл `build.bat`
|
||||
|
||||
<img src="https://i.imgur.com/iZSUKJ6.png" width="550" height="368"/>
|
||||
+ `./gradlew buildVTL` - соберет и подпишет APK
|
||||
+ `./gradlew buildAndInstallVTL` - соберет, подпишет и попытается установить через ADB
|
||||
+ [FOR DEVS] `./gradlew prepareDexForMerge` - соберет все необходимое для сборки в `smali/`
|
||||
|
||||
+63
-6
@@ -1,15 +1,24 @@
|
||||
import java.nio.file.Files
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipFile
|
||||
import java.util.zip.ZipInputStream
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
|
||||
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'net.nemerosa.versioning' version '2.15.1'
|
||||
}
|
||||
|
||||
def smaliFolder = projectDir.toPath().resolve("../smali").normalize()
|
||||
def scriptsFolder = projectDir.toPath().resolve("../scripts").normalize()
|
||||
|
||||
versionFile {
|
||||
File moduleDir = projectDir
|
||||
file = new File(moduleDir.getAbsolutePath() + "/src/main/assets/version.properties")
|
||||
file = projectDir.toPath().resolve("src/main/assets/version.properties").toFile()
|
||||
}
|
||||
|
||||
task cleanVersionFile {
|
||||
projectDir.toPath().resolve("src/main/assets/version.properties").toFile().delete()
|
||||
}
|
||||
|
||||
task exportDex {
|
||||
@@ -69,7 +78,13 @@ task exportDex {
|
||||
|
||||
android {
|
||||
compileSdkVersion 32
|
||||
buildToolsVersion '33.0.0'
|
||||
buildToolsVersion '32.0.0'
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java.srcDirs += 'build/generated/aidl_source_output_dir/release/out'
|
||||
}
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId "ru.vtosters.lite.utils.lite"
|
||||
@@ -91,8 +106,50 @@ android {
|
||||
dependencies {
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
|
||||
implementation 'net.sourceforge.streamsupport:streamsupport-minifuture:1.7.4'
|
||||
implementation 'com.google.android.material:material:1.6.1'
|
||||
implementation 'androidx.preference:preference:1.2.0'
|
||||
implementation fileTree(dir: 'libs', include: ['*.aar'])
|
||||
compileOnly fileTree(dir: 'libs', include: ['*.jar'])
|
||||
}
|
||||
}
|
||||
|
||||
task prepareDexForMerge(type: Copy) {
|
||||
dependsOn('exportDex')
|
||||
into smaliFolder.toString()
|
||||
from(projectDir) {
|
||||
include 'classes6.dex'
|
||||
include 'classes7.dex'
|
||||
}
|
||||
from(projectDir) {
|
||||
include 'version.properties'
|
||||
into("assets")
|
||||
}
|
||||
doLast {
|
||||
new File(projectDir, "classes6.dex").delete()
|
||||
new File(projectDir, "classes7.dex").delete()
|
||||
new File(projectDir, "version.properties").delete()
|
||||
}
|
||||
}
|
||||
|
||||
task buildVTL(type: Exec) {
|
||||
dependsOn('prepareDexForMerge')
|
||||
workingDir(projectDir.parentFile)
|
||||
if (Os.isFamily("unix") || Os.isFamily("mac")) {
|
||||
commandLine 'bash', '-c', './scripts/build.sh'
|
||||
} else {
|
||||
commandLine 'cmd', '/C', '.\\scripts\\build.bat'
|
||||
}
|
||||
}
|
||||
|
||||
task buildAndInstallVTL(type: Exec) {
|
||||
dependsOn('buildVTL')
|
||||
workingDir(scriptsFolder.toString())
|
||||
ignoreExitValue true
|
||||
if (Os.isFamily("unix") || Os.isFamily("mac")) {
|
||||
commandLine 'bash', '-c', 'adb install VTLite.apk'
|
||||
} else {
|
||||
commandLine 'adb', 'install', 'VTLite.apk'
|
||||
}
|
||||
}
|
||||
|
||||
exportDex.dependsOn('assembleRelease')
|
||||
clean.dependsOn('cleanVersionFile')
|
||||
versionFile.dependsOn('cleanVersionFile')
|
||||
preBuild.dependsOn('versionFile')
|
||||
|
||||
@@ -2,6 +2,7 @@ package bruhcollective.itaysonlab.libvkx.client;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.isValidSignature;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
@@ -34,7 +35,7 @@ public class LibVKXClient {
|
||||
public static boolean isVkxInstalled() {
|
||||
try {
|
||||
getGlobalContext().getPackageManager().getPackageInfo("ua.itaysonlab.vkx", 0);
|
||||
return true;
|
||||
return isValidSignature();
|
||||
} catch (Exception unused) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ import androidx.core.app.NotificationManagerCompat;
|
||||
import com.aefyr.tsg.g2.stickersgrabber.TelegramStickersGrabber;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
@@ -21,22 +22,22 @@ import ru.vtosters.lite.utils.AndroidUtils;
|
||||
* Created by Aefyr on 20.05.2018.
|
||||
*/
|
||||
public class NotificationsHelper {
|
||||
private static final int NOTIFICATION_ID_BASE = 3921337;
|
||||
// private static final int NOTIFICATION_ID_BASE = 3921337;
|
||||
private static final String NOTIFICATION_CHANNEL_ID = "tgss_chan_v5";
|
||||
private static final int MAX_UPDATE_NOTIFICATIONS_PER_SECOND = 3;
|
||||
private static final int MIN_TIME_BETWEEN_UPDATE_NOTIFICATIONS = 1000 / MAX_UPDATE_NOTIFICATIONS_PER_SECOND;
|
||||
private final HashMap<TelegramStickersPack, Integer> downloadingPacksNotificationsIds;
|
||||
private final List<Integer> downloadingPacksNotificationsIds;
|
||||
private final Context c;
|
||||
private final NotificationManagerCompat manager;
|
||||
private final AtomicLong lastNotificationTime = new AtomicLong(0);
|
||||
private int currentNotificationN = 0;
|
||||
// private int currentNotificationN = 0;
|
||||
|
||||
public NotificationsHelper(Context c) {
|
||||
this.c = c;
|
||||
manager = NotificationManagerCompat.from(c);
|
||||
|
||||
|
||||
downloadingPacksNotificationsIds = new HashMap<>();
|
||||
downloadingPacksNotificationsIds = new ArrayList<>();
|
||||
|
||||
if (oreo()) {
|
||||
NotificationChannel notificationChan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, AndroidUtils.getString(R.string.telegram_stickers_service), NotificationManager.IMPORTANCE_HIGH);
|
||||
@@ -45,19 +46,19 @@ public class NotificationsHelper {
|
||||
}
|
||||
|
||||
public void packStartedDownloading(TelegramStickersPack pack) {
|
||||
int notificationId = NOTIFICATION_ID_BASE + currentNotificationN++;
|
||||
downloadingPacksNotificationsIds.put(pack, notificationId);
|
||||
downloadingPacksNotificationsIds.add(pack.hash);
|
||||
|
||||
Notification.Builder builder = commonBuilder();
|
||||
builder.setContentTitle(pack.state == TelegramStickersPack.DOWNLOADING ? pack.title + AndroidUtils.getString(R.string.telegram_stickers_downloading) : pack.title + AndroidUtils.getString(R.string.telegram_stickers_updating));
|
||||
builder.setContentText(AndroidUtils.getString(R.string.telegram_stickers_gettinginfo));
|
||||
builder.setOngoing(true);
|
||||
|
||||
manager.notify(notificationId, builder.build());
|
||||
manager.notify(pack.hash, builder.build());
|
||||
}
|
||||
|
||||
public void packDownloadUpdated(TelegramStickersPack pack, int downloadProgress) {
|
||||
if (System.currentTimeMillis() - lastNotificationTime.get() < MIN_TIME_BETWEEN_UPDATE_NOTIFICATIONS)
|
||||
if (System.currentTimeMillis() - lastNotificationTime.get() < MIN_TIME_BETWEEN_UPDATE_NOTIFICATIONS
|
||||
|| !downloadingPacksNotificationsIds.contains(pack.hash))
|
||||
return;
|
||||
|
||||
lastNotificationTime.set(System.currentTimeMillis());
|
||||
@@ -69,11 +70,13 @@ public class NotificationsHelper {
|
||||
builder.setOngoing(true);
|
||||
builder.setOnlyAlertOnce(true);
|
||||
|
||||
if (downloadingPacksNotificationsIds.containsKey(pack))
|
||||
manager.notify(downloadingPacksNotificationsIds.get(pack), builder.build());
|
||||
manager.notify(pack.hash, builder.build());
|
||||
}
|
||||
|
||||
public void packDoneDownloading(TelegramStickersPack pack, boolean success, boolean wasUpdate, @Nullable Exception e) {
|
||||
if (!downloadingPacksNotificationsIds.remove(pack.hash))
|
||||
return;
|
||||
|
||||
Notification.Builder builder = commonBuilder();
|
||||
builder.setProgress(0, 0, false);
|
||||
builder.setOngoing(false);
|
||||
@@ -81,9 +84,9 @@ public class NotificationsHelper {
|
||||
|
||||
String text;
|
||||
if (success)
|
||||
text = wasUpdate ? pack.title + AndroidUtils.getString(R.string.telegram_stickers_updated) : pack.title + AndroidUtils.getString(R.string.telegram_stickers_downloaded);
|
||||
text = pack.title + " " + AndroidUtils.getString(wasUpdate ? R.string.telegram_stickers_updated : R.string.telegram_stickers_downloaded);
|
||||
else
|
||||
text = wasUpdate ? pack.title + AndroidUtils.getString(R.string.telegram_stickers_error_update) : pack.title + AndroidUtils.getString(R.string.telegram_stickers_error_download);
|
||||
text = pack.title + " " + AndroidUtils.getString(wasUpdate ? R.string.telegram_stickers_error_update : R.string.telegram_stickers_error_download);
|
||||
|
||||
if (e instanceof TelegramStickersGrabber.TSGException) {
|
||||
text = pack.title + ": " + e.getMessage();
|
||||
@@ -91,11 +94,12 @@ public class NotificationsHelper {
|
||||
|
||||
builder.setContentText(String.format(text, pack.title));
|
||||
|
||||
manager.notify(downloadingPacksNotificationsIds.remove(pack), builder.build());
|
||||
manager.notify(pack.hash, builder.build());
|
||||
}
|
||||
|
||||
public void removePackNotification(TelegramStickersPack pack) {
|
||||
manager.cancel(downloadingPacksNotificationsIds.remove(pack));
|
||||
if (downloadingPacksNotificationsIds.remove(pack.hash))
|
||||
manager.cancel(pack.hash);
|
||||
}
|
||||
|
||||
private Notification.Builder commonBuilder() {
|
||||
|
||||
@@ -32,11 +32,14 @@ public class TelegramStickersPack extends CustomStickersPack {
|
||||
public int stickersCount = -1;
|
||||
public String version;
|
||||
public int index = -1;
|
||||
public Integer hash;
|
||||
|
||||
public HashMap<String, List<Integer>> emojis = new HashMap<>();
|
||||
|
||||
public TelegramStickersPack(String id) {
|
||||
this.id = id.toLowerCase();
|
||||
final var idLowerCase = id.toLowerCase();
|
||||
this.id = idLowerCase;
|
||||
this.hash = idLowerCase.hashCode();
|
||||
title = id;
|
||||
}
|
||||
|
||||
@@ -106,7 +109,7 @@ public class TelegramStickersPack extends CustomStickersPack {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.toLowerCase().hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -235,7 +235,7 @@ public class TelegramStickersService {
|
||||
runOnUiThread(() -> {
|
||||
newPack.state = TelegramStickersPack.DOWNLOADED;
|
||||
notifyPackChanged(newPack, packs.indexOf(newPack));
|
||||
currentlyDownloading.remove(newPack.id.toLowerCase());
|
||||
currentlyDownloading.remove(newPack.id);
|
||||
syncPack(newPack);
|
||||
|
||||
if (isUpdate) {
|
||||
|
||||
@@ -184,7 +184,7 @@ public class TelegramStickersGrabber {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(NetCall call, NetResponse response) throws IOException {
|
||||
public void onResponse(NetCall call, NetResponse response) {
|
||||
if (!response.isSuccessful()) {
|
||||
if (response.getData() != null)
|
||||
listener.onPackDownloadError(new TSGException(response.getDataString() + "\nURL: " + call.request().url()));
|
||||
@@ -211,21 +211,24 @@ public class TelegramStickersGrabber {
|
||||
return;
|
||||
}
|
||||
|
||||
if (jPackInfo.optBoolean("is_animated")) {
|
||||
listener.onPackDownloadError(new TSGException("Animated stickerpacks are not supported!"));
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<Sticker> stickers = new ArrayList<>(jStickers.length());
|
||||
|
||||
Log.d(TAG, String.format("Parsing stickers in pack %s", packName));
|
||||
|
||||
for (int i = 0; i < jStickers.length(); i++) {
|
||||
JSONObject jSticker = jStickers.getJSONObject(i);
|
||||
stickers.add(new Sticker(jSticker.getString("file_id"), jSticker.getString("emoji")));
|
||||
if (jSticker.optBoolean("is_animated") || jSticker.optBoolean("is_video")) {
|
||||
if (jSticker.has("thumb")) {
|
||||
stickers.add(new Sticker(jSticker.getJSONObject("thumb").getString("file_id"), jSticker.getString("emoji")));
|
||||
} else {
|
||||
listener.onPackDownloadError(new TSGException("Animated and video stickerpacks without thumbs are not supported!"));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
stickers.add(new Sticker(jSticker.getString("file_id"), jSticker.getString("emoji")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
set = new StickerSet(jPackInfo.getString("name"), jPackInfo.getString("title"), packVersion, stickers);
|
||||
} catch (Exception e) {
|
||||
listener.onPackDownloadError(e);
|
||||
|
||||
@@ -8,29 +8,24 @@ import com.arthenica.smartexception.java.Exceptions;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class NativeLoader {
|
||||
static final String[] FFMPEG_LIBRARIES = {"avutil", "swscale", "swresample", "avcodec", "avformat", "avfilter", "avdevice"};
|
||||
static final String[] FFMPEG_LIBRARIES = {"avutil", "swresample", "avcodec", "avformat", "avfilter", "avdevice"};
|
||||
|
||||
private static void loadLibrary(String libraryName) {
|
||||
String path = AndroidUtils.getGlobalContext().getFilesDir() + "/lib" + libraryName + ".so";
|
||||
System.load(path);
|
||||
System.loadLibrary(libraryName);
|
||||
}
|
||||
|
||||
private static List<String> loadExternalLibraries() {
|
||||
// return Packages.getExternalLibraries();
|
||||
//return Packages.getExternalLibraries();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static String loadNativeAbi() {
|
||||
// return AbiDetect.getNativeAbi();
|
||||
return Abi.ABI_ARMV7A_NEON.getName();
|
||||
return AbiDetect.getNativeAbi();
|
||||
}
|
||||
|
||||
static String loadAbi() {
|
||||
// return AbiDetect.getAbi();
|
||||
return Abi.ABI_ARMV7A_NEON.getName();
|
||||
return AbiDetect.getAbi();
|
||||
}
|
||||
|
||||
static String loadPackageName() {
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.vk.core.drawable;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import androidx.annotation.NonNull;
|
||||
import ru.vtosters.lite.themes.utils.RecolorUtils;
|
||||
|
||||
public class RecoloredDrawable extends Drawable implements Drawable.Callback {
|
||||
private Drawable drawable;
|
||||
private ColorStateList colorStateList;
|
||||
private int c;
|
||||
private int d;
|
||||
|
||||
public RecoloredDrawable(Drawable drawable, ColorStateList colorStateList) {
|
||||
this.c = 255;
|
||||
this.d = 255;
|
||||
try {
|
||||
this.drawable = drawable.mutate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.drawable.setCallback(this);
|
||||
this.colorStateList = RecolorUtils.themeCSL(colorStateList);
|
||||
onStateChange(new int[0]);
|
||||
}
|
||||
|
||||
public void a(int i) {
|
||||
a(new ColorStateList(new int[][]{new int[0]}, new int[]{i}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
this.drawable.draw(canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
return this.drawable.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
return this.drawable.getIntrinsicWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return this.drawable.getOpacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateDrawable(@NonNull Drawable drawable) {
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStateful() {
|
||||
return this.colorStateList.isStateful();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onStateChange(int[] iArr) {
|
||||
super.onStateChange(iArr);
|
||||
ColorStateList colorStateList = this.colorStateList;
|
||||
this.drawable.setColorFilter(colorStateList.getColorForState(iArr, colorStateList.getDefaultColor()), PorterDuff.Mode.SRC_IN);
|
||||
int length = iArr.length;
|
||||
boolean z = false;
|
||||
int i = 0;
|
||||
while (true) {
|
||||
if (i >= length) {
|
||||
break;
|
||||
} else if (iArr[i] == 0x010100a1) {
|
||||
z = true;
|
||||
break;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
this.drawable.setState(iArr);
|
||||
this.drawable.setAlpha(z ? this.c : this.d);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleDrawable(@NonNull Drawable drawable, @NonNull Runnable runnable, long j) {
|
||||
scheduleSelf(runnable, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int i) {
|
||||
this.c = i;
|
||||
this.d = i;
|
||||
this.drawable.setAlpha(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBounds(int i, int i2, int i3, int i4) {
|
||||
super.setBounds(i, i2, i3, i4);
|
||||
this.drawable.setBounds(i, i2, i3, i4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter colorFilter) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unscheduleDrawable(@NonNull Drawable drawable, @NonNull Runnable runnable) {
|
||||
unscheduleSelf(runnable);
|
||||
}
|
||||
|
||||
public void a(ColorStateList colorStateList) {
|
||||
this.colorStateList = colorStateList;
|
||||
onStateChange(getState());
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public Drawable a() {
|
||||
return this.drawable;
|
||||
}
|
||||
|
||||
public RecoloredDrawable(Drawable drawable, int i) {
|
||||
this(drawable, new ColorStateList(new int[][]{new int[0]}, new int[]{i}));
|
||||
}
|
||||
|
||||
public RecoloredDrawable() {
|
||||
this.c = 255;
|
||||
this.d = 255;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import android.util.Log;
|
||||
|
||||
import com.facebook.common.i.MediaUtils;
|
||||
import com.facebook.x.g.EncodedImage;
|
||||
import com.vk.core.concurrent.VkExecutors;
|
||||
import com.vk.imageloader.VKImageLoader;
|
||||
import com.vk.log.L;
|
||||
import com.vk.metrics.eventtracking.VkTracker;
|
||||
@@ -29,6 +28,7 @@ import java.util.HashSet;
|
||||
|
||||
import b.h.g.m.CameraUtils;
|
||||
import b.h.g.m.FileUtils;
|
||||
import ru.vtosters.lite.concurrent.VTExecutors;
|
||||
|
||||
public class DownloadUtils {
|
||||
public static final HashSet<Long> a = new HashSet<>();
|
||||
@@ -81,7 +81,7 @@ public class DownloadUtils {
|
||||
file.createNewFile();
|
||||
}
|
||||
if (file.exists()) {
|
||||
VkExecutors.x.e().execute(() -> {
|
||||
VTExecutors.getIoExecutor().execute(() -> {
|
||||
try {
|
||||
FileUtils.b.a(h, new FileOutputStream(file), h.available(), null);
|
||||
ToastUtils.a(context.getString(R.string.file_saved, file.getAbsoluteFile()));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.vtosters.lite;
|
||||
|
||||
public class R {
|
||||
public final class R {
|
||||
|
||||
public static final class anim {
|
||||
public static final int abc_fade_in = 0x7f010000; // 2130771968
|
||||
public static final int abc_fade_out = 0x7f010001; // 2130771969
|
||||
@@ -220,6 +221,8 @@ public class R {
|
||||
public static final int targetlang_value = 0x7f030074; // 2130903156
|
||||
public static final int undel_value = 0x7f030075; // 2130903157
|
||||
public static final int wallpaper_change_dialog = 0x7f030076; // 2130903158
|
||||
public static final int theme_type_name = 0x7f030077; // 2130903159
|
||||
public static final int theme_type_name_checkbox = 0x7f030078; // 2130903160
|
||||
}
|
||||
|
||||
public static final class attr {
|
||||
@@ -19514,6 +19517,17 @@ public class R {
|
||||
public static final int whitelisted_filters_groups_title = 0x7f121838; // 2131892280
|
||||
public static final int why_news_not_updated_summ = 0x7f121839; // 2131892281
|
||||
public static final int why_news_not_updated_title = 0x7f12183a; // 2131892282
|
||||
public static final int blockminiapps_summ = 0x7f12183b; // 2131892283
|
||||
public static final int blockminiapps_title = 0x7f12183c; // 2131892284
|
||||
public static final int current_theme = 0x7f12183d; // 2131892285
|
||||
public static final int invalid_pack_link = 0x7f12183e; // 2131892286
|
||||
public static final int maxquality_summ = 0x7f12183f; // 2131892287
|
||||
public static final int maxquality_title = 0x7f121840; // 2131892288
|
||||
public static final int newsfeed_notif_summ = 0x7f121841; // 2131892289
|
||||
public static final int newsfeed_notif_title = 0x7f121842; // 2131892290
|
||||
public static final int promotedstickers_title = 0x7f121843; // 2131892291
|
||||
public static final int vkx_integration_enabled_info = 0x7f121844; // 2131892292
|
||||
public static final int writebar_ios_title = 0x7f121845; // 2131892293
|
||||
}
|
||||
|
||||
public static final class style {
|
||||
|
||||
+7
-5
@@ -71,12 +71,11 @@ public class BottomNavigationItemView extends FrameLayout implements MenuView.It
|
||||
this.mIcon.getLayoutParams().width = V.a(28.0F);
|
||||
this.mIcon.getLayoutParams().height = V.a(28.0F);
|
||||
|
||||
var colorStateList = getCSTDock();
|
||||
this.mSmallLabel = this.findViewById(R.id.smallLabel);
|
||||
mSmallLabel.setTextColor(colorStateList);
|
||||
mSmallLabel.setTextColor(getCSTDock());
|
||||
|
||||
this.mLargeLabel = this.findViewById(R.id.largeLabel);
|
||||
mLargeLabel.setTextColor(colorStateList);
|
||||
mLargeLabel.setTextColor(getCSTDock());
|
||||
|
||||
LayoutInflater.from(this.getContext()).inflate(R.layout.navigation_bottom_counter, this, true);
|
||||
this.mCounterContainer = this.findViewById(R.id.counter_container);
|
||||
@@ -280,12 +279,13 @@ public class BottomNavigationItemView extends FrameLayout implements MenuView.It
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
public void setIcon(Drawable drawable) {
|
||||
if (drawable != null) {
|
||||
var csl = this.mColorStateList;
|
||||
if (drawable != null && csl != null) {
|
||||
if (drawable.getConstantState() != null)
|
||||
drawable = drawable.getConstantState().newDrawable();
|
||||
|
||||
drawable = DrawableCompat.wrap(drawable).mutate();
|
||||
DrawableCompat.setTintList(drawable, this.mColorStateList);
|
||||
DrawableCompat.setTintList(drawable, csl);
|
||||
}
|
||||
|
||||
this.mIcon.setImageDrawable(drawable);
|
||||
@@ -326,6 +326,8 @@ public class BottomNavigationItemView extends FrameLayout implements MenuView.It
|
||||
}
|
||||
|
||||
public void setTextColor(ColorStateList colorStateList) {
|
||||
this.mSmallLabel.setTextColor(colorStateList);
|
||||
this.mLargeLabel.setTextColor(colorStateList);
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package ru.vtosters.lite.concurrent;
|
||||
|
||||
import com.vk.core.concurrent.VkExecutors;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import io.reactivex.Scheduler;
|
||||
|
||||
public class VTExecutors {
|
||||
public static ExecutorService getMusicDownloadExecutor() {
|
||||
return VTMusicDownloadExecutor.getInstance();
|
||||
}
|
||||
|
||||
public static ExecutorService getIoExecutor() {
|
||||
return VkExecutors.x.e();
|
||||
}
|
||||
|
||||
public static Scheduler getIoScheduler() {
|
||||
return VkExecutors.x.f();
|
||||
}
|
||||
|
||||
public static Scheduler getSlowTasksScheduler() {
|
||||
return VkExecutors.x.q();
|
||||
}
|
||||
|
||||
static class VTMusicDownloadExecutor {
|
||||
private VTMusicDownloadExecutor() {
|
||||
}
|
||||
|
||||
public static ExecutorService getInstance() {
|
||||
return LazyHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class LazyHolder {
|
||||
public static final ExecutorService INSTANCE = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,8 +70,8 @@ public class OEMDetector {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isIntentResolved(Context ctx, Intent intent ){
|
||||
return (intent!=null && ctx.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null);
|
||||
public static boolean isIntentResolved(Context ctx, Intent intent) {
|
||||
return (intent != null && ctx.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null);
|
||||
}
|
||||
|
||||
public static boolean detectMiuiV2() {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package ru.vtosters.lite.di.singleton;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class VtOkHttpClient extends OkHttpClient {
|
||||
public static VtOkHttpClient getInstance() {
|
||||
return LazyHolder.instance;
|
||||
}
|
||||
|
||||
private static class LazyHolder {
|
||||
private static final VtOkHttpClient instance = new VtOkHttpClient();
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,8 @@ import java.util.List;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.downloaders.MessagesDownloader;
|
||||
import ru.vtosters.lite.downloaders.messages.HtmlDialogDownloaderFormatProvider;
|
||||
import ru.vtosters.lite.downloaders.messages.MessagesDownloader;
|
||||
import ru.vtosters.lite.encryption.EncryptProvider;
|
||||
import ru.vtosters.lite.encryption.base.IMProcessor;
|
||||
import ru.vtosters.lite.hooks.CryptImHook;
|
||||
@@ -189,7 +190,7 @@ public class DNRInjector {
|
||||
if (action == DialogAction.DOWNLOAD) {
|
||||
File out = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "dialog-" + peerId + ".html");
|
||||
try {
|
||||
new MessagesDownloader().downloadDialog(peerId, new MessagesDownloader.HtmlDialogDownloaderFormatProvider(), out);
|
||||
new MessagesDownloader().downloadDialog(peerId, new HtmlDialogDownloaderFormatProvider(), out);
|
||||
} catch (Exception e) {
|
||||
sendToast(AndroidUtils.getString(R.string.download_dl_error));
|
||||
e.printStackTrace();
|
||||
@@ -250,7 +251,7 @@ public class DNRInjector {
|
||||
if (action == DialogAction.DOWNLOAD) {
|
||||
File out = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), peerId + "-dialog.html");
|
||||
try {
|
||||
new MessagesDownloader().downloadDialog(peerId, new MessagesDownloader.HtmlDialogDownloaderFormatProvider(), out);
|
||||
new MessagesDownloader().downloadDialog(peerId, new HtmlDialogDownloaderFormatProvider(), out);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import com.vk.dto.music.Playlist;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
@@ -21,6 +23,7 @@ import ru.vtosters.lite.music.downloader.PlaylistDownloader;
|
||||
import ru.vtosters.lite.music.downloader.TrackDownloader;
|
||||
import ru.vtosters.lite.music.notification.MusicNotificationBuilder;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
/**
|
||||
@@ -30,6 +33,7 @@ import ru.vtosters.lite.utils.IOUtils;
|
||||
*/
|
||||
|
||||
public class AudioDownloader {
|
||||
public static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
public static void downloadPlaylist(Playlist playlist) {
|
||||
var tracks = PlaylistConverter.getPlaylist(playlist);
|
||||
@@ -60,13 +64,14 @@ public class AudioDownloader {
|
||||
|
||||
if (CacheDatabaseDelegate.isCached(trackId)) {
|
||||
CacheDatabaseDelegate.removeTrackFromCache(LibVKXClient.asId(track));
|
||||
AndroidUtils.sendToast(AndroidUtils.getString("audio_deleted_from_cache"));
|
||||
return;
|
||||
}
|
||||
|
||||
var trackFile = FileCacheImplementation.getTrackFile(trackId);
|
||||
if (!trackFile.exists())
|
||||
trackFile.getParentFile().mkdirs();
|
||||
downloadM3U8(track, true);
|
||||
executor.submit(() -> downloadM3U8(track, true));
|
||||
}
|
||||
|
||||
public static void cachePlaylist(Playlist playlist) {
|
||||
|
||||
@@ -1,621 +0,0 @@
|
||||
package ru.vtosters.lite.downloaders;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static android.widget.Toast.makeText;
|
||||
import static ru.vtosters.lite.encryption.EncryptProvider.decryptMessage;
|
||||
import static ru.vtosters.lite.net.Request.makeRequest;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserId;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getArray;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getResources;
|
||||
|
||||
import android.util.SparseArray;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
|
||||
public class MessagesDownloader {
|
||||
private static final String VK_DOMAIN = "vk.com";
|
||||
private static SimpleDateFormat sdformat;
|
||||
private static SparseArray<MiniUser> usersArray;
|
||||
|
||||
public static String formatTime(long now) {
|
||||
return sdformat.format(new Date(now));
|
||||
}
|
||||
|
||||
public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) {
|
||||
Objects.requireNonNull(delimiter);
|
||||
Objects.requireNonNull(elements);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (CharSequence cs : elements) {
|
||||
builder.append(cs).append(delimiter);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getPollHtml(JSONObject poll) throws JSONException {
|
||||
StringBuilder pollHtml = new StringBuilder(
|
||||
"<div class=\"vtex-milk-msg poll\">" +
|
||||
"<p style=\"text-align:center;\">" + poll.optString("question") + "</p>"
|
||||
);
|
||||
|
||||
var answers = poll.optJSONArray("answers");
|
||||
|
||||
for (int i = 0; i < answers.length(); i++) {
|
||||
var jsonObject = answers.optJSONObject(i);
|
||||
if (jsonObject != null)
|
||||
pollHtml.append("<hr><p>").append(jsonObject.optString("text")).append(" · ").append(jsonObject.optString("votes")).append(" (").append(jsonObject.optString("rate")).append("%)</p>");
|
||||
}
|
||||
|
||||
pollHtml.append("<hr><p style=\"text-align:center;\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_poll_voted))
|
||||
.append(" ")
|
||||
.append(poll.optString("votes"))
|
||||
.append(" ")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_users_name))
|
||||
.append("</p>");
|
||||
|
||||
return pollHtml.append("</div>").toString();
|
||||
}
|
||||
|
||||
private static String getVideoHtml(JSONObject files) throws JSONException {
|
||||
if (files == null) return AndroidUtils.getString(R.string.chat_export_video_nolinks);
|
||||
|
||||
Iterator<?> keys = files.keys();
|
||||
StringBuilder videoHtml = new StringBuilder();
|
||||
|
||||
int qualityIndex = 0;
|
||||
String[] quality = {"144", "240", "360", "480", "720", "1080", "1440", "2160"};
|
||||
|
||||
while (keys.hasNext()) {
|
||||
String key = (String) keys.next();
|
||||
if (key.equals("mp4_" + quality[qualityIndex])) {
|
||||
videoHtml.append("<a class=\"msg-attach-link\" href=\"").append(files.get(key)).append("\">").append(quality[qualityIndex]).append("p</a>").append(" ");
|
||||
|
||||
if (qualityIndex == quality.length - 1) break;
|
||||
++qualityIndex;
|
||||
}
|
||||
}
|
||||
|
||||
return videoHtml.toString();
|
||||
}
|
||||
|
||||
public void downloadDialog(int peer_id, DialogDownloaderFormatProvider format, File out) throws Exception {
|
||||
sdformat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", getResources().getConfiguration().locale);
|
||||
|
||||
FileOutputStream fos = new FileOutputStream(out);
|
||||
|
||||
// fix TODO with conversation name (API method messages.getConversationsById)
|
||||
fos.write(format.provideDocumentStart("TODO", formatTime(System.currentTimeMillis())).getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
fetchDialogInfo(peer_id, 0, ((users, messages) -> {
|
||||
try {
|
||||
fos.write(format.provideHeader("TODO", formatTime(System.currentTimeMillis())).getBytes(StandardCharsets.UTF_8));
|
||||
for (MiniMsg msg : messages) {
|
||||
fos.write(format.provideMessage(msg, users.get(msg.fromId)).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
fos.write(format.provideDocumentEnd().getBytes(StandardCharsets.UTF_8));
|
||||
fos.close();
|
||||
LifecycleUtils.getCurrentActivity().runOnUiThread(() -> makeText(getGlobalContext(), AndroidUtils.getString(R.string.saved_as) + " " + out.getAbsolutePath(), LENGTH_SHORT).show());
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void fetchDialogInfo(int peer_id, int offset, FetchListener fl) {
|
||||
makeRequest("https://" + getApi() + "/method/messages.getHistory?extended=1&v=5.140&offset=" + offset + "&count=200&peer_id=" + peer_id + "&access_token=" + getUserToken(),
|
||||
response -> {
|
||||
try {
|
||||
JSONObject mainJson = new JSONObject(response);
|
||||
JSONObject obj = mainJson.getJSONObject("response");
|
||||
|
||||
SparseArray<MiniUser> users = new SparseArray<>();
|
||||
parseUsers(users, obj.optJSONArray("profiles"), false);
|
||||
parseUsers(users, obj.optJSONArray("groups"), true);
|
||||
|
||||
List<MiniMsg> msgs = parseMessages(obj.getJSONArray("items"));
|
||||
|
||||
usersArray = users;
|
||||
|
||||
fl.onReceive(users, msgs);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<MiniMsg> parseMessages(JSONArray jsonArray) throws JSONException {
|
||||
ArrayList<MiniMsg> thing = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
MiniMsg msg = new MiniMsg(jsonArray.getJSONObject(i));
|
||||
thing.add(msg);
|
||||
}
|
||||
|
||||
return thing;
|
||||
}
|
||||
|
||||
private void parseUsers(SparseArray<MiniUser> array, @Nullable JSONArray jsonArray, boolean groups) throws JSONException {
|
||||
if (jsonArray == null) return;
|
||||
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
MiniUser user = new MiniUser(jsonArray.getJSONObject(i), groups);
|
||||
array.put(groups ? -user.id : user.id, user);
|
||||
}
|
||||
}
|
||||
|
||||
interface FetchListener {
|
||||
void onReceive(SparseArray<MiniUser> users, List<MiniMsg> messages);
|
||||
}
|
||||
|
||||
static class MiniUser {
|
||||
public String firstName;
|
||||
public String lastName;
|
||||
public boolean isGroup;
|
||||
int id;
|
||||
String photo100;
|
||||
|
||||
public MiniUser(JSONObject obj, boolean is_group) throws JSONException {
|
||||
id = obj.getInt("id");
|
||||
firstName = obj.optString("first_name", obj.optString("name"));
|
||||
lastName = obj.optString("last_name", "");
|
||||
photo100 = obj.getString("photo_100");
|
||||
isGroup = is_group;
|
||||
}
|
||||
}
|
||||
|
||||
static class MiniMsg {
|
||||
long date;
|
||||
int fromId;
|
||||
int id; // message id
|
||||
String text;
|
||||
List<JSONObject> attachments;
|
||||
List<JSONObject> fwd_messages;
|
||||
JSONObject reply_message; // one reply
|
||||
JSONObject chat_action;
|
||||
JSONObject geo;
|
||||
|
||||
public MiniMsg(JSONObject obj) throws JSONException {
|
||||
date = obj.getLong("date") * 1000;
|
||||
fromId = obj.getInt("from_id");
|
||||
id = obj.getInt("id");
|
||||
text = decryptMessage(obj.getString("text"), obj.getInt("peer_id"));
|
||||
reply_message = obj.optJSONObject("reply_message");
|
||||
chat_action = obj.optJSONObject("action");
|
||||
geo = obj.optJSONObject("geo");
|
||||
|
||||
attachments = new ArrayList<>();
|
||||
fwd_messages = new ArrayList<>();
|
||||
|
||||
JSONArray arr = obj.optJSONArray("attachments");
|
||||
if (arr != null)
|
||||
for (int i = 0; i < arr.length(); i++) attachments.add(arr.getJSONObject(i));
|
||||
|
||||
JSONArray fwdArr = obj.optJSONArray("fwd_messages");
|
||||
if (fwdArr != null)
|
||||
for (int i = 0; i < fwdArr.length(); i++) fwd_messages.add(fwdArr.getJSONObject(i));
|
||||
}
|
||||
}
|
||||
|
||||
// This class defines everything which is needed to create an output file
|
||||
abstract static class DialogDownloaderFormatProvider {
|
||||
// Internal, for JSON/HTML
|
||||
abstract String provideDocumentStart(String dialogName, String date);
|
||||
|
||||
abstract String provideDocumentEnd();
|
||||
|
||||
abstract String provideHeader(String dialogName, String date);
|
||||
|
||||
abstract String provideMessage(MiniMsg message, MiniUser user) throws JSONException;
|
||||
}
|
||||
|
||||
public static class HtmlDialogDownloaderFormatProvider extends DialogDownloaderFormatProvider {
|
||||
@Override
|
||||
String provideDocumentStart(String dialogName, String date) {
|
||||
String style = ".vtex-milk-msg {\n" +
|
||||
" border-radius: 8px;\n" +
|
||||
" padding: 24px;\n" +
|
||||
" background: white;\n" +
|
||||
" margin: 16px;\n" +
|
||||
" box-shadow: 0 4px 8px 0 rgba(0,0,0,0.07);\n" +
|
||||
" word-wrap: break-word;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".vtex-milk-msgcont br {\n" +
|
||||
" display: none;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".vtex-milk-msg p {\n" +
|
||||
" margin: 0;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".vtex-milk-msg.vtex-milk-msg-out {\n" +
|
||||
" background: #ADD3FF;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"p.msg-attaches {\n" +
|
||||
" margin-top: 8px;\n" +
|
||||
" font-style: italic;\n" +
|
||||
"}\n" +
|
||||
"p.chat-action {\n" +
|
||||
" font-style: italic;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".vtex-milk-header {\n" +
|
||||
" border-radius: 8px;\n" +
|
||||
" padding: 24px;\n" +
|
||||
" background: white;\n" +
|
||||
" margin: 16px;\n" +
|
||||
" box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"h4.vtex-milk-header-txt {\n" +
|
||||
" margin: 0;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"h5.vtex-milk-header-sub {\n" +
|
||||
" margin: 0;\n" +
|
||||
" padding-top: 8px;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"a.msg-attach-link {\n" +
|
||||
" color: #5181B8;\n" +
|
||||
" text-decoration: none;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".msg-from a {\n" +
|
||||
" color: #5181B8;\n" +
|
||||
" text-decoration: none;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".msg-from-date {\n" +
|
||||
" color: rgba(0, 0, 0, 0.75);\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"body {\n" +
|
||||
" font-family: Roboto, system-ui, sans-serif;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".msg-body {\n" +
|
||||
" padding-top: 4px;\n" +
|
||||
"}\n" +
|
||||
".msg-reply {\n" +
|
||||
" border-left: 3px solid #7aa7f6;\n" +
|
||||
" margin-top: 5px;\n" +
|
||||
" padding-left: 3px;\n" +
|
||||
"}\n\n" +
|
||||
".msg-reply p {\n" +
|
||||
" padding-left: 5px;\n" +
|
||||
"}\n\n" +
|
||||
".msg-reply p.reply-header {\n" +
|
||||
" color: #5181B8;\n" +
|
||||
"}\n\n" +
|
||||
".msg-reply p.reply-content {\n" +
|
||||
" color: #000000;\n" +
|
||||
"}\n" +
|
||||
".vtex-milk-msg.poll {\n" +
|
||||
" width: 45%;\n" +
|
||||
" background: linear-gradient(to bottom right, #707c8c, #4d5565);\n" +
|
||||
" font-style: normal;" +
|
||||
"}\n" +
|
||||
".vtex-milk-msg.poll p { color: white; }\n" +
|
||||
".vtex-milk-msg.poll hr { border-top: 1px; background: #ffffff; }\n" +
|
||||
"\n" +
|
||||
"";
|
||||
|
||||
return "<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><meta charset=\"utf-8\"><title>"
|
||||
+ AndroidUtils.getString(R.string.chat_export_title)
|
||||
+ "</title><style>"
|
||||
+ style
|
||||
+ "</style></head><body>";
|
||||
}
|
||||
|
||||
@Override
|
||||
String provideDocumentEnd() {
|
||||
return "</div></body></html>";
|
||||
}
|
||||
|
||||
@Override
|
||||
String provideHeader(String dialogName, String date) {
|
||||
return "<div class=\"vtex-milk-header\"><h4 class=\"vtex-milk-header-txt\">VTLite</h4><h5 class=\"vtex-milk-header-sub\">" + AndroidUtils.getString(R.string.chat_export_header) + " (" + date + ")</h5></div><div class=\"vtex-milk-msgcont\">";
|
||||
}
|
||||
|
||||
@Override
|
||||
String provideMessage(MiniMsg message, MiniUser user) throws JSONException {
|
||||
String isOut = (user.id == getUserId()) ? " vtex-milk-msg-out" : "";
|
||||
|
||||
String geoPosition = "";
|
||||
if (message.geo != null) {
|
||||
var coordinates = message.geo.optJSONObject("coordinates");
|
||||
if (coordinates != null) {
|
||||
var latitude = coordinates.optDouble("latitude");
|
||||
var longitude = coordinates.optDouble("longitude");
|
||||
var ll = longitude + "," + latitude;
|
||||
geoPosition = "<a href=\"https://yandex.ru/maps/?ll=" + ll + "&mode=search&sll=" + ll + "&text=" + latitude + "," + longitude + "&z=12\">" +
|
||||
"<img src=\"https://static-maps.yandex.ru/1.x/?ll=" + longitude + "," + latitude + "&z=12&l=map&size=300,200&pt=" + ll + ",vkgrm\"/>" +
|
||||
"</a>";
|
||||
}
|
||||
}
|
||||
|
||||
String chatAction = (message.chat_action != null) ? getHtmlForChatAction(message.chat_action) : "";
|
||||
String attaches = (message.attachments.size() > 0) ? "<p class=\"msg-attaches\">" + AndroidUtils.getString(R.string.attachments) + ": " + getHtmlForAttach(message.attachments) + "</p>" : "";
|
||||
String reply = (message.reply_message != null) ? provideReply(message.reply_message) : "";
|
||||
String fwdMessages = (message.fwd_messages.size() > 0) ? provideForwardMessages(message.fwd_messages) : "";
|
||||
String userLink = (user.isGroup ? "club" : "id") + user.id;
|
||||
|
||||
return "<div class=\"vtex-milk-msg" + isOut + "\" id=\"" + message.id + "\">" +
|
||||
"<p class=\"msg-from\">" + AndroidUtils.getString(R.string.from_lower) + " <a href=\"https://" + VK_DOMAIN + "/" + userLink + "\">" + user.firstName + " " + user.lastName + "</a> <span class=\"msg-from-date\">" + formatTime(message.date) + "</span></p>" + // TODO photo100
|
||||
"<p class=\"msg-body\">" + mentionsReplace(message.text) + "</p>" +
|
||||
geoPosition +
|
||||
chatAction +
|
||||
attaches +
|
||||
reply +
|
||||
fwdMessages +
|
||||
"</div>";
|
||||
}
|
||||
|
||||
private String provideReply(JSONObject replyMessage) {
|
||||
var messageId = replyMessage.optInt("id");
|
||||
var userId = replyMessage.optInt("from_id");
|
||||
var peerId = replyMessage.optInt("peer_id");
|
||||
var text = mentionsReplace(decryptMessage(replyMessage.optString("text"), peerId));
|
||||
var fwdMessages = replyMessage.optJSONArray("fwd_messages");
|
||||
|
||||
var user = usersArray.get(userId);
|
||||
|
||||
if (text.isEmpty()) {
|
||||
if (fwdMessages != null) {
|
||||
var length = fwdMessages.length();
|
||||
if (length > 0) text = length + " " + pluralMsg(length);
|
||||
} else text = AndroidUtils.getString(R.string.attachment); // Вложение
|
||||
}
|
||||
|
||||
return "<a href=\"#" + messageId + "\" class=\"msg-attach-link\">" +
|
||||
"<div class=\"msg-reply\">" +
|
||||
"<p class=\"reply-header\">" + AndroidUtils.getString(R.string.vkim_msg_fwd_single) + "</p>" +
|
||||
"<p class=\"reply-content\">" + user.firstName + " " + user.lastName + ": " + text + "</p>" +
|
||||
"</div>" +
|
||||
"</a>";
|
||||
}
|
||||
|
||||
private String provideForwardMessages(List<JSONObject> fwd_messages) throws JSONException {
|
||||
StringBuilder fwdmsgs = new StringBuilder("<div class=\"msg-reply\">");
|
||||
|
||||
for (JSONObject fwd_message : fwd_messages) {
|
||||
|
||||
if (fwd_message == null) continue;
|
||||
|
||||
List<JSONObject> attaches = new ArrayList<>();
|
||||
|
||||
JSONArray arr = fwd_message.optJSONArray("attachments");
|
||||
if (arr != null) {
|
||||
for (int i = 0; i < arr.length(); i++) {
|
||||
try {
|
||||
attaches.add(arr.getJSONObject(i));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<JSONObject> fwdsMsg = new ArrayList<>();
|
||||
|
||||
JSONArray fwd_msgs = fwd_message.optJSONArray("fwd_messages");
|
||||
if (fwd_msgs != null) {
|
||||
for (int i = 0; i < fwd_msgs.length(); i++) {
|
||||
try {
|
||||
fwdsMsg.add(fwd_msgs.getJSONObject(i));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject reply_message = fwd_message.optJSONObject("reply_message");
|
||||
|
||||
var attachesHtml = (attaches.size() > 0) ? AndroidUtils.getString(R.string.attachments) + ": " + getHtmlForAttach(attaches) : "";
|
||||
var replyHtml = (reply_message != null) ? provideReply(reply_message) : "";
|
||||
var fwdsHtml = (fwdsMsg.size() > 0) ? provideForwardMessages(fwdsMsg) : ""; // recursion XD :>
|
||||
|
||||
var userId = fwd_message.optInt("from_id");
|
||||
var peerId = fwd_message.optInt("peer_id");
|
||||
var text = mentionsReplace(decryptMessage(fwd_message.optString("text"), peerId));
|
||||
|
||||
var userLink = ((userId < 0) ? "club" : "id") + Math.abs(userId);
|
||||
|
||||
fwdmsgs.append("<p class=\"reply-content\"><a class=\"msg-attach-link\" href=\"https://" + VK_DOMAIN + "/").append(userLink).append("\">@").append(userLink).append("</a>: ").append(text).append(attachesHtml).append(replyHtml).append(fwdsHtml);
|
||||
}
|
||||
|
||||
return fwdmsgs.append("</div>").toString();
|
||||
}
|
||||
|
||||
private String mentionsReplace(String text) {
|
||||
var matcher = Pattern.compile("\\[((?:club|id|public)\\d+)\\|([^]]+)\\]").matcher(text);
|
||||
|
||||
return matcher.replaceAll("<a class=\"msg-attach-link\" href=\"https://" + VK_DOMAIN + "/$1\">$2</a>");
|
||||
}
|
||||
|
||||
private String pluralMsg(int count) {
|
||||
String[] plurals = getArray(R.array.msg_plurals);
|
||||
|
||||
var hundredModulo = count % 100;
|
||||
var tenModulo = count % 10;
|
||||
|
||||
if (hundredModulo > 10 && hundredModulo < 20) return plurals[2];
|
||||
else if (tenModulo > 1 && tenModulo < 5) return plurals[1];
|
||||
else if (tenModulo == 1) return plurals[0];
|
||||
|
||||
return plurals[2];
|
||||
}
|
||||
|
||||
private String getHtmlForChatAction(JSONObject action) {
|
||||
var type = action.optString("type");
|
||||
|
||||
StringBuilder htmlAction = new StringBuilder("<p class=\"chat-action\">");
|
||||
|
||||
switch (type) {
|
||||
case "chat_photo_update":
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_avatar_update));
|
||||
break;
|
||||
case "chat_photo_remove":
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_avatar_remove));
|
||||
break;
|
||||
case "chat_create":
|
||||
var name = action.optString("text");
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_chat_created)).append((!name.isEmpty()) ? " \"" + name + "\"" : "");
|
||||
break;
|
||||
case "chat_title_update":
|
||||
var newName = action.optString("text");
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_name_changed)).append((!newName.isEmpty()) ? (" " + AndroidUtils.getString(R.string.chat_export_to) + " \"" + newName + "\"") : "");
|
||||
break;
|
||||
case "chat_invite_user":
|
||||
var newUserId = action.optInt("member_id");
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_user_added) + " ").append((newUserId > 0) ? AndroidUtils.getString(R.string.chat_export_type_user) : AndroidUtils.getString(R.string.chat_export_type_group));
|
||||
if (newUserId != 0) {
|
||||
var userLink = ((newUserId < 0) ? "club" : "id") + Math.abs(newUserId);
|
||||
htmlAction.append(" <a href=\"https://" + VK_DOMAIN + "/").append(userLink).append("\" class=\"msg-attach-link\">@").append(userLink).append("</a>");
|
||||
}
|
||||
break;
|
||||
case "chat_kick_user":
|
||||
var removedUserId = action.optInt("member_id");
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_user_kicked) + " ").append((removedUserId > 0) ? AndroidUtils.getString(R.string.chat_export_type_user) : AndroidUtils.getString(R.string.chat_export_type_group));
|
||||
if (removedUserId != 0) {
|
||||
var userLink = ((removedUserId < 0) ? "club" : "id") + Math.abs(removedUserId);
|
||||
htmlAction.append(" <a href=\"https://" + VK_DOMAIN + "/").append(userLink).append("\" class=\"msg-attach-link\">@").append(userLink).append("</a>");
|
||||
}
|
||||
break;
|
||||
case "chat_pin_message":
|
||||
var message = action.optString("message");
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_msg_pinned)).append((!message.isEmpty()) ? (" \"" + message + "\"") : "");
|
||||
break;
|
||||
case "chat_unpin_message":
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_msg_unpinned));
|
||||
break;
|
||||
case "chat_invite_user_by_link":
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_join_by_link));
|
||||
break;
|
||||
case "chat_screenshot":
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_chat_screenshot));
|
||||
break;
|
||||
case "custom":
|
||||
htmlAction.append(action.optString("message"));
|
||||
break;
|
||||
default:
|
||||
htmlAction.append(AndroidUtils.getString(R.string.vkim_msg_unsupported) + " (").append(type).append(")");
|
||||
break;
|
||||
}
|
||||
|
||||
return htmlAction.append("</p>").toString();
|
||||
}
|
||||
|
||||
private String getHtmlForAttach(List<JSONObject> attaches) throws JSONException {
|
||||
StringBuilder rs = new StringBuilder();
|
||||
|
||||
for (JSONObject attach : attaches) {
|
||||
String type = attach.getString("type");
|
||||
JSONObject item = attach.optJSONObject(type);
|
||||
|
||||
if (item == null) continue;
|
||||
|
||||
switch (type) { // market_album is not supported
|
||||
case "photo":
|
||||
var sizes = item.getJSONArray("sizes");
|
||||
rs.append("<a href=\"").append(sizes.getJSONObject(sizes.length() - 1).getString("url")).append("\" class=\"msg-attach-link\">").append(AndroidUtils.getString(R.string.chat_export_type_photo)).append("</a>");
|
||||
break;
|
||||
case "doc":
|
||||
rs.append("<a href=\"").append(item.getString("url")).append("\" class=\"msg-attach-link\">").append(AndroidUtils.getString(R.string.chat_export_type_doc)).append("</a>");
|
||||
break;
|
||||
case "link":
|
||||
rs.append("<a href=\"").append(item.getString("url")).append("\" class=\"msg-attach-link\">").append(AndroidUtils.getString(R.string.chat_export_type_link)).append("</a>");
|
||||
break;
|
||||
case "wall":
|
||||
rs.append("<a href=\"https://" + VK_DOMAIN + "/wall").append(item.optString("to_id", item.optString("owner_id"))).append("_").append(item.getString("id")).append("\" class=\"msg-attach-link\">").append(AndroidUtils.getString(R.string.chat_export_type_wallpost)).append("</a>");
|
||||
break;
|
||||
case "sticker":
|
||||
rs.append("<img style=\"width:128px;height:128px;\" src=\"").append(item.getJSONArray("images").getJSONObject(1).getString("url")).append("\"/>");
|
||||
break;
|
||||
case "audio_message":
|
||||
rs.append("<a href=\"").append(item.optString("link_mp3")).append("\" class=\"msg-attach-link\">").append(AndroidUtils.getString(R.string.chat_export_type_audiomsg)).append("</a>");
|
||||
break;
|
||||
case "audio":
|
||||
rs.append(AndroidUtils.getString(R.string.chat_export_type_audio)).append(" (").append(item.optString("artist")).append(" — ").append(item.optString("title")).append(")");
|
||||
break;
|
||||
case "video":
|
||||
rs.append(AndroidUtils.getString(R.string.chat_export_type_video)).append(" (").append(getVideoHtml(item.optJSONObject("files"))).append(")");
|
||||
break;
|
||||
case "wall_reply":
|
||||
var link = "https://" + VK_DOMAIN + "/wall" + item.optString("owner_id") + "_" + item.optString("post_id") + "?reply=" + item.optString("id");
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"").append(link).append("\">").append(AndroidUtils.getString(R.string.chat_export_type_wallreply)).append("</a>");
|
||||
break;
|
||||
case "story":
|
||||
var story_link = "https://" + VK_DOMAIN + "/story" + item.optString("owner_id") + "_" + item.optString("id");
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"").append(story_link).append("\">").append(AndroidUtils.getString(R.string.chat_export_type_story)).append("</a>");
|
||||
break;
|
||||
case "podcast":
|
||||
var podcast_link = "https://" + VK_DOMAIN + "/podcast" + item.optString("owner_id") + "_" + item.optString("id");
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"").append(podcast_link).append("\">").append(AndroidUtils.getString(R.string.chat_export_type_podcast)).append("</a>");
|
||||
break;
|
||||
case "gift":
|
||||
rs.append("<img src=\"").append(item.optString("thumb_96")).append("\"/>");
|
||||
break;
|
||||
case "mini_app":
|
||||
var app = item.optJSONObject("app");
|
||||
|
||||
if (app != null) {
|
||||
var miniapp_link = "https://" + VK_DOMAIN + "/app" + app.optString("id");
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"").append(miniapp_link).append("\">").append(AndroidUtils.getString(R.string.chat_export_type_miniapp)).append("</a>");
|
||||
break;
|
||||
}
|
||||
|
||||
rs.append(AndroidUtils.getString(R.string.chat_export_error));
|
||||
break;
|
||||
case "audio_playlist":
|
||||
var playlist_link = "https://" + VK_DOMAIN + "/music/album/" + item.optString("owner_id") + "_" + item.optString("id") + "_" + item.optString("access_key");
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"").append(playlist_link).append("\">").append(AndroidUtils.getString(R.string.chat_export_type_playlist)).append(" (").append(item.optString("title")).append(")</a>");
|
||||
break;
|
||||
case "poll":
|
||||
rs.append(AndroidUtils.getString(item.optBoolean("anonymous") ? R.string.chat_export_poll_anon : R.string.chat_export_poll_publ)).append(" ").append(AndroidUtils.getString(R.string.chat_export_type_poll)).append(" ").append(getPollHtml(item));
|
||||
break;
|
||||
case "market":
|
||||
var market_item_link = "https://" + VK_DOMAIN + "/market" + item.optString("owner_id") + "_" + item.optString("id");
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"").append(market_item_link).append("\">").append(AndroidUtils.getString(R.string.chat_export_type_market)).append("</a>");
|
||||
break;
|
||||
default:
|
||||
rs.append(AndroidUtils.getString(R.string.vkim_msg_unsupported)).append(" (").append(type).append(")");
|
||||
break;
|
||||
}
|
||||
|
||||
rs.append(" ");
|
||||
}
|
||||
|
||||
return rs.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,18 +9,20 @@ import android.content.IntentFilter;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import b.h.g.m.FileUtils;
|
||||
import ru.vtosters.lite.ui.activities.APKInstallActivity;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class OTADownloader {
|
||||
|
||||
private static final BroadcastReceiver callback = new BroadcastReceiver() {
|
||||
@SuppressLint("Range")
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
var extras = intent.getExtras();
|
||||
@@ -30,24 +32,15 @@ public class OTADownloader {
|
||||
var query = new DownloadManager.Query();
|
||||
var id = extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID);
|
||||
query.setFilterById(id);
|
||||
var manager = (DownloadManager) AndroidUtils.getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
var manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
var cursor = manager.query(query);
|
||||
if (cursor.moveToFirst()) {
|
||||
@SuppressLint("Range") var status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
|
||||
if (status == DownloadManager.STATUS_SUCCESSFUL) {
|
||||
var downloadDir = new File(Environment.getExternalStorageDirectory(), "Download");
|
||||
if (!downloadDir.exists()) return;
|
||||
var list = downloadDir.listFiles();
|
||||
if (list == null || list.length == 0) return;
|
||||
var maxIndex = -1;
|
||||
for (File file : list) {
|
||||
var name = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf("/") + 1);
|
||||
if (file.isFile()
|
||||
&& name.matches("VTLite-\\d+\\.apk"))
|
||||
maxIndex = Math.max(maxIndex, Integer.parseInt(name.replaceFirst(".+-(\\d+).+", "$1")));
|
||||
}
|
||||
File apk = maxIndex == -1 ? new File(downloadDir, "VTLite.apk") : new File(downloadDir, "VTLite-" + maxIndex + ".apk");
|
||||
APKInstallActivity.installOta(context, FileUtils.uriFromFile(apk));
|
||||
var uriStr = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
|
||||
var apk = new File(uriStr.replace("file://", ""));
|
||||
var uri = FileProvider.getUriForFile(context, "com.vtosters.lite.common.VKFileProvider", apk);
|
||||
APKInstallActivity.installOta(context, uri);
|
||||
} else if (status == DownloadManager.STATUS_FAILED) {
|
||||
AndroidUtils.sendToast(context.getString(R.string.downloaderr));
|
||||
}
|
||||
@@ -55,7 +48,7 @@ public class OTADownloader {
|
||||
}
|
||||
};
|
||||
|
||||
public static void downloadBuild(String url) {
|
||||
public static void downloadBuild(String url, String commitSHA) {
|
||||
var context = AndroidUtils.getGlobalContext();
|
||||
try {
|
||||
var uri = Uri.parse(url);
|
||||
@@ -64,8 +57,8 @@ public class OTADownloader {
|
||||
|
||||
var request = new DownloadManager.Request(uri);
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setTitle("VTLite.apk");
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "VTLite.apk");
|
||||
request.setTitle(AndroidUtils.getString("downloading_update"));
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "VTLite-" + commitSHA + ".apk");
|
||||
|
||||
var manager = (DownloadManager) AndroidUtils.getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
manager.enqueue(request);
|
||||
|
||||
@@ -7,32 +7,35 @@ import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.dto.common.ImageSize;
|
||||
import com.vk.dto.stories.model.StoryEntry;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class StoryDownloader {
|
||||
public static Runnable injectButton(StoryEntry story) {
|
||||
return () -> {
|
||||
// if story is a pic
|
||||
if (story.T1()) {
|
||||
List<ImageSize> imageSizes = story.E.Q.t1();
|
||||
String url = imageSizes.get(imageSizes.size() - 1).url;
|
||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setTitle("photo" + story.E.a + ".jpg");
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, "photo" + story.E.a + ".jpg");
|
||||
request.allowScanningByMediaScanner();
|
||||
((DownloadManager) getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
|
||||
return;
|
||||
}
|
||||
return () -> downloadStory(story);
|
||||
}
|
||||
|
||||
// if story is a video
|
||||
if (story.F != null) {
|
||||
downloadVideo(story.F, null);
|
||||
}
|
||||
};
|
||||
public static void downloadStory(StoryEntry story){
|
||||
if (story.T1()) {
|
||||
List<ImageSize> imageSizes = story.E.Q.t1();
|
||||
String url = imageSizes.get(imageSizes.size() - 1).url;
|
||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setTitle("photo" + story.E.a + ".jpg");
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, "photo" + story.E.a + ".jpg");
|
||||
request.allowScanningByMediaScanner();
|
||||
((DownloadManager) getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
|
||||
return;
|
||||
}
|
||||
// if story is a video
|
||||
if (story.F != null) {
|
||||
downloadVideo(story.F, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,35 @@
|
||||
package ru.vtosters.lite.downloaders;
|
||||
|
||||
import static ru.vtosters.lite.net.Request.makeRequest;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
import android.app.DownloadManager;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.core.dialogs.bottomsheet.MenuBottomSheetAction;
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vk.dto.common.VideoFile;
|
||||
import com.vk.dto.stories.model.StoryEntry;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.utils.ExternalLinkParser;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import ru.vtosters.lite.utils.ExternalLinkParser;
|
||||
import static ru.vtosters.lite.net.Request.makeRequest;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
public class VideoDownloader {
|
||||
private static final int DOWNLOAD_ID = 0;
|
||||
@@ -54,77 +57,105 @@ public class VideoDownloader {
|
||||
}
|
||||
|
||||
public static void downloadVideo(VideoFile videoFile, Context context) {
|
||||
final List<String> list = new ArrayList<>();
|
||||
final List<String> qualities = new ArrayList<>();
|
||||
final List<String> urls = new ArrayList<>();
|
||||
|
||||
if (!Objects.equals(videoFile.e, "")) {
|
||||
list.add("240p");
|
||||
urls.add(videoFile.e);
|
||||
}
|
||||
if (!Objects.equals(videoFile.f, "")) {
|
||||
list.add("360p");
|
||||
urls.add(videoFile.f);
|
||||
}
|
||||
if (!Objects.equals(videoFile.g, "")) {
|
||||
list.add("480p");
|
||||
urls.add(videoFile.g);
|
||||
}
|
||||
if (!Objects.equals(videoFile.h, "")) {
|
||||
list.add("720p");
|
||||
urls.add(videoFile.h);
|
||||
}
|
||||
if (!Objects.equals(videoFile.B, "")) {
|
||||
list.add("1080p");
|
||||
urls.add(videoFile.B);
|
||||
}
|
||||
if (!Objects.equals(videoFile.C, "")) {
|
||||
list.add("1440p");
|
||||
urls.add(videoFile.C);
|
||||
}
|
||||
if (!Objects.equals(videoFile.D, "")) {
|
||||
list.add("2160p");
|
||||
if (!TextUtils.isEmpty(videoFile.D)) {
|
||||
qualities.add("2160p");
|
||||
urls.add(videoFile.D);
|
||||
}
|
||||
|
||||
if (list.isEmpty()) {
|
||||
ToastUtils.a(context.getString(R.string.videodownloaderr));
|
||||
if (!TextUtils.isEmpty(videoFile.C)) {
|
||||
qualities.add("1440p");
|
||||
urls.add(videoFile.C);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(videoFile.B)) {
|
||||
qualities.add("1080p");
|
||||
urls.add(videoFile.B);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(videoFile.h)) {
|
||||
qualities.add("720p");
|
||||
urls.add(videoFile.h);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(videoFile.g)) {
|
||||
qualities.add("480p");
|
||||
urls.add(videoFile.g);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(videoFile.f)) {
|
||||
qualities.add("360p");
|
||||
urls.add(videoFile.f);
|
||||
}
|
||||
if (!TextUtils.isEmpty(videoFile.e)) {
|
||||
qualities.add("240p");
|
||||
urls.add(videoFile.e);
|
||||
}
|
||||
|
||||
Context finalContext = context != null ? context : LifecycleUtils.getCurrentActivity();
|
||||
|
||||
if (qualities.isEmpty()) {
|
||||
ToastUtils.a(finalContext.getString(R.string.videodownloaderr));
|
||||
return;
|
||||
}
|
||||
|
||||
var max = new String[list.size()];
|
||||
var adapter = new ArrayAdapter(
|
||||
finalContext,
|
||||
android.R.layout.simple_list_item_1,
|
||||
qualities.toArray(new String[0])) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
TextView textView = (TextView) super.getView(position, convertView, parent);
|
||||
textView.setTextColor(getTextAttr());
|
||||
return textView;
|
||||
}
|
||||
};
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
max[i] = list.get(i);
|
||||
}
|
||||
|
||||
if (context == null) {
|
||||
var url = urls.get(urls.size() - 1);
|
||||
|
||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setTitle(videoFile.toString());
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_MOVIES, videoFile + ".mp4");
|
||||
((DownloadManager) getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
|
||||
return;
|
||||
}
|
||||
|
||||
new VkAlertDialog.Builder(context)
|
||||
.setItems(max, ((dialog, which) -> {
|
||||
var url = urls.get(which);
|
||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setTitle(videoFile.toString());
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_MOVIES, videoFile + ".mp4");
|
||||
((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
|
||||
}))
|
||||
.show();
|
||||
new VkAlertDialog.Builder(finalContext)
|
||||
.setAdapter(adapter, (dialog, which) -> {
|
||||
try {
|
||||
var url = urls.get(which);
|
||||
var request = new DownloadManager.Request(Uri.parse(url))
|
||||
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
||||
.setTitle(videoFile.toString())
|
||||
.setDestinationInExternalPublicDir(Environment.DIRECTORY_MOVIES, videoFile + ".mp4");
|
||||
request.allowScanningByMediaScanner();
|
||||
((DownloadManager) finalContext.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void parseVideoLink(String url, Context ctx) {
|
||||
if (url.startsWith("http://")) {
|
||||
url.replace("http://", "https://");
|
||||
} else if (url.startsWith("vk.com"))
|
||||
url = "https://" + url;
|
||||
|
||||
if (url.contains("vk.com/story")) {
|
||||
ToastUtils.a(ctx.getString(R.string.video_dl_stories_not_supported));
|
||||
String storyId = url.substring(url.startsWith("https") ? 20 : 19) + "_story";
|
||||
|
||||
ProgressDialog progressDialog = new ProgressDialog(ctx);
|
||||
progressDialog.setMessage(ctx.getString(R.string.video_dl_progress));
|
||||
progressDialog.show();
|
||||
|
||||
makeRequest("https://" + getApi() + "/method/stories.getById?stories=" + storyId + "&v=5.99&access_token=" + getUserToken(),
|
||||
response -> {
|
||||
progressDialog.cancel();
|
||||
|
||||
try {
|
||||
JSONObject mainJson = new JSONObject(response);
|
||||
JSONObject responseJson = mainJson.getJSONObject("response").optJSONArray("items").optJSONObject(0);
|
||||
StoryEntry story = new StoryEntry(responseJson);
|
||||
StoryDownloader.downloadStory(story);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(ctx, ctx.getString(R.string.video_dl_error), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package ru.vtosters.lite.downloaders.messages;
|
||||
|
||||
public class Constants {
|
||||
public static final String VK_DOMAIN = "vk.com";
|
||||
public static final String HTML_DOC_STYLE = ".vtex-milk-msg {\n" +
|
||||
" border-radius: 8px;\n" +
|
||||
" padding: 24px;\n" +
|
||||
" background: white;\n" +
|
||||
" margin: 16px;\n" +
|
||||
" box-shadow: 0 4px 8px 0 rgba(0,0,0,0.07);\n" +
|
||||
" word-wrap: break-word;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".vtex-milk-msgcont br {\n" +
|
||||
" display: none;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".vtex-milk-msg p {\n" +
|
||||
" margin: 0;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".vtex-milk-msg.vtex-milk-msg-out {\n" +
|
||||
" background: #ADD3FF;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"p.msg-attaches {\n" +
|
||||
" margin-top: 8px;\n" +
|
||||
" font-style: italic;\n" +
|
||||
"}\n" +
|
||||
"p.chat-action {\n" +
|
||||
" font-style: italic;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".vtex-milk-header {\n" +
|
||||
" border-radius: 8px;\n" +
|
||||
" padding: 24px;\n" +
|
||||
" background: white;\n" +
|
||||
" margin: 16px;\n" +
|
||||
" box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"h4.vtex-milk-header-txt {\n" +
|
||||
" margin: 0;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"h5.vtex-milk-header-sub {\n" +
|
||||
" margin: 0;\n" +
|
||||
" padding-top: 8px;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"a.msg-attach-link {\n" +
|
||||
" color: #5181B8;\n" +
|
||||
" text-decoration: none;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".msg-from a {\n" +
|
||||
" color: #5181B8;\n" +
|
||||
" text-decoration: none;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".msg-from-date {\n" +
|
||||
" color: rgba(0, 0, 0, 0.75);\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"body {\n" +
|
||||
" font-family: Roboto, system-ui, sans-serif;\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
".msg-body {\n" +
|
||||
" padding-top: 4px;\n" +
|
||||
"}\n" +
|
||||
".msg-reply {\n" +
|
||||
" border-left: 3px solid #7aa7f6;\n" +
|
||||
" margin-top: 5px;\n" +
|
||||
" padding-left: 3px;\n" +
|
||||
"}\n\n" +
|
||||
".msg-reply p {\n" +
|
||||
" padding-left: 5px;\n" +
|
||||
"}\n\n" +
|
||||
".msg-reply p.reply-header {\n" +
|
||||
" color: #5181B8;\n" +
|
||||
"}\n\n" +
|
||||
".msg-reply p.reply-content {\n" +
|
||||
" color: #000000;\n" +
|
||||
"}\n" +
|
||||
".vtex-milk-msg.poll {\n" +
|
||||
" width: 45%;\n" +
|
||||
" background: linear-gradient(to bottom right, #707c8c, #4d5565);\n" +
|
||||
" font-style: normal;" +
|
||||
"}\n" +
|
||||
".vtex-milk-msg.poll p { color: white; }\n" +
|
||||
".vtex-milk-msg.poll hr { border-top: 1px; background: #ffffff; }\n" +
|
||||
"\n" +
|
||||
"";
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package ru.vtosters.lite.downloaders.messages;
|
||||
|
||||
import org.json.JSONException;
|
||||
import ru.vtosters.lite.downloaders.messages.items.MiniMsg;
|
||||
import ru.vtosters.lite.downloaders.messages.items.MiniUser;
|
||||
|
||||
// This class defines everything which is needed to create an output file
|
||||
public abstract class DialogDownloaderFormatProvider {
|
||||
// Internal, for JSON/HTML
|
||||
public abstract String provideDocumentStart(String dialogName, String date);
|
||||
|
||||
public abstract String provideDocumentEnd();
|
||||
|
||||
public abstract String provideHeader(String dialogName, String date);
|
||||
|
||||
public abstract String provideMessage(MiniMsg message, MiniUser user) throws JSONException;
|
||||
}
|
||||
+435
@@ -0,0 +1,435 @@
|
||||
package ru.vtosters.lite.downloaders.messages;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.downloaders.messages.items.MiniMsg;
|
||||
import ru.vtosters.lite.downloaders.messages.items.MiniUser;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static ru.vtosters.lite.encryption.EncryptProvider.decryptMessage;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserId;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getArray;
|
||||
|
||||
public class HtmlDialogDownloaderFormatProvider extends DialogDownloaderFormatProvider {
|
||||
|
||||
@Override
|
||||
public String provideDocumentStart(String dialogName, String date) {
|
||||
|
||||
return "<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><meta charset=\"utf-8\"><title>"
|
||||
+ AndroidUtils.getString(R.string.chat_export_title)
|
||||
+ "</title><style>"
|
||||
+ Constants.HTML_DOC_STYLE
|
||||
+ "</style></head><body>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String provideDocumentEnd() {
|
||||
return "</div></body></html>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String provideHeader(String dialogName, String date) {
|
||||
return "<div class=\"vtex-milk-header\"><h4 class=\"vtex-milk-header-txt\">VTLite</h4><h5 class=\"vtex-milk-header-sub\">"
|
||||
+ AndroidUtils.getString(R.string.chat_export_header)
|
||||
+ " (" + date + ")</h5></div><div class=\"vtex-milk-msgcont\">";
|
||||
}
|
||||
@Override
|
||||
public String provideMessage(MiniMsg message, MiniUser user) throws JSONException {
|
||||
String isOut = (user.id == getUserId()) ? " vtex-milk-msg-out" : "";
|
||||
|
||||
String geoPosition = "";
|
||||
if (message.geo != null) {
|
||||
var coordinates = message.geo.optJSONObject("coordinates");
|
||||
if (coordinates != null) {
|
||||
var latitude = coordinates.optDouble("latitude");
|
||||
var longitude = coordinates.optDouble("longitude");
|
||||
var ll = longitude + "," + latitude;
|
||||
geoPosition = "<a href=\"https://yandex.ru/maps/?ll=" + ll + "&mode=search&sll=" + ll + "&text=" + latitude + "," + longitude + "&z=12\">" +
|
||||
"<img src=\"https://static-maps.yandex.ru/1.x/?ll=" + longitude + "," + latitude + "&z=12&l=map&size=300,200&pt=" + ll + ",vkgrm\"/>" +
|
||||
"</a>";
|
||||
}
|
||||
}
|
||||
|
||||
String chatAction = (message.chat_action != null) ? getHtmlForChatAction(message.chat_action) : "";
|
||||
String attaches = (message.attachments.size() > 0) ? "<p class=\"msg-attaches\">" + AndroidUtils.getString(R.string.attachments) + ": " + getHtmlForAttach(message.attachments) + "</p>" : "";
|
||||
String reply = (message.reply_message != null) ? provideReply(message.reply_message) : "";
|
||||
String fwdMessages = (message.fwd_messages.size() > 0) ? provideForwardMessages(message.fwd_messages) : "";
|
||||
String userLink = (user.isGroup ? "club" : "id") + user.id;
|
||||
|
||||
return "<div class=\"vtex-milk-msg" + isOut + "\" id=\"" + message.id + "\">" +
|
||||
"<p class=\"msg-from\">" + AndroidUtils.getString(R.string.from_lower)
|
||||
+ " <a href=\"https://" + Constants.VK_DOMAIN + "/" + userLink + "\">" + user.firstName + " " + user.lastName
|
||||
+ "</a> <span class=\"msg-from-date\">" + MessagesDownloader.formatTime(message.date) + "</span></p>" + // TODO photo100
|
||||
"<p class=\"msg-body\">" + mentionsReplace(message.text) + "</p>" +
|
||||
geoPosition +
|
||||
chatAction +
|
||||
attaches +
|
||||
reply +
|
||||
fwdMessages +
|
||||
"</div>";
|
||||
}
|
||||
|
||||
private String provideReply(JSONObject replyMessage) {
|
||||
var text = mentionsReplace(decryptMessage(replyMessage.optString("text"), replyMessage.optInt("peer_id")));
|
||||
var fwdMessages = replyMessage.optJSONArray("fwd_messages");
|
||||
|
||||
var user = MessagesDownloader.usersArray.get(replyMessage.optInt("from_id"));
|
||||
|
||||
if (text.isEmpty()) {
|
||||
if (fwdMessages != null) {
|
||||
var length = fwdMessages.length();
|
||||
if (length > 0) text = length + " " + pluralMsg(length);
|
||||
} else text = AndroidUtils.getString(R.string.attachment); // Вложение
|
||||
}
|
||||
|
||||
return "<a href=\"#" + replyMessage.optInt("id") + "\" class=\"msg-attach-link\">" +
|
||||
"<div class=\"msg-reply\">" +
|
||||
"<p class=\"reply-header\">" + AndroidUtils.getString(R.string.vkim_msg_fwd_single) + "</p>" +
|
||||
"<p class=\"reply-content\">" + user.firstName + " " + user.lastName + ": " + text + "</p>" +
|
||||
"</div>" +
|
||||
"</a>";
|
||||
}
|
||||
|
||||
private String provideForwardMessages(List<JSONObject> fwd_messages) throws JSONException {
|
||||
StringBuilder fwdmsgs = new StringBuilder("<div class=\"msg-reply\">");
|
||||
|
||||
for (JSONObject fwd_message : fwd_messages) {
|
||||
|
||||
if (fwd_message == null) continue;
|
||||
|
||||
List<JSONObject> attaches = new ArrayList<>();
|
||||
|
||||
JSONArray arr = fwd_message.optJSONArray("attachments");
|
||||
if (arr != null) {
|
||||
for (int i = 0; i < arr.length(); i++) {
|
||||
try {
|
||||
attaches.add(arr.getJSONObject(i));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<JSONObject> fwdsMsg = new ArrayList<>();
|
||||
|
||||
JSONArray fwd_msgs = fwd_message.optJSONArray("fwd_messages");
|
||||
if (fwd_msgs != null) {
|
||||
for (int i = 0; i < fwd_msgs.length(); i++) {
|
||||
try {
|
||||
fwdsMsg.add(fwd_msgs.getJSONObject(i));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject reply_message = fwd_message.optJSONObject("reply_message");
|
||||
|
||||
var attachesHtml = (attaches.size() > 0) ? AndroidUtils.getString(R.string.attachments) + ": " + getHtmlForAttach(attaches) : "";
|
||||
var replyHtml = (reply_message != null) ? provideReply(reply_message) : "";
|
||||
var fwdsHtml = (fwdsMsg.size() > 0) ? provideForwardMessages(fwdsMsg) : ""; // recursion XD :>
|
||||
|
||||
var userId = fwd_message.optInt("from_id");
|
||||
var peerId = fwd_message.optInt("peer_id");
|
||||
var text = mentionsReplace(decryptMessage(fwd_message.optString("text"), peerId));
|
||||
|
||||
var userLink = ((userId < 0) ? "club" : "id") + Math.abs(userId);
|
||||
|
||||
fwdmsgs.append("<p class=\"reply-content\"><a class=\"msg-attach-link\" href=\"https://" + Constants.VK_DOMAIN + "/")
|
||||
.append(userLink)
|
||||
.append("\">@")
|
||||
.append(userLink)
|
||||
.append("</a>: ")
|
||||
.append(text)
|
||||
.append(attachesHtml)
|
||||
.append(replyHtml)
|
||||
.append(fwdsHtml);
|
||||
}
|
||||
|
||||
return fwdmsgs.append("</div>").toString();
|
||||
}
|
||||
|
||||
private String mentionsReplace(String text) {
|
||||
var matcher = Pattern.compile("\\[((?:club|id|public)\\d+)\\|([^]]+)\\]").matcher(text);
|
||||
|
||||
return matcher.replaceAll("<a class=\"msg-attach-link\" href=\"https://" + Constants.VK_DOMAIN + "/$1\">$2</a>");
|
||||
}
|
||||
|
||||
private String pluralMsg(int count) {
|
||||
String[] plurals = getArray(R.array.msg_plurals);
|
||||
|
||||
var hundredModulo = count % 100;
|
||||
var tenModulo = count % 10;
|
||||
|
||||
if (hundredModulo > 10 && hundredModulo < 20) return plurals[2];
|
||||
else if (tenModulo > 1 && tenModulo < 5) return plurals[1];
|
||||
else if (tenModulo == 1) return plurals[0];
|
||||
|
||||
return plurals[2];
|
||||
}
|
||||
|
||||
private String getHtmlForChatAction(JSONObject action) {
|
||||
var type = action.optString("type");
|
||||
|
||||
StringBuilder htmlAction = new StringBuilder("<p class=\"chat-action\">");
|
||||
|
||||
switch (type) {
|
||||
case "chat_photo_update":
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_avatar_update));
|
||||
break;
|
||||
case "chat_photo_remove":
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_avatar_remove));
|
||||
break;
|
||||
case "chat_create":
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_chat_created));
|
||||
var name = action.optString("text");
|
||||
if (!name.isEmpty())
|
||||
htmlAction.append(" \"").append(name).append("\"");
|
||||
break;
|
||||
case "chat_title_update":
|
||||
var newName = action.optString("text");
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_name_changed));
|
||||
if (!newName.isEmpty())
|
||||
htmlAction.append(" ")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_to))
|
||||
.append(" \"")
|
||||
.append(newName)
|
||||
.append("\"");
|
||||
break;
|
||||
case "chat_invite_user":
|
||||
var newMemberId = action.optInt("member_id");
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_user_added))
|
||||
.append(" ");
|
||||
if (newMemberId != 0) {
|
||||
int id;
|
||||
String endpoint;
|
||||
if (newMemberId >= 0) {
|
||||
id = R.string.chat_export_type_user;
|
||||
endpoint = "id" + newMemberId;
|
||||
} else {
|
||||
id = R.string.chat_export_type_group;
|
||||
endpoint = "club" + -newMemberId;
|
||||
}
|
||||
htmlAction.append(AndroidUtils.getString(id))
|
||||
.append(" <a href=\"https://" + Constants.VK_DOMAIN + "/")
|
||||
.append(endpoint)
|
||||
.append("\" class=\"msg-attach-link\">@")
|
||||
.append(endpoint)
|
||||
.append("</a>");
|
||||
}
|
||||
break;
|
||||
case "chat_kick_user":
|
||||
var removedMemberId = action.optInt("member_id");
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_user_kicked))
|
||||
.append(" ");
|
||||
if (removedMemberId != 0) {
|
||||
int id;
|
||||
String endpoint;
|
||||
if (removedMemberId >= 0) {
|
||||
id = R.string.chat_export_type_user;
|
||||
endpoint = "id" + removedMemberId;
|
||||
} else {
|
||||
id = R.string.chat_export_type_group;
|
||||
endpoint = "club" + -removedMemberId;
|
||||
}
|
||||
htmlAction.append(AndroidUtils.getString(id))
|
||||
.append(" <a href=\"https://" + Constants.VK_DOMAIN + "/")
|
||||
.append(endpoint)
|
||||
.append("\" class=\"msg-attach-link\">@")
|
||||
.append(endpoint)
|
||||
.append("</a>");
|
||||
}
|
||||
break;
|
||||
case "chat_pin_message":
|
||||
var message = action.optString("message");
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_msg_pinned));
|
||||
if (!message.isEmpty()) htmlAction.append(" \"").append(message).append("\"");
|
||||
break;
|
||||
case "chat_unpin_message":
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_msg_unpinned));
|
||||
break;
|
||||
case "chat_invite_user_by_link":
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_join_by_link));
|
||||
break;
|
||||
case "chat_screenshot":
|
||||
htmlAction.append(AndroidUtils.getString(R.string.chat_export_chat_screenshot));
|
||||
break;
|
||||
case "custom":
|
||||
htmlAction.append(action.optString("message"));
|
||||
break;
|
||||
default:
|
||||
htmlAction.append(AndroidUtils.getString(R.string.vkim_msg_unsupported)).append(" (").append(type).append(")");
|
||||
break;
|
||||
}
|
||||
|
||||
return htmlAction.append("</p>").toString();
|
||||
}
|
||||
|
||||
private String getHtmlForAttach(List<JSONObject> attaches) throws JSONException {
|
||||
StringBuilder rs = new StringBuilder();
|
||||
|
||||
for (JSONObject attach : attaches) {
|
||||
String type = attach.getString("type");
|
||||
JSONObject item = attach.optJSONObject(type);
|
||||
|
||||
if (item == null) continue;
|
||||
|
||||
switch (type) { // market_album is not supported
|
||||
case "photo":
|
||||
var sizes = item.getJSONArray("sizes");
|
||||
rs.append("<a href=\"")
|
||||
.append(sizes.getJSONObject(sizes.length() - 1).getString("url"))
|
||||
.append("\" class=\"msg-attach-link\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_photo))
|
||||
.append("</a>");
|
||||
break;
|
||||
case "doc":
|
||||
rs.append("<a href=\"")
|
||||
.append(item.getString("url"))
|
||||
.append("\" class=\"msg-attach-link\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_doc))
|
||||
.append("</a>");
|
||||
break;
|
||||
case "link":
|
||||
rs.append("<a href=\"")
|
||||
.append(item.getString("url"))
|
||||
.append("\" class=\"msg-attach-link\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_link))
|
||||
.append("</a>");
|
||||
break;
|
||||
case "wall":
|
||||
rs.append("<a href=\"https://" + Constants.VK_DOMAIN + "/wall")
|
||||
.append(item.optString("to_id", item.optString("owner_id")))
|
||||
.append("_").append(item.getString("id"))
|
||||
.append("\" class=\"msg-attach-link\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_wallpost))
|
||||
.append("</a>");
|
||||
break;
|
||||
case "sticker":
|
||||
rs.append("<img style=\"width:128px;height:128px;\" src=\"")
|
||||
.append(item.getJSONArray("images")
|
||||
.getJSONObject(1)
|
||||
.getString("url"))
|
||||
.append("\"/>");
|
||||
break;
|
||||
case "audio_message":
|
||||
rs.append("<a href=\"")
|
||||
.append(item.optString("link_mp3"))
|
||||
.append("\" class=\"msg-attach-link\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_audiomsg))
|
||||
.append("</a>");
|
||||
break;
|
||||
case "audio":
|
||||
rs.append(AndroidUtils.getString(R.string.chat_export_type_audio))
|
||||
.append(" (")
|
||||
.append(item.optString("artist"))
|
||||
.append(" — ")
|
||||
.append(item.optString("title"))
|
||||
.append(")");
|
||||
break;
|
||||
case "video":
|
||||
rs.append(AndroidUtils.getString(R.string.chat_export_type_video))
|
||||
.append(" (")
|
||||
.append(MessagesDownloader.getVideoHtml(item.optJSONObject("files")))
|
||||
.append(")");
|
||||
break;
|
||||
case "wall_reply":
|
||||
var link = String.format("https://" + Constants.VK_DOMAIN + "/wall%s_%s?reply=%s",
|
||||
item.optString("owner_id"),
|
||||
item.optString("post_id"),
|
||||
item.optString("id"));
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"")
|
||||
.append(link).append("\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_wallreply))
|
||||
.append("</a>");
|
||||
break;
|
||||
case "story":
|
||||
var story_link = String.format("https://" + Constants.VK_DOMAIN + "/story%s_%s",
|
||||
item.optString("owner_id"),
|
||||
item.optString("id"));
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"")
|
||||
.append(story_link)
|
||||
.append("\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_story))
|
||||
.append("</a>");
|
||||
break;
|
||||
case "podcast":
|
||||
var podcast_link = String.format("https://" + Constants.VK_DOMAIN + "/podcast%s_%s",
|
||||
item.optString("owner_id"),
|
||||
item.optString("id"));
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"")
|
||||
.append(podcast_link)
|
||||
.append("\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_podcast))
|
||||
.append("</a>");
|
||||
break;
|
||||
case "gift":
|
||||
rs.append("<img src=\"")
|
||||
.append(item.optString("thumb_96"))
|
||||
.append("\"/>");
|
||||
break;
|
||||
case "mini_app":
|
||||
var app = item.optJSONObject("app");
|
||||
|
||||
if (app != null) {
|
||||
var miniapp_link = String.format("https://" + Constants.VK_DOMAIN + "/app%s", app.optString("id"));
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"")
|
||||
.append(miniapp_link)
|
||||
.append("\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_miniapp))
|
||||
.append("</a>");
|
||||
break;
|
||||
}
|
||||
|
||||
rs.append(AndroidUtils.getString(R.string.chat_export_error));
|
||||
break;
|
||||
case "audio_playlist":
|
||||
var playlist_link = String.format("https://" + Constants.VK_DOMAIN + "/music/album/%s_%s_%s",
|
||||
item.optString("owner_id"),
|
||||
item.optString("id"),
|
||||
item.optString("access_key"));
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"")
|
||||
.append(playlist_link)
|
||||
.append("\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_playlist))
|
||||
.append(" (")
|
||||
.append(item.optString("title"))
|
||||
.append(")</a>");
|
||||
break;
|
||||
case "poll":
|
||||
rs.append(AndroidUtils.getString(item.optBoolean("anonymous") ? R.string.chat_export_poll_anon : R.string.chat_export_poll_publ))
|
||||
.append(" ")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_poll))
|
||||
.append(" ")
|
||||
.append(MessagesDownloader.getPollHtml(item));
|
||||
break;
|
||||
case "market":
|
||||
var market_item_link = String.format("https://" + Constants.VK_DOMAIN + "/market%s_%s",
|
||||
item.optString("owner_id"),
|
||||
item.optString("id"));
|
||||
rs.append("<a class=\"msg-attach-link\" href=\"")
|
||||
.append(market_item_link)
|
||||
.append("\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_type_market))
|
||||
.append("</a>");
|
||||
break;
|
||||
default:
|
||||
rs.append(AndroidUtils.getString(R.string.vkim_msg_unsupported))
|
||||
.append(" (")
|
||||
.append(type)
|
||||
.append(")");
|
||||
break;
|
||||
}
|
||||
|
||||
rs.append(" ");
|
||||
}
|
||||
|
||||
return rs.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package ru.vtosters.lite.downloaders.messages;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vtosters.lite.R;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
import ru.vtosters.lite.downloaders.messages.items.MiniMsg;
|
||||
import ru.vtosters.lite.downloaders.messages.items.MiniUser;
|
||||
import ru.vtosters.lite.proxy.ProxyUtils;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class MessagesDownloader {
|
||||
private static final int[] VIDEO_QUALITIES = { 144, 240, 360, 480, 720, 1080, 1440, 2160 };
|
||||
|
||||
private static final SimpleDateFormat SDFORMAT = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", AndroidUtils.getResources().getConfiguration().locale);
|
||||
|
||||
public static SparseArray<MiniUser> usersArray;
|
||||
|
||||
public static String formatTime(long now) {
|
||||
return SDFORMAT.format(new Date(now));
|
||||
}
|
||||
|
||||
public static String getPollHtml(JSONObject poll) {
|
||||
StringBuilder pollHtml = new StringBuilder(
|
||||
"<div class=\"vtex-milk-msg poll\">" +
|
||||
"<p style=\"text-align:center;\">" + poll.optString("question") + "</p>"
|
||||
);
|
||||
|
||||
var answers = poll.optJSONArray("answers");
|
||||
|
||||
for (int i = 0; i < answers.length(); i++) {
|
||||
var jsonObject = answers.optJSONObject(i);
|
||||
if (jsonObject != null)
|
||||
pollHtml.append("<hr><p>")
|
||||
.append(jsonObject.optString("text"))
|
||||
.append(" · ")
|
||||
.append(jsonObject.optString("votes"))
|
||||
.append(" (")
|
||||
.append(jsonObject.optString("rate"))
|
||||
.append("%)</p>");
|
||||
}
|
||||
|
||||
pollHtml.append("<hr><p style=\"text-align:center;\">")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_poll_voted))
|
||||
.append(" ")
|
||||
.append(poll.optString("votes"))
|
||||
.append(" ")
|
||||
.append(AndroidUtils.getString(R.string.chat_export_users_name))
|
||||
.append("</p>")
|
||||
.append("</div>");
|
||||
|
||||
return pollHtml.toString();
|
||||
}
|
||||
|
||||
public static String getVideoHtml(JSONObject files) throws JSONException {
|
||||
if (files == null) return AndroidUtils.getString(R.string.chat_export_video_nolinks);
|
||||
|
||||
Iterator<? extends String> keys = files.keys();
|
||||
StringBuilder videoHtml = new StringBuilder();
|
||||
|
||||
int i = 0;
|
||||
while (keys.hasNext() && i < VIDEO_QUALITIES.length) {
|
||||
var key = keys.next();
|
||||
if (key.equals("mp4_" + VIDEO_QUALITIES[i])) {
|
||||
videoHtml.append("<a class=\"msg-attach-link\" href=\"")
|
||||
.append(files.get(key))
|
||||
.append("\">")
|
||||
.append(VIDEO_QUALITIES[i])
|
||||
.append("p</a>")
|
||||
.append(" ");
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
return videoHtml.toString();
|
||||
}
|
||||
|
||||
public void downloadDialog(int peer_id, DialogDownloaderFormatProvider format, File out) throws Exception {
|
||||
FileOutputStream fos = new FileOutputStream(out);
|
||||
|
||||
// fix TODO with conversation name (API method messages.getConversationsById)
|
||||
fos.write(format.provideDocumentStart("TODO", formatTime(System.currentTimeMillis())).getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
var url = String.format("https://" + ProxyUtils.getApi() + "/method/messages.getHistory?extended=1&v=5.140&offset=%d&count=200&peer_id=%d&access_token=%s",
|
||||
0,
|
||||
peer_id,
|
||||
AccountManagerUtils.getUserToken());
|
||||
var req = new Request.a()
|
||||
.b(url)
|
||||
.a();
|
||||
VtOkHttpClient.getInstance().a(req).a(new Callback() {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
Log.d("MessagesDownloader", e+"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(Call call, Response response)
|
||||
throws IOException {
|
||||
try {
|
||||
JSONObject obj = new JSONObject(response.a().g()).getJSONObject("response");
|
||||
|
||||
SparseArray<MiniUser> users = new SparseArray<>();
|
||||
parseUsers(users, obj.optJSONArray("profiles"), false);
|
||||
parseUsers(users, obj.optJSONArray("groups"), true);
|
||||
|
||||
List<MiniMsg> msgs = parseMessages(obj.getJSONArray("items"));
|
||||
|
||||
usersArray = users;
|
||||
|
||||
fos.write(format.provideHeader("TODO", formatTime(System.currentTimeMillis())).getBytes(StandardCharsets.UTF_8));
|
||||
for (MiniMsg msg : msgs) {
|
||||
fos.write(format.provideMessage(msg, users.get(msg.fromId)).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
fos.write(format.provideDocumentEnd().getBytes(StandardCharsets.UTF_8));
|
||||
fos.close();
|
||||
ToastUtils.a(AndroidUtils.getString(R.string.saved_as) + " " + out.getAbsolutePath());
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<MiniMsg> parseMessages(JSONArray jsonArray) throws JSONException {
|
||||
List<MiniMsg> thing = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < jsonArray.length(); i++)
|
||||
thing.add(new MiniMsg(jsonArray.getJSONObject(i)));
|
||||
|
||||
return thing;
|
||||
}
|
||||
|
||||
private void parseUsers(SparseArray<MiniUser> array, @Nullable JSONArray jsonArray, boolean groups) throws JSONException {
|
||||
if (jsonArray == null) return;
|
||||
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
MiniUser user = new MiniUser(jsonArray.getJSONObject(i), groups);
|
||||
array.put(groups ? -user.id : user.id, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package ru.vtosters.lite.downloaders.messages.items;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static ru.vtosters.lite.encryption.EncryptProvider.decryptMessage;
|
||||
public class MiniMsg {
|
||||
public long date;
|
||||
public int fromId;
|
||||
public int id; // message id
|
||||
public String text;
|
||||
public List<JSONObject> attachments;
|
||||
public List<JSONObject> fwd_messages;
|
||||
public JSONObject reply_message; // one reply
|
||||
public JSONObject chat_action;
|
||||
public JSONObject geo;
|
||||
|
||||
public MiniMsg(JSONObject obj) throws JSONException {
|
||||
date = obj.getLong("date") * 1000;
|
||||
fromId = obj.getInt("from_id");
|
||||
id = obj.getInt("id");
|
||||
text = decryptMessage(obj.getString("text"), obj.getInt("peer_id"));
|
||||
reply_message = obj.optJSONObject("reply_message");
|
||||
chat_action = obj.optJSONObject("action");
|
||||
geo = obj.optJSONObject("geo");
|
||||
|
||||
attachments = new ArrayList<>();
|
||||
fwd_messages = new ArrayList<>();
|
||||
|
||||
JSONArray arr = obj.optJSONArray("attachments");
|
||||
if (arr != null)
|
||||
for (int i = 0; i < arr.length(); i++) attachments.add(arr.getJSONObject(i));
|
||||
|
||||
JSONArray fwdArr = obj.optJSONArray("fwd_messages");
|
||||
if (fwdArr != null)
|
||||
for (int i = 0; i < fwdArr.length(); i++) fwd_messages.add(fwdArr.getJSONObject(i));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package ru.vtosters.lite.downloaders.messages.items;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class MiniUser {
|
||||
public String firstName;
|
||||
public String lastName;
|
||||
public boolean isGroup;
|
||||
public int id;
|
||||
public String photo100;
|
||||
|
||||
public MiniUser(JSONObject obj, boolean is_group) throws JSONException {
|
||||
id = obj.getInt("id");
|
||||
firstName = obj.optString("first_name", obj.optString("name"));
|
||||
lastName = obj.optString("last_name", "");
|
||||
photo100 = obj.getString("photo_100");
|
||||
isGroup = is_group;
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,14 @@ public class EncryptProvider {
|
||||
return (String) decryptMessage(msgBody, peer, showEmoji);
|
||||
}
|
||||
|
||||
public static CharSequence decryptMessage(CharSequence msgBody, MsgFromUser msgFromUser, boolean showEmoji) {
|
||||
try {
|
||||
return decryptMessage((String) msgBody, msgFromUser.v1(), showEmoji);
|
||||
} catch (Exception e) {
|
||||
return decryptMessage((String) msgBody, 0, showEmoji);
|
||||
}
|
||||
}
|
||||
|
||||
// For MentionsFormatter that requires CharSequence
|
||||
public static CharSequence decryptMessage(String msgBody, int peer, boolean showEmoji) {
|
||||
var decryptedMessage = decryptMessage(msgBody, peer);
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
import ru.vtosters.lite.net.Request;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class FoafBase {
|
||||
private static final Pattern FOAF_REGEX = Pattern.compile("<ya:created dc:date=\"(.+?)\"");
|
||||
private static final Pattern FOAF_REGEX_LAST_SEEN = Pattern.compile("<ya:lastLoggedIn dc:date=\"(.*)(((\\+|-)\\d\\d):(\\d\\d))\"");
|
||||
private static final String API_VKNEXT = "https://api.vtosters.app/v1/getBypassedOnlineInfo?json=1&ids=";
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
private static final OkHttpClient client = VtOkHttpClient.getInstance();
|
||||
|
||||
public static long getLastSeen(long origtime, int id) throws ParseException {
|
||||
var request = new okhttp3.Request.a()
|
||||
|
||||
@@ -9,6 +9,7 @@ import static ru.vtosters.lite.utils.Preferences.adsstories;
|
||||
import static ru.vtosters.lite.utils.Preferences.authorsrecomm;
|
||||
import static ru.vtosters.lite.utils.Preferences.dev;
|
||||
import static ru.vtosters.lite.utils.Preferences.friendsrecomm;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.postsrecomm;
|
||||
|
||||
import android.util.Log;
|
||||
@@ -224,6 +225,12 @@ public class AdBlockHook {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasMiniAppAds(list) && !isWhitelistedFilters(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: MiniApp filters");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NewsFeedFiltersUtils.injectFiltersReposts(list) && !isWhitelistedFilters(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: repost ad");
|
||||
@@ -360,4 +367,17 @@ public class AdBlockHook {
|
||||
|
||||
return whitelist.contains(id);
|
||||
}
|
||||
|
||||
public static Boolean hasMiniAppAds(JSONObject list) {
|
||||
var attachments = list.optJSONArray("attachments");
|
||||
|
||||
if (attachments != null && getBoolValue("blockminiapps", false)) {
|
||||
for (int j = 0; j < attachments.length(); j++) {
|
||||
var type = attachments.optJSONObject(j).optString("type");
|
||||
if (type.contains("mini_app")) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package ru.vtosters.lite.hooks;
|
||||
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
import b.h.g.g.BuildInfo;
|
||||
|
||||
public class AppVerHook {
|
||||
public static int appBuild() {
|
||||
return getBoolValue("useOldAppVer", false) ? 6561 : BuildInfo.i.e();
|
||||
}
|
||||
|
||||
public static String appVer() {
|
||||
return getBoolValue("useOldAppVer", false) ? "6.18.1" : BuildInfo.i.d();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package ru.vtosters.lite.hooks;
|
||||
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
public class BusinessNotifHook {
|
||||
public static boolean hook(boolean i){
|
||||
return !getBoolValue("businessDisabler", false) && i;
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class DockBarInjector {
|
||||
}
|
||||
|
||||
} catch (NoSuchFieldException | IllegalAccessException | ClassNotFoundException |
|
||||
NoSuchMethodException | InvocationTargetException e) {
|
||||
NoSuchMethodException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ public class DockBarInjector {
|
||||
item.setStaticMode(true);
|
||||
item.setIconsMode(false);
|
||||
item.setShiftingMode(false);
|
||||
item.setTextColor(getCSTDock());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.vtosters.lite.hooks;
|
||||
|
||||
import static ru.vtosters.lite.utils.Preferences.musicFixNew;
|
||||
import static ru.vtosters.lite.utils.Preferences.isValidSignature;
|
||||
|
||||
import android.os.Build;
|
||||
import android.util.Base64;
|
||||
@@ -27,9 +27,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
|
||||
public class GcmHook {
|
||||
|
||||
private static final String agent = String.format("Android-GCM/1.5 (%s %s)", Build.MODEL, Build.MODEL);
|
||||
|
||||
private static KeyPair pair;
|
||||
|
||||
private static int rid = 0;
|
||||
|
||||
static {
|
||||
@@ -37,14 +41,11 @@ public class GcmHook {
|
||||
}
|
||||
|
||||
public static String requestTokenV2(String orig) {
|
||||
if (musicFixNew()) return "null"; //not public
|
||||
return orig;
|
||||
return isValidSignature() ? "eyJhbGciOiAibm9uZSJ9.eyJub25jZSI6ICJ0ZXN0PT0ifQ." : "e251bGx9";
|
||||
}
|
||||
|
||||
public static String requestToken(String orig) {
|
||||
if (musicFixNew()) return "{null}"; //not public
|
||||
if (orig.equals("")) return requestToken();
|
||||
return orig;
|
||||
return "yssp9o9p9pamz5t-nvmq8spgwtin3e0==";
|
||||
}
|
||||
|
||||
public static String requestToken() {
|
||||
@@ -60,6 +61,7 @@ public class GcmHook {
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
xappide = "";
|
||||
}
|
||||
|
||||
AtomicBoolean wait = new AtomicBoolean(false);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<String> params = new ArrayList<>();
|
||||
@@ -71,17 +73,20 @@ public class GcmHook {
|
||||
while (!wait.get()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
String token = sb.toString();
|
||||
|
||||
if (token.equals("REGISTRATION_ERROR")) {
|
||||
return requestToken();
|
||||
}
|
||||
|
||||
rid = 0;
|
||||
String pub22 = genNewKey();
|
||||
String sig2 = getSig(pub22);
|
||||
params.clear();
|
||||
fillParams(params, sig2, pub22, xappide, Long.parseLong(aid.split(" ")[1].split(":")[0]), true);
|
||||
doRequest("https://android.clients.google.com/c2dm/register3", "POST", params, aid, GcmHook::lambda$requestToken$1);
|
||||
return token;
|
||||
return isValidSignature() ? token : null;
|
||||
} catch (FileNotFoundException e2) {
|
||||
return requestToken();
|
||||
} catch (Exception e3) {
|
||||
@@ -100,12 +105,14 @@ public class GcmHook {
|
||||
private static void fillParams(List<String> params, String sig, String pub2, String xappid, long androidId, boolean del) {
|
||||
rid++;
|
||||
params.add("X-subtype=841415684880");
|
||||
|
||||
if (del) {
|
||||
params.add("X-delete=1");
|
||||
params.add("X-X-delete=1");
|
||||
} else {
|
||||
params.add("X-X-subscription=841415684880");
|
||||
}
|
||||
|
||||
params.add("X-X-subtype=841415684880");
|
||||
params.add("X-app_ver=" + "7.26");
|
||||
params.add("X-kid=|ID|" + rid + "|");
|
||||
@@ -115,19 +122,20 @@ public class GcmHook {
|
||||
params.add("X-gmsv=11949480");
|
||||
params.add("X-pub2=" + pub2);
|
||||
params.add("X-X-kid=|ID|" + rid + "|");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("X-appid=");
|
||||
sb.append(xappid);
|
||||
params.add(sb.toString());
|
||||
params.add("X-appid=" + xappid);
|
||||
|
||||
if (del) {
|
||||
params.add("X-scope=GCM");
|
||||
} else {
|
||||
params.add("X-scope=*");
|
||||
}
|
||||
|
||||
params.add("X-subscription=841415684880");
|
||||
|
||||
if (!del) {
|
||||
params.add("X-gmp_app_id=1:841415684880:android:632f429381141121");
|
||||
}
|
||||
|
||||
params.add("X-app_ver_name=" + "7.26");
|
||||
params.add("app=com.vkontakte.android");
|
||||
params.add("sender=841415684880");
|
||||
@@ -139,9 +147,11 @@ public class GcmHook {
|
||||
|
||||
private static String join(String chr, Iterable<String> arr) {
|
||||
String str = "";
|
||||
|
||||
for (String s : arr) {
|
||||
str = str.isEmpty() ? s : str + chr + s;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -168,8 +178,12 @@ public class GcmHook {
|
||||
}
|
||||
|
||||
private static String getRandomAid() {
|
||||
var arr1 = new String[]{"3974055026275073921", "4418584909973341826", "4585634953328772978"};
|
||||
var arr2 = new String[]{"1932960345884890854", "6594645578425092292", "1792344590975444730"};
|
||||
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];
|
||||
}
|
||||
@@ -182,6 +196,7 @@ public class GcmHook {
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return Base64.encodeToString(pair.getPublic().getEncoded(), 0);
|
||||
}
|
||||
|
||||
@@ -190,7 +205,9 @@ public class GcmHook {
|
||||
PrivateKey key = pair.getPrivate();
|
||||
Signature sign = Signature.getInstance(key instanceof RSAPrivateKey ? "SHA256withRSA" : "SHA256withECDSA");
|
||||
sign.initSign(key);
|
||||
sign.update(join("\n", new String[]{"com.vkontakte.android", pub2}).getBytes(StandardCharsets.UTF_8));
|
||||
sign.update(join("\n", new String[]{
|
||||
"com.vkontakte.android", pub2
|
||||
}).getBytes(StandardCharsets.UTF_8));
|
||||
return Base64.encodeToString(sign.sign(), 0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -201,4 +218,4 @@ public class GcmHook {
|
||||
public interface Callback {
|
||||
void doCallback(String str);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,13 @@
|
||||
package ru.vtosters.lite.hooks;
|
||||
|
||||
import static ru.vtosters.lite.foaf.FoafBase.getBypassedOnlineInfo;
|
||||
import static ru.vtosters.lite.hooks.DateHook.getLocale;
|
||||
import static ru.vtosters.lite.hooks.OnlineFormatterHook.onlineHookProfiles;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getCatalogHeader;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getCatalogPlaylist;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getCatalogSeparator;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getPlaylist;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getStatic;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
|
||||
import static ru.vtosters.lite.utils.Preferences.dev;
|
||||
import static ru.vtosters.lite.utils.Preferences.friendsblock;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.hasVerification;
|
||||
import static ru.vtosters.lite.utils.Preferences.podcastcatalog;
|
||||
import static ru.vtosters.lite.utils.VTVerifications.isDeveloper;
|
||||
import static ru.vtosters.lite.utils.VTVerifications.isPrometheus;
|
||||
import static ru.vtosters.lite.utils.VTVerifications.isVerified;
|
||||
@@ -22,8 +15,6 @@ import static ru.vtosters.lite.utils.VTVerifications.isVerified;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.core.network.Network;
|
||||
import com.vk.core.util.DeviceIdProvider;
|
||||
import com.vk.core.util.LangUtils;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
@@ -37,122 +28,131 @@ import java.util.LinkedHashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class JsonInjectors {
|
||||
private static final OkHttpClient mClient = new OkHttpClient();
|
||||
public static JSONObject profileButton(JSONObject orig) {
|
||||
try {
|
||||
int id = orig.getInt("id");
|
||||
|
||||
public static JSONObject profileButton(JSONObject orig) throws JSONException {
|
||||
var id = orig.getInt("id");
|
||||
var newItem = new JSONArray();
|
||||
|
||||
var newItem = new JSONArray();
|
||||
if (orig.has("buttons")) {
|
||||
newItem = orig.getJSONArray("buttons");
|
||||
}
|
||||
|
||||
if (orig.has("buttons")) {
|
||||
newItem = orig.getJSONArray("buttons");
|
||||
if (!haveDonateButton() && id == AccountManagerUtils.getUserId()) {
|
||||
newItem.put(donateRecomm());
|
||||
}
|
||||
|
||||
if (!orig.has("type") && AccountManagerUtils.isVKTester()) {
|
||||
newItem.put(vktesters(id));
|
||||
}
|
||||
|
||||
orig.put("buttons", newItem);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!haveDonateButton() && id == AccountManagerUtils.getUserId()) {
|
||||
newItem.put(donateRecomm());
|
||||
}
|
||||
|
||||
if (!orig.has("type") && AccountManagerUtils.isVKTester()) {
|
||||
newItem.put(vktesters(id));
|
||||
}
|
||||
|
||||
orig.put("buttons", newItem);
|
||||
|
||||
return orig;
|
||||
}
|
||||
|
||||
public static JSONObject donateRecomm() throws JSONException {
|
||||
var title = AndroidUtils.getString(R.string.donate_to_vtl);
|
||||
var link = "https://vk.com/vtosters_official";
|
||||
var text_color = "2D81E0";
|
||||
public static JSONObject donateRecomm() {
|
||||
try {
|
||||
var title = AndroidUtils.getString(R.string.donate_to_vtl);
|
||||
var link = "https://vk.com/vtosters_official";
|
||||
var text_color = "2D81E0";
|
||||
|
||||
var json = new JSONObject();
|
||||
var icons = new JSONArray();
|
||||
var json = new JSONObject();
|
||||
var icons = new JSONArray();
|
||||
|
||||
var action = new JSONObject();
|
||||
action.put("target", "internal");
|
||||
action.put("type", "open_url"); // may be open_url, open_internal_vkui, open_game, help_hint, show_full_post, open_vkapp, show_recommendations_for_post and groups_advertisement
|
||||
action.put("url", link);
|
||||
json.put("action", action);
|
||||
var action = new JSONObject().put("target", "internal");
|
||||
action.put("type", "open_url"); // may be open_url, open_internal_vkui, open_game, help_hint, show_full_post, open_vkapp, show_recommendations_for_post and groups_advertisement
|
||||
action.put("url", link);
|
||||
json.put("action", action);
|
||||
|
||||
json.put("title", title);
|
||||
json.put("title", title);
|
||||
|
||||
var icon1 = new JSONObject();
|
||||
icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
|
||||
icon1.put("width", "20");
|
||||
icon1.put("height", "20");
|
||||
icons.put(icon1);
|
||||
var icon1 = new JSONObject();
|
||||
icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
|
||||
icon1.put("width", "20");
|
||||
icon1.put("height", "20");
|
||||
icons.put(icon1);
|
||||
|
||||
var icon2 = new JSONObject();
|
||||
icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
|
||||
icon2.put("width", "40");
|
||||
icon2.put("height", "40");
|
||||
icons.put(icon2);
|
||||
var icon2 = new JSONObject();
|
||||
icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
|
||||
icon2.put("width", "40");
|
||||
icon2.put("height", "40");
|
||||
icons.put(icon2);
|
||||
|
||||
var icon3 = new JSONObject();
|
||||
icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png");
|
||||
icon3.put("width", "80");
|
||||
icon3.put("height", "80");
|
||||
icons.put(icon3);
|
||||
var icon3 = new JSONObject();
|
||||
icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png");
|
||||
icon3.put("width", "80");
|
||||
icon3.put("height", "80");
|
||||
icons.put(icon3);
|
||||
|
||||
json.put("icons", icons);
|
||||
json.put("icons", icons);
|
||||
|
||||
json.put("text_color", text_color);
|
||||
json.put("text_color", text_color);
|
||||
|
||||
return json;
|
||||
return json;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject vktesters(int id) throws JSONException {
|
||||
var title = AndroidUtils.getString(R.string.tester_profile);
|
||||
var text_color = "2D81E0";
|
||||
var link = "https://" + getStatic() + "/bugs?lang=" + LangUtils.a() + "#/reporter" + id;
|
||||
public static JSONObject vktesters(int id) {
|
||||
try {
|
||||
var title = AndroidUtils.getString(R.string.tester_profile);
|
||||
var text_color = "2D81E0";
|
||||
var link = "https://" + getStatic() + "/bugs?lang=" + LangUtils.a() + "#/reporter" + id;
|
||||
|
||||
var json = new JSONObject();
|
||||
var icons = new JSONArray();
|
||||
var json = new JSONObject();
|
||||
var icons = new JSONArray();
|
||||
|
||||
var action = new JSONObject();
|
||||
action.put("target", "internal");
|
||||
action.put("type", "open_internal_vkui");
|
||||
action.put("url", link);
|
||||
json.put("action", action);
|
||||
var action = new JSONObject();
|
||||
action.put("target", "internal");
|
||||
action.put("type", "open_internal_vkui");
|
||||
action.put("url", link);
|
||||
json.put("action", action);
|
||||
|
||||
json.put("title", title);
|
||||
json.put("title", title);
|
||||
|
||||
var icon1 = new JSONObject();
|
||||
icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
|
||||
icon1.put("width", "20");
|
||||
icon1.put("height", "20");
|
||||
icons.put(icon1);
|
||||
var icon1 = new JSONObject();
|
||||
icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
|
||||
icon1.put("width", "20");
|
||||
icon1.put("height", "20");
|
||||
icons.put(icon1);
|
||||
|
||||
var icon2 = new JSONObject();
|
||||
icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
|
||||
icon2.put("width", "40");
|
||||
icon2.put("height", "40");
|
||||
icons.put(icon2);
|
||||
var icon2 = new JSONObject();
|
||||
icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
|
||||
icon2.put("width", "40");
|
||||
icon2.put("height", "40");
|
||||
icons.put(icon2);
|
||||
|
||||
var icon3 = new JSONObject();
|
||||
icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png");
|
||||
icon3.put("width", "80");
|
||||
icon3.put("height", "80");
|
||||
icons.put(icon3);
|
||||
var icon3 = new JSONObject();
|
||||
icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png");
|
||||
icon3.put("width", "80");
|
||||
icon3.put("height", "80");
|
||||
icons.put(icon3);
|
||||
|
||||
json.put("icons", icons);
|
||||
json.put("icons", icons);
|
||||
|
||||
json.put("text_color", text_color);
|
||||
json.put("text_color", text_color);
|
||||
return json;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return json;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject convBar(JSONObject orig) throws JSONException {
|
||||
public static JSONObject convBar(JSONObject orig) {
|
||||
var peerid = Objects.requireNonNull(orig.optJSONObject("peer")).optInt("id");
|
||||
|
||||
var pic = "https://image.pngaaa.com/641/326641-middle.png"; // can be null
|
||||
@@ -165,7 +165,8 @@ public class JsonInjectors {
|
||||
|
||||
var isPicture = pic.endsWith(".png") || pic.endsWith(".jpg") || pic.endsWith(".jpeg") || pic.endsWith(".webp");
|
||||
|
||||
if (isVerified(peerid)) text = AndroidUtils.getString(R.string.i_bought) + " VTosters Premium";
|
||||
if (isVerified(peerid))
|
||||
text = AndroidUtils.getString(R.string.i_bought) + " VTosters Premium";
|
||||
if (isPrometheus(peerid))
|
||||
text = AndroidUtils.getString(R.string.i_bought) + " VTosters Premium Gold Prime Pro Plus";
|
||||
if (isDeveloper(peerid)) text = AndroidUtils.getString(R.string.i_created_poop);
|
||||
@@ -180,25 +181,30 @@ public class JsonInjectors {
|
||||
|
||||
if (!dev()) return orig.optJSONObject("conversation_bar"); // for devs only
|
||||
|
||||
var json = new JSONObject();
|
||||
try {
|
||||
var json = new JSONObject();
|
||||
|
||||
var buttonsJson = new JSONObject();
|
||||
buttonsJson.put("layout", "tertiary");
|
||||
buttonsJson.put("text", linktitle);
|
||||
buttonsJson.put("type", "link");
|
||||
buttonsJson.put("link", link);
|
||||
var buttonsJson = new JSONObject();
|
||||
buttonsJson.put("layout", "tertiary");
|
||||
buttonsJson.put("text", linktitle);
|
||||
buttonsJson.put("type", "link");
|
||||
buttonsJson.put("link", link);
|
||||
|
||||
var buttonsjson = new JSONArray(); // max 3 buttons in array
|
||||
if (hasButton) buttonsjson.put(buttonsJson);
|
||||
var buttonsjson = new JSONArray(); // max 3 buttons in array
|
||||
if (hasButton) buttonsjson.put(buttonsJson);
|
||||
|
||||
json.put("name", "group_admin_welcome");
|
||||
json.put("text", text);
|
||||
json.put("buttons", buttonsjson);
|
||||
if (hasIcon && isPicture) {
|
||||
json.put("icon", pic);
|
||||
json.put("name", "group_admin_welcome");
|
||||
json.put("text", text);
|
||||
json.put("buttons", buttonsjson);
|
||||
if (hasIcon && isPicture) {
|
||||
json.put("icon", pic);
|
||||
}
|
||||
return json;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return json;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject menu(JSONObject orig) throws JSONException {
|
||||
@@ -242,19 +248,6 @@ public class JsonInjectors {
|
||||
return json.putOpt("items", newItems);
|
||||
}
|
||||
|
||||
public static JSONObject musiclink(JSONObject json) {
|
||||
var links = json.optJSONArray("links");
|
||||
|
||||
if (links != null) {
|
||||
if (links.optJSONObject(0).optString("url").contains("?section=recent")) {
|
||||
json.remove("links");
|
||||
|
||||
if (dev()) Log.d("VKMusic", "Removed links buttons");
|
||||
}
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSONObject setOnlineInfo(JSONObject json) throws JSONException {
|
||||
var id = json.optInt("id");
|
||||
@@ -368,159 +361,6 @@ public class JsonInjectors {
|
||||
return items;
|
||||
}
|
||||
|
||||
public static JSONObject music(JSONObject json) throws JSONException {
|
||||
var catalog = json.optJSONObject("catalog");
|
||||
|
||||
JSONArray oldItems = null;
|
||||
|
||||
if (catalog != null) {
|
||||
oldItems = catalog.optJSONArray("sections");
|
||||
}
|
||||
|
||||
if (oldItems != null && oldItems.optJSONObject(0).optString("url").contains("general")) {
|
||||
json.optJSONArray("playlists").put(getPlaylist());
|
||||
|
||||
if (podcastcatalog()) {
|
||||
var podcasts = fetchCatalogPodcast();
|
||||
if (podcasts != null) {
|
||||
var catalogarr = podcasts.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0);
|
||||
|
||||
var title = catalogarr.optString("title");
|
||||
var id = catalogarr.optString("id");
|
||||
var url = catalogarr.optString("url");
|
||||
|
||||
if (dev()) Log.d("VKMusic", "Added " + title + " in music sections");
|
||||
|
||||
oldItems.put(new JSONObject().put("id", id).put("title", title).put("url", url));
|
||||
}
|
||||
}
|
||||
|
||||
var playlists = fetchCatalogId("https://vk.com/audio?section=my_playlists");
|
||||
if (playlists != null) {
|
||||
var catalogarr = playlists.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0);
|
||||
|
||||
var title = catalogarr.optString("title");
|
||||
var id = catalogarr.optString("id");
|
||||
var url = catalogarr.optString("url");
|
||||
|
||||
if (dev()) Log.d("VKMusic", "Added " + title + " in music sections");
|
||||
|
||||
oldItems.put(new JSONObject().put("id", id).put("title", title).put("url", url));
|
||||
}
|
||||
|
||||
var albums = fetchCatalogId("https://vk.com/audio?section=albums");
|
||||
if (albums != null) {
|
||||
var catalogarr = albums.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0);
|
||||
|
||||
var title = catalogarr.optString("title");
|
||||
var id = catalogarr.optString("id");
|
||||
var url = catalogarr.optString("url");
|
||||
|
||||
if (dev()) Log.d("VKMusic", "Added " + title + " in music sections");
|
||||
|
||||
oldItems.put(new JSONObject().put("id", id).put("title", title).put("url", url));
|
||||
}
|
||||
|
||||
var recent = fetchCatalogId("https://vk.com/audio?section=recent");
|
||||
if (recent != null) {
|
||||
var catalogarr = recent.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0);
|
||||
|
||||
var title = catalogarr.optString("title");
|
||||
var id = catalogarr.optString("id");
|
||||
var url = catalogarr.optString("url");
|
||||
|
||||
if (dev()) Log.d("VKMusic", "Added " + title + " in music sections");
|
||||
|
||||
oldItems.put(new JSONObject().put("id", id).put("title", title).put("url", url));
|
||||
}
|
||||
|
||||
for (int i = 0; i < oldItems.length(); i++) {
|
||||
var item = oldItems.optJSONObject(i);
|
||||
var title = item.optString("title");
|
||||
var id = item.optString("id");
|
||||
var url = item.optString("url");
|
||||
var value = AndroidUtils.getPrefsValue("musicdefcatalog");
|
||||
|
||||
Log.d("VKMusic", "title: " + title + " id: " + id + " url: " + url + " value: " + value);
|
||||
|
||||
if (url.contains(value) && !value.isEmpty()) {
|
||||
catalog.put("default_section", id);
|
||||
if (dev()) Log.d("VKMusic", "Added " + title + " as default music section");
|
||||
}
|
||||
}
|
||||
|
||||
if (CacheDatabaseDelegate.hasTracks() && !LibVKXClient.isIntegrationEnabled()){ // inj in playlist list
|
||||
var blocks = oldItems.optJSONObject(0).optJSONArray("blocks");
|
||||
var newBlocks = new JSONArray();
|
||||
|
||||
if (blocks != null){
|
||||
newBlocks
|
||||
.put(getCatalogHeader())
|
||||
.put(getCatalogPlaylist())
|
||||
.put(getCatalogSeparator());
|
||||
|
||||
Log.d("VKMusic", "added cache catalog playlist");
|
||||
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
newBlocks.put(blocks.optJSONObject(i));
|
||||
}
|
||||
|
||||
oldItems.optJSONObject(0).put("blocks", newBlocks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSONObject fetchCatalogId(String section) {
|
||||
if (section.isEmpty()) return null;
|
||||
|
||||
var request = new Request.a()
|
||||
.b("https://" + getApi() + "/method/catalog.getAudio"
|
||||
+ "?v=5.119"
|
||||
+ "&https=1"
|
||||
+ "&need_blocks=1"
|
||||
+ "&lang="
|
||||
+ getLocale()
|
||||
+ "&device_id="
|
||||
+ DeviceIdProvider.d(AndroidUtils.getGlobalContext())
|
||||
+ "&url="
|
||||
+ section
|
||||
+ "&access_token="
|
||||
+ AccountManagerUtils.getUserToken())
|
||||
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8")).a();
|
||||
try {
|
||||
return new JSONObject(mClient.a(request).execute().a().g()).getJSONObject("response");
|
||||
} catch (JSONException | IOException e) {
|
||||
Log.d("VTLMusic", "Error: " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject fetchCatalogPodcast() {
|
||||
var request = new Request.a()
|
||||
.b("https://" + getApi() + "/method/catalog.getPodcasts"
|
||||
+ "?v=5.119"
|
||||
+ "&https=1"
|
||||
+ "&need_blocks=1"
|
||||
+ "&lang="
|
||||
+ getLocale()
|
||||
+ "&device_id="
|
||||
+ DeviceIdProvider.d(AndroidUtils.getGlobalContext())
|
||||
+ "&access_token="
|
||||
+ AccountManagerUtils.getUserToken())
|
||||
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8")).a();
|
||||
try {
|
||||
return new JSONObject(mClient.a(request).execute().a().g()).getJSONObject("response");
|
||||
} catch (JSONException | IOException e) {
|
||||
Log.d("VTLMusic", "Error: " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject friends(JSONObject json) throws JSONException, ParseException, IOException {
|
||||
JSONObject catalog = onlineHookProfiles(json);
|
||||
boolean sectionexecute = true;
|
||||
|
||||
@@ -4,15 +4,12 @@ import static ru.vtosters.lite.ui.dialogs.ServerDialog.sendRequest;
|
||||
import static ru.vtosters.lite.utils.CacheUtils.getInstance;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.setupFilters;
|
||||
import static ru.vtosters.lite.utils.Preferences.checkupdates;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.isDarkTheme;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.setNeededTheme;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.vk.core.concurrent.VkExecutors;
|
||||
|
||||
import ru.vtosters.lite.concurrent.VTExecutors;
|
||||
import ru.vtosters.lite.downloaders.notifications.NotificationChannels;
|
||||
import ru.vtosters.lite.ui.dialogs.DisableBattery;
|
||||
import ru.vtosters.lite.ui.dialogs.InstallGMS;
|
||||
@@ -25,17 +22,12 @@ public class MainActivityInjector {
|
||||
setNeededTheme(activity);
|
||||
sendRequest();
|
||||
if (checkupdates()) OTADialog.checkUpdates(activity);
|
||||
VkExecutors.x.f().a(DeletedMessagesHandler::reloadMessagesList); // ioScheduler
|
||||
VTExecutors.getIoScheduler().a(DeletedMessagesHandler::reloadMessagesList); // ioScheduler
|
||||
Start.alert(activity);
|
||||
InstallGMS.alert(activity);
|
||||
DisableBattery.alert(activity);
|
||||
PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
.edit()
|
||||
.putBoolean("isdark", isDarkTheme())
|
||||
.commit();
|
||||
|
||||
|
||||
VkExecutors.x.q().a(() -> {
|
||||
VTExecutors.getSlowTasksScheduler().a(() -> {
|
||||
getInstance().autoCleaningCache();
|
||||
}); // slowTasksScheduler
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.ads;
|
||||
import static ru.vtosters.lite.utils.Preferences.adsslider;
|
||||
import static ru.vtosters.lite.utils.Preferences.authorsrecomm;
|
||||
import static ru.vtosters.lite.utils.Preferences.friendsrecomm;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
@@ -115,14 +114,16 @@ public class NewsfeedHook {
|
||||
}
|
||||
|
||||
public static void adsParams(HashSet<String> hashSet) {
|
||||
if (ads())
|
||||
if (ads()) {
|
||||
hashSet.add("ads_disabled");
|
||||
} else {
|
||||
hashSet.add("ads_app_slider");
|
||||
hashSet.add("ads_site_slider");
|
||||
}
|
||||
|
||||
hashSet.add("ads_app");
|
||||
hashSet.add("ads_site");
|
||||
hashSet.add("ads_post");
|
||||
if (!adsslider())
|
||||
hashSet.add("ads_app_slider");
|
||||
hashSet.add("ads_site_slider");
|
||||
hashSet.add("ads_app_video");
|
||||
hashSet.add("ads_post_pretty_cards");
|
||||
hashSet.add("ads_post_snippet_video");
|
||||
|
||||
@@ -18,6 +18,8 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.vk.core.dialogs.actionspopup.ActionsPopup;
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
import com.vk.core.ui.themes.VKThemeHelper;
|
||||
import com.vk.core.util.ContextExtKt;
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vk.dto.common.AttachmentWithMedia;
|
||||
import com.vk.dto.common.ImageSize;
|
||||
@@ -37,11 +39,12 @@ import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class PhotoViewer {
|
||||
static OkHttpClient client = new OkHttpClient();
|
||||
static OkHttpClient client = VtOkHttpClient.getInstance();
|
||||
|
||||
public static boolean interceptClick(AttachmentWithMedia attachment, MenuItem item, View view) {
|
||||
if (item.getItemId() == R.id.search_photo) {
|
||||
@@ -96,9 +99,7 @@ public class PhotoViewer {
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public static void addMenuItems(AttachmentWithMedia attachment, ActionsPopup.b actionPopup, int i, boolean z) {
|
||||
actionPopup.a(R.string.search_photo_content,
|
||||
ThemesUtils.isDarkTheme()
|
||||
? AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_menu_search_outline_28)
|
||||
: new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_menu_search_outline_28), ThemesUtils.getAccentColor()),
|
||||
ContextExtKt.b(AndroidUtils.getGlobalContext(), R.drawable.ic_menu_search_outline_28, VKThemeHelper.g(R.attr.header_tint)),
|
||||
false,
|
||||
() -> {
|
||||
if (attachment instanceof PhotoAttachment) {
|
||||
@@ -118,9 +119,7 @@ public class PhotoViewer {
|
||||
}
|
||||
);
|
||||
actionPopup.a(R.string.copy_photo_url_content,
|
||||
!ThemesUtils.isDarkTheme()
|
||||
? new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_copy_outline_28), ThemesUtils.getAccentColor())
|
||||
: new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_copy_outline_28), Color.WHITE),
|
||||
ContextExtKt.b(AndroidUtils.getGlobalContext(), R.drawable.ic_copy_outline_28, VKThemeHelper.g(R.attr.header_tint)),
|
||||
false,
|
||||
() -> {
|
||||
if (attachment instanceof PhotoAttachment) {
|
||||
@@ -140,10 +139,7 @@ public class PhotoViewer {
|
||||
}
|
||||
);
|
||||
actionPopup.a(R.string.open_original_photo_content,
|
||||
ThemesUtils.isDarkTheme()
|
||||
? AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_link_outline_28)
|
||||
: new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_link_outline_28),
|
||||
ThemesUtils.getAccentColor()),
|
||||
ContextExtKt.b(AndroidUtils.getGlobalContext(), R.drawable.ic_link_outline_28, VKThemeHelper.g(R.attr.header_tint)),
|
||||
false,
|
||||
() -> {
|
||||
if (attachment instanceof PhotoAttachment) {
|
||||
@@ -233,8 +229,7 @@ public class PhotoViewer {
|
||||
}
|
||||
|
||||
private static void searchWithGoogle(String url) {
|
||||
openUrl("https://www.google.ru/searchbyimage?image_url=" +
|
||||
URLEncoder.encode(url));
|
||||
openUrl("https://www.google.com/searchbyimage?image_url=" + URLEncoder.encode(url) + "&client=app");
|
||||
}
|
||||
|
||||
private static void searchWithBing(String url) {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package ru.vtosters.lite.hooks;
|
||||
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
public class PromoStickersHook {
|
||||
public static String hook() {
|
||||
return getBoolValue("promotedstickers", true) ? "purchased,active" : "purchased,active,promoted";
|
||||
}
|
||||
}
|
||||
@@ -70,11 +70,11 @@ public class ProxyHook {
|
||||
rgRandomProxy.setChecked(isRandomProxyEnabled());
|
||||
rgVika.setChecked(isVikaProxyEnabled());
|
||||
|
||||
new VkAlertDialog.Builder(ctx)
|
||||
.setTitle(ctx.getString(R.string.vtlproxy))
|
||||
.setMessage(ctx.getString(R.string.proxy_warning))
|
||||
.setView(rg)
|
||||
.setPositiveButton(ctx.getString(R.string.vtl_confirm), ((dialog, which) -> { // Применить
|
||||
new VkAlertDialog.Builder(ctx)
|
||||
.setTitle(ctx.getString(R.string.vtlproxy))
|
||||
.setMessage(ctx.getString(R.string.proxy_warning))
|
||||
.setView(rg)
|
||||
.setPositiveButton(ctx.getString(R.string.vtl_confirm), ((dialog, which) -> { // Применить
|
||||
if (rgZaborona.isChecked()) {
|
||||
edit().putString("proxy", "zaborona").commit();
|
||||
restartApplication();
|
||||
@@ -88,13 +88,13 @@ public class ProxyHook {
|
||||
edit().putString("proxy", "noproxy").commit();
|
||||
restartApplication();
|
||||
}
|
||||
}))
|
||||
.setNeutralButton(ctx.getString(R.string.proxy_settings), ((dialog, which) -> {
|
||||
}))
|
||||
.setNeutralButton(ctx.getString(R.string.proxy_settings), ((dialog, which) -> {
|
||||
var intent = new Navigator(ProxySettingsFragment.class)
|
||||
.b(ctx)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
ctx.startActivity(intent);
|
||||
}))
|
||||
.show();
|
||||
}))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ public class TogglesHook {
|
||||
case FEATURE_NEWS_GAMES_IN_DISCOVER:
|
||||
case FEATURE_NEWS_HEADER_SCROLL:
|
||||
case FEATURE_NEW_FORMAT_SHOW_WPB:
|
||||
case FEATURE_NOTIFICATION_ANIM:
|
||||
case FEATURE_PODCASTS_PAGE:
|
||||
case FEATURE_QR_CREATE_QR:
|
||||
case FEATURE_QR_DYNAMIC_FRAME:
|
||||
@@ -110,8 +109,6 @@ public class TogglesHook {
|
||||
case FEATURE_VK_APPS_SEARCH:
|
||||
case FEATURE_VOTES_BALANCE:
|
||||
case FEATURE_WEBVIEW_TOKEN_ACTIVE:
|
||||
case FEATURE_WISHLIST_ENTRY_POINT:
|
||||
case FEATURE_WISHLIST_MY_PROFILE:
|
||||
case FEATURE_MILKSHAKE_FORCE_DISABLED:
|
||||
case FEATURE_MILKSHAKE_ACTIVATION_DISABLED:
|
||||
case EXPERIMENT_NEWS_DISABLE_CACHE:
|
||||
|
||||
@@ -18,6 +18,8 @@ import android.webkit.WebView;
|
||||
import com.vk.articles.preload.WebCachePreloader;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.data.ThemeTracker;
|
||||
import ru.vtosters.lite.themes.ThemesCore;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@@ -77,22 +79,19 @@ public class VKUIHook {
|
||||
}
|
||||
|
||||
public static void inject(WebView webView) {
|
||||
String string = getPrefsValue("darktheme");
|
||||
|
||||
if (getBoolValue("VKUI_INJ", true)) {
|
||||
|
||||
if (!isLoaded) {
|
||||
load();
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (true/*Themes.isAccentedCache()*/) {
|
||||
if (ThemesCore.isCachedAccents()) {
|
||||
sb.append("\n\n");
|
||||
sb.append(loadedCSS);
|
||||
}
|
||||
|
||||
if (string.equals("amoled")) {
|
||||
if (ThemesUtils.isAmoledTheme()) {
|
||||
sb.append("\n\n");
|
||||
sb.append(loadedCSSAmoled);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class WritebarHook {
|
||||
public static int getWriteBar() {
|
||||
return wbios() ? R.layout.write_bar_i : R.layout.write_bar;
|
||||
return wbios() ? R.layout.write_bar_i : R.layout.write_bar;
|
||||
}
|
||||
|
||||
public static int getIconsColors(int def) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import okhttp3.FormBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
import ru.vtosters.lite.downloaders.AudioDownloader;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
@@ -35,7 +36,7 @@ public class LastFMScrobbler {
|
||||
private static final String KEY = "5965d63402414776c54c266db0211746";
|
||||
private static final String KEY_SECRET = "d982180eed13275bb948e41cf225f88f";
|
||||
private static final String URL = "https://ws.audioscrobbler.com/2.0/";
|
||||
private static final OkHttpClient CLIENT = new OkHttpClient();
|
||||
private static final OkHttpClient CLIENT = VtOkHttpClient.getInstance();
|
||||
private static final List<String> SCROBBLED_UUIDS = new ArrayList<>();
|
||||
|
||||
public static void grabMusicTrack(MusicTrack musictrack) {
|
||||
@@ -55,7 +56,7 @@ public class LastFMScrobbler {
|
||||
}
|
||||
|
||||
if (Preferences.autocache() && !CacheDatabaseDelegate.isCached(uid)) {
|
||||
if (LibVKXClient.isIntegrationEnabled()){
|
||||
if (LibVKXClient.isIntegrationEnabled()) {
|
||||
LibVKXClient.getInstance().runOnService(service -> {
|
||||
try {
|
||||
service.addTrackToCache(track_id, owner_id, access_key);
|
||||
@@ -100,7 +101,7 @@ public class LastFMScrobbler {
|
||||
fetch(params, new Callback() {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
Log.d("Scrobbler", e+"");
|
||||
Log.d("Scrobbler", e + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -199,7 +200,7 @@ public class LastFMScrobbler {
|
||||
}
|
||||
|
||||
public static boolean needScrobbling(String uid) {
|
||||
return isLoggedIn() && isScrobblingEnabled() && !SCROBBLED_UUIDS.contains(uid);
|
||||
return isLoggedIn() && isScrobblingEnabled() && (SCROBBLED_UUIDS.isEmpty() || !SCROBBLED_UUIDS.get(SCROBBLED_UUIDS.size() - 1).contains(uid));
|
||||
}
|
||||
|
||||
public static boolean isLoggedIn() {
|
||||
|
||||
@@ -10,8 +10,6 @@ import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
@@ -19,6 +17,7 @@ import javax.crypto.NoSuchPaddingException;
|
||||
import java8.util.concurrent.CompletableFuture;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
import ru.vtosters.lite.music.converter.ts.FFMpeg;
|
||||
import ru.vtosters.lite.music.converter.ts.TSMerger;
|
||||
import ru.vtosters.lite.music.downloader.ThumbnailDownloader;
|
||||
@@ -27,8 +26,7 @@ import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
public class M3UDownloader implements ITrackDownloader {
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
private ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
private static final OkHttpClient client = VtOkHttpClient.getInstance();
|
||||
|
||||
public static M3UDownloader getInstance() {
|
||||
return Holder.INSTANCE;
|
||||
@@ -99,6 +97,7 @@ public class M3UDownloader implements ITrackDownloader {
|
||||
}));
|
||||
}
|
||||
var future = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
|
||||
future.join();
|
||||
future.exceptionally(throwable -> {
|
||||
callback.onFailure();
|
||||
return null;
|
||||
|
||||
@@ -45,7 +45,7 @@ public class VKM3UParser {
|
||||
if (mTransportStreams.size() == i)
|
||||
mTransportStreams.add(new TransportStream());
|
||||
} else if (isM3U8(line)) {
|
||||
mTransportStreams.get(i).setName(line);
|
||||
mTransportStreams.get(i).setName(line.substring(line.lastIndexOf("/") + 1));
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -13,6 +13,8 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import io.reactivex.Observable;
|
||||
@@ -23,11 +25,11 @@ import ru.vtosters.lite.music.cache.helpers.PlaylistHelper;
|
||||
import ru.vtosters.lite.music.cache.helpers.TracklistHelper;
|
||||
|
||||
public class PlaylistInjector {
|
||||
|
||||
public final static String CHANNEL_NAME = "VTCH";
|
||||
private static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
public static void injectDownloadPlaylist(Playlist playlist) {
|
||||
AudioDownloader.cachePlaylist(playlist);
|
||||
executor.submit(() -> AudioDownloader.cachePlaylist(playlist));
|
||||
}
|
||||
|
||||
public static boolean eligibleForOfflineCaching() {
|
||||
|
||||
+61
-66
@@ -1,6 +1,11 @@
|
||||
package ru.vtosters.lite.music.cache.injectors;
|
||||
|
||||
import static ru.vtosters.lite.music.cache.CacheDatabaseDelegate.hasTracks;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getCatalogHeader;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getCatalogPlaylist;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getCatalogSeparator;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getPlaylist;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserId;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
@@ -20,9 +25,8 @@ import java.util.UUID;
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import ru.vtosters.lite.music.cache.helpers.PlaylistHelper;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.music.cache.helpers.TracklistHelper;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.NetworkUtils;
|
||||
|
||||
@@ -76,76 +80,67 @@ public class TracklistInjector {
|
||||
public static void injectIntoExistingCatalog(JSONObject catalogNode) {
|
||||
Log.d("TracklistInjector", "injectIntoExistingCatalog");
|
||||
|
||||
if (!hasTracks()) return;
|
||||
try {
|
||||
var sectionsNode = catalogNode.getJSONObject("catalog")
|
||||
.getJSONArray("sections");
|
||||
var catalog = catalogNode.getJSONObject("catalog");
|
||||
var sectionsNode = catalog.getJSONArray("sections");
|
||||
var firstSection = sectionsNode.getJSONObject(0);
|
||||
if (!firstSection.getString("url").equals("https://vk.com/audios" + AccountManagerUtils.getUserId() + "?section=all"))
|
||||
return;
|
||||
|
||||
var foundPlaylistBlock = false;
|
||||
var suitableIndex = 0;
|
||||
if (!firstSection.getString("url").equals("https://vk.com/audios" + getUserId() + "?section=all"))
|
||||
return;
|
||||
|
||||
var blocks = firstSection.getJSONArray("blocks");
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
var block = blocks.getJSONObject(i);
|
||||
var dataType = block.getString("data_type");
|
||||
if ("music_audios".equals(dataType)) {
|
||||
suitableIndex = i - 1;
|
||||
continue;
|
||||
|
||||
if (CacheDatabaseDelegate.hasTracks() && !LibVKXClient.isIntegrationEnabled()) { // inj in playlist list
|
||||
var noPlaylists = blocks.optJSONObject(0).optJSONArray("buttons").optJSONObject(0).optJSONObject("action").optString("type").equals("create_playlist");
|
||||
|
||||
if (noPlaylists) {
|
||||
catalogNode.put("playlists", new JSONArray().put(getPlaylist()));
|
||||
Log.d("catalogInjector", "added new pl");
|
||||
|
||||
var newBlocks = new JSONArray();
|
||||
|
||||
newBlocks
|
||||
.put(getCatalogHeader())
|
||||
.put(getCatalogPlaylist())
|
||||
.put(getCatalogSeparator());
|
||||
|
||||
Log.d("catalogInjector", "added cache catalog playlist");
|
||||
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
newBlocks.put(blocks.optJSONObject(i));
|
||||
}
|
||||
|
||||
firstSection.put("blocks", newBlocks);
|
||||
} else {
|
||||
try {
|
||||
catalogNode.optJSONArray("playlists").put(getPlaylist());
|
||||
Log.d("catalogInjector", "added to exist pl");
|
||||
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
var j = blocks.optJSONObject(i);
|
||||
var type = j.optString("data_type");
|
||||
|
||||
if (type.equals("music_playlists") && j.has("playlists_ids")) {
|
||||
var newarr = new JSONArray();
|
||||
var playlists_ids = j.optJSONArray("playlists_ids");
|
||||
|
||||
newarr.put(getUserId() + "_-1");
|
||||
|
||||
for (int n = 0; n < playlists_ids.length(); n++) {
|
||||
newarr.put(playlists_ids.optString(n));
|
||||
}
|
||||
|
||||
j.put("playlists_ids", newarr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d("catalogInjector", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (!"music_playlists".equals(dataType))
|
||||
continue;
|
||||
|
||||
var playlistIds = block.getJSONArray("playlists_ids");
|
||||
var newPlaylistIds = new JSONArray()
|
||||
.put(AccountManagerUtils.getUserId() + "_-1");
|
||||
|
||||
for (int j = 0; j < playlistIds.length(); j++)
|
||||
newPlaylistIds.put(playlistIds.get(j));
|
||||
|
||||
block.put("playlists_ids", newPlaylistIds);
|
||||
|
||||
// need test
|
||||
blocks.remove(i);
|
||||
blocks.put(i, block);
|
||||
|
||||
foundPlaylistBlock = true;
|
||||
}
|
||||
|
||||
if (foundPlaylistBlock) {
|
||||
var playlists = catalogNode.getJSONArray("playlists")
|
||||
.put(0, PlaylistHelper.createCachedPlaylistMetadata().J());
|
||||
catalogNode.put("playlists", playlists);
|
||||
return;
|
||||
}
|
||||
|
||||
var ids = new JSONArray()
|
||||
.put(0, AccountManagerUtils.getUserId() + "_-1");
|
||||
|
||||
var playlistsBlock = new JSONObject()
|
||||
.put("id", getRandomId())
|
||||
.put("data_type", "music_playlists")
|
||||
.put("url", "synth:cache:playlists")
|
||||
.put("playlists_ids", ids);
|
||||
|
||||
var layout = new JSONObject()
|
||||
.put("name", "large_slider")
|
||||
.put("owner_id", AccountManagerUtils.getUserId());
|
||||
|
||||
playlistsBlock.put("layout", layout);
|
||||
|
||||
blocks.put(suitableIndex, playlistsBlock);
|
||||
|
||||
firstSection.put("blocks", blocks);
|
||||
|
||||
var playlists = new JSONArray()
|
||||
.put(0, PlaylistHelper.createCachedPlaylistMetadata().J());
|
||||
catalogNode.put("playlists", playlists);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
Log.d("TracklistInjector", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +170,7 @@ public class TracklistInjector {
|
||||
|
||||
var layout = new JSONObject()
|
||||
.put("name", "list")
|
||||
.put("owner_id", AccountManagerUtils.getUserId());
|
||||
.put("owner_id", getUserId());
|
||||
|
||||
audiosBlock.put("layout", layout);
|
||||
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
package ru.vtosters.lite.music.catalog.inject;
|
||||
|
||||
import static ru.vtosters.lite.hooks.DateHook.getLocale;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getCatalogHeader;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getCatalogPlaylist;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getCatalogSeparator;
|
||||
import static ru.vtosters.lite.music.cache.helpers.PlaylistHelper.getPlaylist;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserId;
|
||||
import static ru.vtosters.lite.utils.Preferences.dev;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.core.network.Network;
|
||||
import com.vk.core.util.DeviceIdProvider;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class CatalogJsonInjector {
|
||||
private static final OkHttpClient mClient = VtOkHttpClient.getInstance();
|
||||
|
||||
public static JSONObject music(JSONObject json) throws JSONException {
|
||||
var catalog = json.optJSONObject("catalog");
|
||||
|
||||
JSONArray oldItems = null;
|
||||
|
||||
if (catalog != null) {
|
||||
oldItems = catalog.optJSONArray("sections");
|
||||
}
|
||||
|
||||
var useOldAppVer = getBoolValue("useOldAppVer", false);
|
||||
var isUsersCatalog = oldItems.optJSONObject(0).optString("url").equals("https://vk.com/audios" + getUserId() + "?section=" + (useOldAppVer ? "all" : "general"));
|
||||
|
||||
if (oldItems != null && isUsersCatalog) {
|
||||
var blocks = oldItems.optJSONObject(0).optJSONArray("blocks");
|
||||
|
||||
if (!useOldAppVer) {
|
||||
if (blocks != null) {
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
var block = blocks.optJSONObject(i);
|
||||
var layout = block.optJSONObject("layout");
|
||||
if (layout != null) {
|
||||
var name = layout.optString("name");
|
||||
if (name.equals("header_extended")) {
|
||||
if (layout.has("top_title")) blocks.remove(i);
|
||||
try {
|
||||
layout.put("name", "header");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var playlists = fetchCatalogId("https://vk.com/audio?section=my_playlists");
|
||||
if (playlists != null) {
|
||||
var catalogarr = playlists.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0);
|
||||
|
||||
var title = catalogarr.optString("title");
|
||||
var id = catalogarr.optString("id");
|
||||
var url = catalogarr.optString("url");
|
||||
|
||||
if (dev()) Log.d("VKMusic", "Added " + title + " in music sections");
|
||||
|
||||
oldItems.put(new JSONObject().put("id", id).put("title", title).put("url", url));
|
||||
}
|
||||
|
||||
var albums = fetchCatalogId("https://vk.com/audio?section=albums");
|
||||
if (albums != null) {
|
||||
var catalogarr = albums.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0);
|
||||
|
||||
var title = catalogarr.optString("title");
|
||||
var id = catalogarr.optString("id");
|
||||
var url = catalogarr.optString("url");
|
||||
|
||||
if (dev()) Log.d("VKMusic", "Added " + title + " in music sections");
|
||||
|
||||
oldItems.put(new JSONObject().put("id", id).put("title", title).put("url", url));
|
||||
}
|
||||
|
||||
var recent = fetchCatalogId("https://vk.com/audio?section=recent");
|
||||
if (recent != null) {
|
||||
var catalogarr = recent.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0);
|
||||
|
||||
var title = catalogarr.optString("title");
|
||||
var id = catalogarr.optString("id");
|
||||
var url = catalogarr.optString("url");
|
||||
|
||||
if (dev()) Log.d("VKMusic", "Added " + title + " in music sections");
|
||||
|
||||
oldItems.put(new JSONObject().put("id", id).put("title", title).put("url", url));
|
||||
}
|
||||
|
||||
for (int i = 0; i < oldItems.length(); i++) {
|
||||
var item = oldItems.optJSONObject(i);
|
||||
var title = item.optString("title");
|
||||
var id = item.optString("id");
|
||||
var url = item.optString("url");
|
||||
var value = AndroidUtils.getPrefsValue("musicdefcatalog");
|
||||
|
||||
Log.d("VKMusic", "title: " + title + " id: " + id + " url: " + url + " value: " + value);
|
||||
|
||||
if (url.contains(value) && !value.isEmpty()) {
|
||||
catalog.put("default_section", id);
|
||||
if (dev()) Log.d("VKMusic", "Added " + title + " as default music section");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (CacheDatabaseDelegate.hasTracks() && !LibVKXClient.isIntegrationEnabled()) { // inj in playlist list
|
||||
var noPlaylists = !json.has("playlists");
|
||||
|
||||
if (noPlaylists) {
|
||||
json.put("playlists", new JSONArray().put(getPlaylist()));
|
||||
Log.d("catalogInjector", "added new pl");
|
||||
} else {
|
||||
try {
|
||||
json.optJSONArray("playlists").put(getPlaylist());
|
||||
Log.d("catalogInjector", "added to exist pl");
|
||||
} catch (Exception e) {
|
||||
Log.d("catalogInjector", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (blocks != null && (!useOldAppVer || noPlaylists)) {
|
||||
var newBlocks = new JSONArray();
|
||||
|
||||
newBlocks
|
||||
.put(getCatalogHeader())
|
||||
.put(getCatalogPlaylist())
|
||||
.put(getCatalogSeparator());
|
||||
|
||||
Log.d("VKMusic", "added cache catalog playlist");
|
||||
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
newBlocks.put(blocks.optJSONObject(i));
|
||||
}
|
||||
|
||||
oldItems.optJSONObject(0).put("blocks", newBlocks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSONObject catalogInjector(JSONObject json) {
|
||||
try {
|
||||
var section = json.optJSONObject("section");
|
||||
var useOldAppVer = getBoolValue("useOldAppVer", false);
|
||||
var isUsersCatalog = section.optString("url").equals("https://vk.com/audios" + getUserId() + "?section=" + (useOldAppVer ? "all" : "general"));
|
||||
|
||||
if (isUsersCatalog && CacheDatabaseDelegate.hasTracks() && !LibVKXClient.isIntegrationEnabled()) {
|
||||
var blocks = section.getJSONArray("blocks");
|
||||
var noPlaylists = !json.has("playlists");
|
||||
|
||||
// Log.d("catalogInjector", "type: " + blocks.optJSONObject(0).optJSONArray("buttons").optJSONObject(0).optJSONObject("action").optString("type"));
|
||||
|
||||
if (noPlaylists) {
|
||||
json.put("playlists", new JSONArray().put(getPlaylist()));
|
||||
Log.d("catalogInjector", "added new pl");
|
||||
} else {
|
||||
try {
|
||||
json.optJSONArray("playlists").put(getPlaylist());
|
||||
Log.d("catalogInjector", "added to exist pl");
|
||||
} catch (Exception e) {
|
||||
Log.d("catalogInjector", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (!useOldAppVer || noPlaylists) {
|
||||
var newBlocks = new JSONArray();
|
||||
|
||||
newBlocks
|
||||
.put(getCatalogHeader())
|
||||
.put(getCatalogPlaylist())
|
||||
.put(getCatalogSeparator());
|
||||
|
||||
Log.d("catalogInjector", "added cache catalog playlist");
|
||||
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
newBlocks.put(blocks.optJSONObject(i));
|
||||
}
|
||||
|
||||
section.put("blocks", newBlocks);
|
||||
} else {
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
var j = blocks.optJSONObject(i);
|
||||
var type = j.optString("data_type");
|
||||
|
||||
if (type.equals("music_playlists") && j.has("playlists_ids")) {
|
||||
var newarr = new JSONArray();
|
||||
var playlists_ids = j.optJSONArray("playlists_ids");
|
||||
|
||||
newarr.put(getUserId() + "_-1");
|
||||
|
||||
for (int n = 0; n < playlists_ids.length(); n++) {
|
||||
newarr.put(playlists_ids.optString(n));
|
||||
}
|
||||
|
||||
Log.d("catalogInjector", "added to pl ids");
|
||||
|
||||
j.put("playlists_ids", newarr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.d("catalogInjector", e.toString());
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSONObject musiclink(JSONObject json) {
|
||||
var links = json.optJSONArray("links");
|
||||
|
||||
if (links != null && !getBoolValue("useOldAppVer", false)) {
|
||||
if (links.optJSONObject(0).optString("url").contains("?section=recent")) {
|
||||
json.remove("links");
|
||||
|
||||
if (dev()) Log.d("VKMusic", "Removed links buttons");
|
||||
}
|
||||
}
|
||||
|
||||
var section = json.optJSONObject("section");
|
||||
if (section != null) {
|
||||
var blocks = section.optJSONArray("blocks");
|
||||
if (blocks != null) {
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
var block = blocks.optJSONObject(i);
|
||||
var layout = block.optJSONObject("layout");
|
||||
if (layout != null) {
|
||||
var name = layout.optString("name");
|
||||
if (name.equals("header_extended")) {
|
||||
if (layout.has("top_title")) blocks.remove(i);
|
||||
try {
|
||||
layout.put("name", "header");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return catalogInjector(json);
|
||||
}
|
||||
|
||||
private static JSONObject fetchCatalogId(String section) {
|
||||
if (section.isEmpty()) return null;
|
||||
|
||||
var request = new Request.a()
|
||||
.b("https://" + getApi() + "/method/" + "catalog.getAudio"
|
||||
+ "?v=5.119"
|
||||
+ "&https=1"
|
||||
+ "&need_blocks=1"
|
||||
+ "&lang="
|
||||
+ getLocale()
|
||||
+ "&device_id="
|
||||
+ DeviceIdProvider.d(AndroidUtils.getGlobalContext())
|
||||
+ "&url="
|
||||
+ section
|
||||
+ "&access_token="
|
||||
+ AccountManagerUtils.getUserToken())
|
||||
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8")).a();
|
||||
try {
|
||||
return new JSONObject(mClient.a(request).execute().a().g()).getJSONObject("response");
|
||||
} catch (JSONException | IOException e) {
|
||||
Log.d("VTLMusic", "Error: " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -28,15 +28,13 @@ public class FFMpeg {
|
||||
* @return True if success, else false
|
||||
*/
|
||||
public static boolean convert(File in, String out, MusicTrack track) {
|
||||
checkFFMpegLibs();
|
||||
|
||||
|
||||
// convert .ts file to .mp3 file via ffmpeg
|
||||
var sb = new StringBuilder();
|
||||
sb.append("-y -i \"").append(in.getAbsolutePath()).append("\"");
|
||||
sb.append(" -map 0 -dn ");
|
||||
//sb.append(" -loglevel error");
|
||||
sb.append(" -hide_banner");
|
||||
//sb.append(" -hide_banner");
|
||||
sb.append(" -write_id3v2 1");
|
||||
|
||||
String title = null;
|
||||
@@ -60,6 +58,7 @@ public class FFMpeg {
|
||||
if (track.I != null) {
|
||||
sb.append(" -metadata album=\"").append(track.I.getTitle()).append("\"");
|
||||
}
|
||||
sb.append(" -write_xing 0");
|
||||
|
||||
sb.append(" -c copy \"").append(out).append("\"");
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.vk.dto.music.MusicTrack;
|
||||
import java.io.File;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import ru.vtosters.lite.concurrent.VTExecutors;
|
||||
import ru.vtosters.lite.music.Callback;
|
||||
import ru.vtosters.lite.music.M3UDownloader;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
@@ -36,6 +37,9 @@ public class TrackDownloader {
|
||||
Log.v("TrackDownloader", "Directory created");
|
||||
else
|
||||
Log.e("TrackDownloader", "Directory creation failed");
|
||||
downloader.downloadTrack(track, outDir, callback, cache);
|
||||
|
||||
VTExecutors.getMusicDownloadExecutor().execute(
|
||||
() -> downloader.downloadTrack(track, outDir, callback, cache)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ru.vtosters.lite.feature.music;
|
||||
package ru.vtosters.lite.music.hook;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
+23
-10
@@ -1,4 +1,4 @@
|
||||
package ru.vtosters.lite.hooks.ui;
|
||||
package ru.vtosters.lite.music.hook;
|
||||
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.asId;
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.getInstance;
|
||||
@@ -19,15 +19,13 @@ import com.vk.music.common.MusicPlaybackLaunchContext;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClientImpl;
|
||||
import ru.vtosters.lite.downloaders.AudioDownloader;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class MusicBottomSheetHook {
|
||||
private static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
public static ArrayList<MusicAction> hook(ArrayList<MusicAction> actions, MusicTrack musicTrack) {
|
||||
if (musicTrack.F1()) return actions;
|
||||
|
||||
@@ -40,9 +38,15 @@ public class MusicBottomSheetHook {
|
||||
if (isIntegrationEnabled()) {
|
||||
if (isVkxCached(trackid)) {
|
||||
actions.add(getRemoveCacheTrackVkxAction());
|
||||
} else {
|
||||
} else if (isNetworkConnected()){
|
||||
actions.add(addToCacheTrackVkxAction());
|
||||
}
|
||||
} else {
|
||||
if (isCached(trackid)) {
|
||||
actions.add(getRemoveCacheTrackAction());
|
||||
} else if (isNetworkConnected()){
|
||||
actions.add(addToCacheTrackAction());
|
||||
}
|
||||
}
|
||||
|
||||
if (isNetworkConnected()) {
|
||||
@@ -89,10 +93,10 @@ public class MusicBottomSheetHook {
|
||||
if (isIntegrationEnabled()) {
|
||||
if (isVkxCached(playlist.a, playlist.b)) {
|
||||
actions.add(getRemoveCacheTrackVkxAction());
|
||||
} else {
|
||||
} else if (isNetworkConnected()){
|
||||
actions.add(addToCacheTrackVkxAction());
|
||||
}
|
||||
} else {
|
||||
} else if (isNetworkConnected()){
|
||||
actions.add(addToCacheTrackAction());
|
||||
}
|
||||
|
||||
@@ -125,6 +129,15 @@ public class MusicBottomSheetHook {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (actionId == R.id.remove_from_cache) {
|
||||
CacheDatabaseDelegate.removeTrackFromCache(asId(track));
|
||||
AndroidUtils.sendToast(AndroidUtils.getString("audio_deleted_from_cache"));
|
||||
return true;
|
||||
} else if (actionId == R.id.add_to_cache) {
|
||||
AudioDownloader.cacheTrack(track);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (actionId == R.id.download_mp3) {
|
||||
if (isIntegrationEnabled()) {
|
||||
getInstance().runOnService(service -> {
|
||||
@@ -149,7 +162,7 @@ public class MusicBottomSheetHook {
|
||||
return tryPlayInVKX(null, null, playlist);
|
||||
|
||||
if (actionId == R.id.add_to_cache) {
|
||||
executor.submit(() -> AudioDownloader.cachePlaylist(playlist));
|
||||
AudioDownloader.cachePlaylist(playlist);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -183,7 +196,7 @@ public class MusicBottomSheetHook {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
executor.submit(() -> AudioDownloader.downloadPlaylist(playlist));
|
||||
AudioDownloader.downloadPlaylist(playlist);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package ru.vtosters.lite.net;
|
||||
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -14,30 +15,24 @@ import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public final class NetCall {
|
||||
private final NetRequest req;
|
||||
private final NetClient cl;
|
||||
private final Executor executor;
|
||||
|
||||
protected NetCall(NetClient cl, NetRequest req, Executor executor) {
|
||||
protected NetCall(NetClient cl, NetRequest req) {
|
||||
this.req = req;
|
||||
this.cl = cl;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
private static String constructArgs(Map<String, String> args) throws UnsupportedEncodingException {
|
||||
args = new TreeMap<>(args);
|
||||
StringBuilder str = new StringBuilder();
|
||||
String str = "";
|
||||
for (Map.Entry<String, String> en : args.entrySet()) {
|
||||
if (str.length() > 0)
|
||||
str.append("&");
|
||||
str.append(URLEncoder.encode(en.getKey(), "UTF-8"))
|
||||
.append("=")
|
||||
.append(URLEncoder.encode(en.getValue(), "UTF-8"));
|
||||
if (!str.isEmpty()) str += "&";
|
||||
str += URLEncoder.encode(en.getKey(), "UTF-8") + "=" + URLEncoder.encode(en.getValue(), "UTF-8");
|
||||
}
|
||||
return str.toString();
|
||||
return str;
|
||||
}
|
||||
|
||||
public NetRequest request() {
|
||||
@@ -82,13 +77,22 @@ public final class NetCall {
|
||||
}
|
||||
|
||||
public void enqueue(NetCallback cb) {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
NetResponse resp = execute();
|
||||
cb.onResponse(NetCall.this, resp);
|
||||
} catch (IOException e) {
|
||||
cb.onFailure(NetCall.this, e);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
NetResponse resp = execute();
|
||||
cb.onResponse(NetCall.this, resp);
|
||||
} catch (IOException e) {
|
||||
cb.onFailure(NetCall.this, e);
|
||||
}
|
||||
try {
|
||||
interrupt();
|
||||
join();
|
||||
} catch (Exception e) {
|
||||
Log.e("NetCall", "Failed to interrupt and join thread", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,12 @@ package ru.vtosters.lite.net;
|
||||
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.net.Proxy;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class NetClient {
|
||||
private final long timeout;
|
||||
private final Proxy proxy;
|
||||
private final PasswordAuthentication authenticator;
|
||||
private final Executor executor
|
||||
= Executors.newSingleThreadExecutor();
|
||||
|
||||
protected NetClient(Builder b) {
|
||||
timeout = b.timeout;
|
||||
@@ -28,7 +24,7 @@ public class NetClient {
|
||||
}
|
||||
|
||||
public NetCall newCall(NetRequest req) {
|
||||
return new NetCall(this, req, executor);
|
||||
return new NetCall(this, req);
|
||||
}
|
||||
|
||||
public PasswordAuthentication getAuthenticator() {
|
||||
|
||||
@@ -2,77 +2,75 @@ package ru.vtosters.lite.net;
|
||||
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.vk.core.network.Network;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class Request {
|
||||
|
||||
private static final Executor EXECUTOR =
|
||||
Executors.newSingleThreadExecutor();
|
||||
|
||||
public static void makeRequest(byte[] bArr, RequestCallback callback) {
|
||||
EXECUTOR.execute(new MakeRequestTask(bArr, callback));
|
||||
public static void makeRequest(byte[] bArr, RequestCallback RequestCallback) {
|
||||
new MakeRequestTask(bArr, RequestCallback).execute();
|
||||
}
|
||||
|
||||
public static void makeRequest(String str, RequestCallback callback) {
|
||||
makeRequest(str.getBytes(), callback);
|
||||
public static void makeRequest(String str, RequestCallback RequestCallback) {
|
||||
new MakeRequestTask(str.getBytes(), RequestCallback).execute();
|
||||
}
|
||||
|
||||
public interface RequestCallback {
|
||||
void onResponse(String str);
|
||||
}
|
||||
|
||||
private static class MakeRequestTask implements Runnable {
|
||||
private static class MakeRequestTask extends AsyncTask<Void, Void, String> {
|
||||
private final RequestCallback callback;
|
||||
private final byte[] url;
|
||||
private final boolean mIsPut;
|
||||
private final boolean mIsVTostersRequest;
|
||||
|
||||
public MakeRequestTask(byte[] bArr, RequestCallback callback) {
|
||||
this.mIsVTostersRequest = false;
|
||||
this.mIsPut = false;
|
||||
this.callback = callback;
|
||||
this.url = bArr;
|
||||
public MakeRequestTask(byte[] bArr, RequestCallback RequestCallback) {
|
||||
mIsVTostersRequest = false;
|
||||
mIsPut = false;
|
||||
callback = RequestCallback;
|
||||
url = bArr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public String doInBackground(Void... voidArr) {
|
||||
try {
|
||||
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(new String(url)).openConnection();
|
||||
httpURLConnection.setRequestMethod(mIsPut ? "PUT" : "GET");
|
||||
|
||||
if (mIsVTostersRequest) {
|
||||
httpURLConnection.setRequestProperty("Token", getUserToken());
|
||||
} else {
|
||||
}
|
||||
if (!mIsVTostersRequest) {
|
||||
httpURLConnection.setRequestProperty("User-Agent", Network.l.c().a());
|
||||
}
|
||||
|
||||
httpURLConnection.setRequestProperty("Content-Type", mIsVTostersRequest
|
||||
? "Content-Type"
|
||||
: "application/x-www-form-urlencoded");
|
||||
httpURLConnection.setRequestProperty("Content-Type", mIsVTostersRequest ? "Content-Type" : "application/x-www-form-urlencoded");
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
while (true) {
|
||||
String readLine = bufferedReader.readLine();
|
||||
if (readLine != null) {
|
||||
builder.append(readLine);
|
||||
stringBuffer.append(readLine);
|
||||
} else {
|
||||
bufferedReader.close();
|
||||
callback.onResponse(builder.toString());
|
||||
break;
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
callback.onResponse(e.getLocalizedMessage());
|
||||
return e.getLocalizedMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public void onPostExecute(String str) {
|
||||
super.onPostExecute(str);
|
||||
callback.onResponse(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,10 @@ import java.util.Arrays;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
|
||||
public class GithubList {
|
||||
private static final OkHttpClient mClient = new OkHttpClient();
|
||||
private static final OkHttpClient mClient = VtOkHttpClient.getInstance();
|
||||
|
||||
public static ArrayList<String> getProxy(String url, String proxyname) throws IOException {
|
||||
Request link = new Request.a()
|
||||
@@ -28,7 +29,7 @@ public class GithubList {
|
||||
Log.d(proxyname, response);
|
||||
|
||||
return new ArrayList<>(Arrays.asList(response.split("\n")));
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
Log.d(proxyname, "Failed to fetch data, link: " + link);
|
||||
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.vtosters.lite.R.color.*;
|
||||
|
||||
public class ColorReferences {
|
||||
public static List<Integer> accentColors = Arrays.asList(
|
||||
Color.parseColor("#3f8ae0"), // azure_300 (light accent)
|
||||
Color.parseColor("#4986cc"), // azure_a400
|
||||
Color.parseColor("#528bcc"), // another light accent
|
||||
Color.parseColor("#71aaeb"), // vk_sky_300 (dark accent)
|
||||
Color.parseColor("#5181b8"), // header_blue
|
||||
Color.parseColor("#5a9eff"),
|
||||
Color.parseColor("#5692d7"),
|
||||
Color.parseColor("#5c9ce6"),
|
||||
Color.parseColor("#518bcc"),
|
||||
Color.parseColor("#74a2d6")
|
||||
);
|
||||
|
||||
public static List<Integer> mutedAccentColors = Arrays.asList(
|
||||
Color.parseColor("#663f8ae0"),
|
||||
Color.parseColor("#19528bcc"),
|
||||
Color.parseColor("#66528bcc"),
|
||||
Color.parseColor("#1971aaeb"),
|
||||
Color.parseColor("#665181b8"),
|
||||
Color.parseColor("#1a003973"),
|
||||
Color.parseColor("#a800244d"),
|
||||
Color.parseColor("#14001c3d"),
|
||||
Color.parseColor("#3d001c3d"),
|
||||
Color.parseColor("#67a5eb"),
|
||||
Color.parseColor("#45678f"),
|
||||
Color.parseColor("#6645678f"),
|
||||
Color.parseColor("#0099cc"),
|
||||
Color.parseColor("#664986cc")
|
||||
);
|
||||
|
||||
public static List<Integer> accents = Arrays.asList(
|
||||
viewer_retry_button_text_color,
|
||||
azure_300,
|
||||
picker_camera_button,
|
||||
music_check_button_bg_pressed,
|
||||
notification_color,
|
||||
music_text_counter,
|
||||
music_follow_button_bg_pressed,
|
||||
music_blue_button_normal,
|
||||
music_check_button_bg_normal,
|
||||
vk_terms_link,
|
||||
vk_blue_200,
|
||||
accent_blue,
|
||||
azure_A400,
|
||||
vk_azure_A400,
|
||||
blue,
|
||||
blue_200,
|
||||
vk_blue_300,
|
||||
vk_blue_400,
|
||||
blue_300,
|
||||
blue_400,
|
||||
cool_blue,
|
||||
cornflower_blue,
|
||||
cornflower_blue_two,
|
||||
dot_unread,
|
||||
fave_promo_btn_pressed,
|
||||
header_blue,
|
||||
colorAccent,
|
||||
live_emoji_butt_hide,
|
||||
music_action_button_blue,
|
||||
name,
|
||||
picker_blue,
|
||||
picker_blue_pressed,
|
||||
picker_tab_bg_selected,
|
||||
picker_tab_text_selected,
|
||||
sharing_blue_btn_normal,
|
||||
sharing_blue_btn_pressed,
|
||||
vk_sky_300,
|
||||
vk_blue_A400,
|
||||
blue_A400,
|
||||
sky_300,
|
||||
text_blue,
|
||||
tip_background,
|
||||
tw__blue_default,
|
||||
tw__blue_pressed,
|
||||
vkim_msg_sending_ic,
|
||||
vkim_playing_drawable_rect,
|
||||
vk_white_blue32,
|
||||
date_picker_selector,
|
||||
post_suggest_blue,
|
||||
list_dialog_blue,
|
||||
music_tab_bg_normal,
|
||||
toolbar_blue_background,
|
||||
toolbar_blue_statusBarColorBack
|
||||
);
|
||||
|
||||
public static List<Integer> mutedAccents = Arrays.asList(
|
||||
blue_200_muted,
|
||||
vk_blue_200_muted,
|
||||
white_blue32,
|
||||
vk_white_blue32,
|
||||
header_blue_opacity16,
|
||||
black_blue45_alpha10,
|
||||
music_check_button_bg_checked,
|
||||
vk_black_blue45_alpha10,
|
||||
black_blue30_alpha66,
|
||||
vk_black_blue30_alpha66,
|
||||
attachpicker_item_background,
|
||||
black_blue24_alpha8,
|
||||
music_placeholder_artist_bg,
|
||||
black_blue24_alpha24,
|
||||
vk_black_blue24_alpha24,
|
||||
azure_100_muted,
|
||||
vk_azure_100_muted,
|
||||
muted_blue,
|
||||
blue_600,
|
||||
light_blue,
|
||||
vk_blue_600,
|
||||
muted_blue_opacity40,
|
||||
muted_blue_old,
|
||||
darker_blue,
|
||||
header_blue_opacity40
|
||||
);
|
||||
|
||||
public static boolean isAccentedColor(ColorStateList target) {
|
||||
return target != null && isAccentedColor(target.getDefaultColor());
|
||||
}
|
||||
|
||||
public static boolean isAccentedColor(int target) {
|
||||
return accentColors.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isMutedAccentedColor(ColorStateList target) {
|
||||
return target != null && isMutedAccentedColor(target.getDefaultColor());
|
||||
}
|
||||
|
||||
public static boolean isMutedAccentedColor(int target) {
|
||||
return mutedAccentColors.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isColorRefAccented(int target) {
|
||||
return accents.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isColorRefMutedAccented(int target) {
|
||||
return mutedAccents.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isCslNeedToBeThemed(ColorStateList csl) {
|
||||
int unsel = csl.getColorForState(new int[]{-android.R.attr.state_selected}, Color.BLACK);
|
||||
int sel = csl.getColorForState(new int[]{android.R.attr.state_selected}, Color.BLACK);
|
||||
boolean isUnselAccent = isAccentedColor(unsel);
|
||||
boolean isSelAccent = isAccentedColor(sel);
|
||||
return ThemesCore.isCachedAccents() && (isUnselAccent || isSelAccent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
|
||||
public class ThemesCore {
|
||||
private static final String TAG = "ThemesCore";
|
||||
|
||||
public static SparseIntArray themedColors = new SparseIntArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_DARK = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_NOMILK_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_NOMILK = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_MILK_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_MILK_DARK = new SparseBooleanArray();
|
||||
|
||||
private static boolean cachedAccents = false;
|
||||
private static int wallLightColor;
|
||||
|
||||
static {
|
||||
setExceptions();
|
||||
setThemedColors(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
public static void setExceptions() {
|
||||
ACCENT_THEME_ONLY_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_DARK.clear();
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_NOMILK.clear();
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_MILK_DARK.clear();
|
||||
|
||||
ACCENT_THEME_ONLY_LIGHT.put(R.attr.attach_picker_tab_active_background, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(R.attr.attach_picker_tab_active_text, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(R.attr.newsfeed_action_color, false);
|
||||
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(R.attr.header_background, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.header_background, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(R.attr.header_alternate_background, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.header_alternate_background, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(R.attr.header_background_before_blur, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.header_background_before_blur, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(R.attr.header_background_before_blur_alternate, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.header_background_before_blur_alternate, false);
|
||||
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(R.attr.header_tint, false);
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(R.attr.header_tint_alternate, false);
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(R.attr.toolbarIconsColor, false);
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(R.attr.header_tab_active_indicator, false);
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(R.attr.header_alternate_tab_active_indicator, false);
|
||||
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(R.attr.im_dropdown_arrow_tint, false);
|
||||
|
||||
ACCENT_THEME_ONLY_NOMILK.put(R.attr.im_dropdown_icon_color, false);
|
||||
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.icon_name, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.text_name, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.button_primary_background, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.button_secondary_foreground, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.button_tertiary_foreground, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.button_muted_foreground, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.button_outline_border, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.newsfeed_post_title_color, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.counter_primary_background, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.action_sheet_action_foreground, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.im_bubble_wallpaper_outgoing, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.im_bubble_outgoing, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.im_bubble_outgoing_highlighted, false);
|
||||
}
|
||||
|
||||
public static void setThemedColors(int accentColor) {
|
||||
int mutedAccentColor = ThemesUtils.getMutedColor(accentColor);
|
||||
|
||||
cachedAccents = true;
|
||||
themedColors.clear();
|
||||
|
||||
themedColors.put(R.attr.text_link, accentColor);
|
||||
themedColors.put(R.attr.accent, accentColor);
|
||||
themedColors.put(R.attr.newsfeed_dropdown_color, accentColor);
|
||||
themedColors.put(R.attr.icon_name, accentColor);
|
||||
|
||||
themedColors.put(R.attr.vk_accent, accentColor);
|
||||
themedColors.put(R.attr.accentColor, accentColor);
|
||||
themedColors.put(R.attr.text_name, accentColor);
|
||||
themedColors.put(R.attr.tabbar_active_icon, accentColor);
|
||||
|
||||
// themedColors.put(com.vtosters.lite.R.attr.header_background, accentColor);
|
||||
// themedColors.put(com.vtosters.lite.R.attr.header_alternate_background, accentColor);
|
||||
// themedColors.put(com.vtosters.lite.R.attr.header_background_before_blur, accentColor);
|
||||
// themedColors.put(com.vtosters.lite.R.attr.header_background_before_blur_alternate, accentColor);
|
||||
|
||||
themedColors.put(R.attr.header_tint, accentColor);
|
||||
themedColors.put(R.attr.header_tint_alternate, accentColor);
|
||||
themedColors.put(R.attr.activity_indicator_tint, accentColor);
|
||||
themedColors.put(R.attr.toolbarIconsColor, accentColor);
|
||||
|
||||
themedColors.put(R.attr.button_primary_background, accentColor);
|
||||
themedColors.put(R.attr.button_secondary_foreground, accentColor);
|
||||
themedColors.put(R.attr.button_tertiary_foreground, accentColor);
|
||||
themedColors.put(R.attr.button_outline_border, accentColor);
|
||||
themedColors.put(R.attr.button_muted_foreground, accentColor);
|
||||
themedColors.put(R.attr.header_tab_active_indicator, accentColor);
|
||||
themedColors.put(R.attr.header_alternate_tab_active_indicator, accentColor);
|
||||
|
||||
themedColors.put(R.attr.button_primary_background_disabled, mutedAccentColor);
|
||||
themedColors.put(R.attr.button_secondary_foreground_disabled, mutedAccentColor);
|
||||
themedColors.put(R.attr.button_tertiary_foreground_disabled, mutedAccentColor);
|
||||
themedColors.put(R.attr.button_outline_border_disabled, mutedAccentColor);
|
||||
themedColors.put(R.attr.button_muted_foreground_disabled, mutedAccentColor);
|
||||
|
||||
themedColors.put(R.attr.im_dropdown_icon_color, accentColor);
|
||||
themedColors.put(R.attr.im_dropdown_arrow_tint, accentColor);
|
||||
|
||||
themedColors.put(R.attr.im_attach_tint, accentColor);
|
||||
themedColors.put(R.attr.im_forward_line_tint, accentColor);
|
||||
themedColors.put(R.attr.link_alternate, accentColor);
|
||||
themedColors.put(R.attr.newsfeed_post_title_color, accentColor);
|
||||
|
||||
themedColors.put(R.attr.attach_picker_tab_active_background, accentColor);
|
||||
themedColors.put(R.attr.attach_picker_tab_active_text, accentColor);
|
||||
themedColors.put(R.attr.newsfeed_action_color, accentColor);
|
||||
themedColors.put(R.attr.counter_primary_background, accentColor);
|
||||
|
||||
themedColors.put(R.attr.dynamic_blue, accentColor);
|
||||
|
||||
themedColors.put(R.attr.action_sheet_action_foreground, accentColor);
|
||||
|
||||
// messages
|
||||
themedColors.put(R.attr.im_reply_separator, accentColor);
|
||||
themedColors.put(R.attr.im_text_name, accentColor);
|
||||
|
||||
wallLightColor = ThemesUtils.lighten(accentColor, 0.67f);
|
||||
|
||||
themedColors.put(R.attr.im_ic_send_msg, accentColor);
|
||||
themedColors.put(R.attr.im_bubble_wallpaper_outgoing, accentColor);
|
||||
themedColors.put(R.attr.im_bubble_outgoing, accentColor);
|
||||
themedColors.put(R.attr.im_bubble_outgoing_highlighted, accentColor);
|
||||
}
|
||||
|
||||
public static int getThemedAttr(Context context, @IdRes int attr) {
|
||||
if (attr == R.attr.im_bubble_wallpaper_outgoing || attr == R.attr.im_bubble_outgoing || attr == R.attr.im_bubble_outgoing_highlighted) {
|
||||
return wallLightColor;
|
||||
}
|
||||
|
||||
return themedColors.get(attr);
|
||||
}
|
||||
|
||||
public static boolean hasThemedAttr(Context context, int attrID) {
|
||||
// try {
|
||||
// Log.d(TAG, "Requesting color by attr " + context.getResources().getResourceName(attrID));
|
||||
// } catch (Exception e) {
|
||||
// }
|
||||
|
||||
if (isCachedAccents()) {
|
||||
if (ThemesUtils.isDarkTheme()) {
|
||||
return (themedColors.get(attrID) != 0 && ACCENT_THEME_ONLY_DARK.get(attrID, true) && (
|
||||
ThemesUtils.isMilkshake() ?
|
||||
ACCENT_THEME_ONLY_MILK_DARK.get(attrID, true) :
|
||||
ACCENT_THEME_ONLY_NOMILK.get(attrID, true)));
|
||||
} else {
|
||||
return (themedColors.get(attrID) != 0 && ACCENT_THEME_ONLY_LIGHT.get(attrID, true) && (
|
||||
ThemesUtils.isMilkshake() ?
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.get(attrID, true) :
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.get(attrID, true)));
|
||||
}
|
||||
} else {
|
||||
return themedColors.get(attrID) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
cachedAccents = false;
|
||||
themedColors.clear();
|
||||
}
|
||||
|
||||
public static boolean isCachedAccents() {
|
||||
return cachedAccents;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.*;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.vtosters.lite.R;
|
||||
import ru.vtosters.lite.themes.utils.RecolorUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ThemesHacks {
|
||||
// Фиксит селектор (все/свои/архив) в профиле
|
||||
public static void fixProfileSelector(View view) {
|
||||
if (!ThemesUtils.isMilkshake()) return;
|
||||
var id = view.getId();
|
||||
|
||||
if (id == R.id.profile_wall_owner_posts || id == R.id.profile_wall_all_posts || id == R.id.profile_wall_archived_posts) {
|
||||
StateListDrawable states = (StateListDrawable) ((LayerDrawable) view.getBackground()).getDrawable(0);
|
||||
LayerDrawable selected = (LayerDrawable) ((DrawableContainer.DrawableContainerState) states.getConstantState()).getChildren()[0];
|
||||
((ColorDrawable) selected.getDrawable(0)).setColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
public static void fixThemedFeed(TextView textView, int i) {
|
||||
if (i != R.layout.themed_feed_tab_2) {
|
||||
return;
|
||||
}
|
||||
textView.setTextColor(RecolorUtils.recolorCSL(textView.getTextColors()));
|
||||
((InsetDrawable) ((DrawableContainer.DrawableContainerState) textView.getBackground().getConstantState()).getChildren()[0]).getDrawable().setTint(ThemesUtils.lighten(ThemesUtils.getAccentColor(), 0.15f));
|
||||
}
|
||||
|
||||
public static void fixDropdown(Drawable drawable) {
|
||||
if (!ThemesUtils.isDarkTheme() && ThemesUtils.isMilkshake() && ThemesCore.isCachedAccents()) {
|
||||
StateListDrawable stateListDrawable = (StateListDrawable) drawable;
|
||||
((DrawableContainer.DrawableContainerState) stateListDrawable.getConstantState()).getChildren()[0].setTint(ThemesUtils.getAccentColor());
|
||||
((DrawableContainer.DrawableContainerState) stateListDrawable.getConstantState()).getChildren()[1].setTint(ThemesUtils.halfAlpha(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
|
||||
public static int getHackedColor(@NonNull Context context, @ColorRes int color) {
|
||||
if (ThemesCore.isCachedAccents() && ColorReferences.isAccentedColor(context.getColor(color))) {
|
||||
return ThemesUtils.getAccentColor();
|
||||
}
|
||||
|
||||
if (ThemesCore.isCachedAccents() && ColorReferences.isMutedAccentedColor(context.getColor(color))) {
|
||||
return ThemesUtils.getMutedAccentColor();
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT > 23) {
|
||||
return context.getColor(color);
|
||||
} else return context.getResources().getColor(color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class VTLResources extends Resources {
|
||||
private static final String TAG = "VTLResources";
|
||||
private final Context context;
|
||||
private static Field typedArrayField;
|
||||
|
||||
private static final List<Integer> attributesToTheme = new ArrayList<>();
|
||||
|
||||
static {
|
||||
try {
|
||||
typedArrayField = TypedArray.class.getDeclaredField("mData");
|
||||
typedArrayField.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
attributesToTheme.add(16843041);
|
||||
attributesToTheme.add(android.R.attr.backgroundTint);
|
||||
attributesToTheme.add(16843173);
|
||||
}
|
||||
|
||||
public VTLResources(Context context, Resources parent) {
|
||||
super(parent.getAssets(), parent.getDisplayMetrics(), parent.getConfiguration());
|
||||
this.context = context;
|
||||
// Log.d(TAG, "VTLResources: init");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
|
||||
var typedArray = super.obtainAttributes(set, attrs);
|
||||
var data = getArrayData(typedArray);
|
||||
for (int i = 0; i < attrs.length; i++) {
|
||||
try {
|
||||
int attrID = attrs[i];
|
||||
if (attributesToTheme.contains(attrID)) {
|
||||
int type = data[i*6];
|
||||
int cnt = data[(i*6)+1];
|
||||
|
||||
if (type == TypedValue.TYPE_ATTRIBUTE && isAttrThemeable(cnt)) {
|
||||
data[i*6] = TypedValue.TYPE_INT_COLOR_RGB8;
|
||||
data[(i*6)+1] = ThemesUtils.getAccentColor();
|
||||
data[(i*6)+2] = 0; // clear reference content
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "TAVzlom failed! (obtainAttributes)");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return typedArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getDrawable(int id, @Nullable Theme theme) throws NotFoundException {
|
||||
var drawable = super.getDrawable(id, theme);
|
||||
if (id == com.vtosters.lite.R.drawable.newsfeed_tab_dropdown_16) {
|
||||
ThemesHacks.fixDropdown(drawable);
|
||||
}
|
||||
return drawable;
|
||||
}
|
||||
|
||||
private static boolean isAttrThemeable(int attrID) {
|
||||
return !ThemesUtils.isDarkTheme() && attrID == com.vtosters.lite.R.attr.button_primary_background;
|
||||
}
|
||||
|
||||
private static int[] getArrayData(TypedArray arr) {
|
||||
try {
|
||||
return (int[]) typedArrayField.get(arr);
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.e(TAG, "getArrayData: ", e);
|
||||
e.printStackTrace();
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ru.vtosters.lite.themes.hooks.BaseHook;
|
||||
import ru.vtosters.lite.themes.hooks.ButtonHook;
|
||||
import ru.vtosters.lite.themes.hooks.ImageViewHook;
|
||||
import ru.vtosters.lite.themes.hooks.ProgressWheelHook;
|
||||
import ru.vtosters.lite.themes.hooks.TabLayoutHook;
|
||||
import ru.vtosters.lite.themes.hooks.TextViewHook;
|
||||
import ru.vtosters.lite.themes.hooks.ToolbarHook;
|
||||
import ru.vtosters.lite.themes.hooks.VKImageViewHook;
|
||||
|
||||
public class ViewInjector {
|
||||
public static ArrayList<BaseHook> hooks = new ArrayList<>();
|
||||
|
||||
static {
|
||||
hooks.add(new ButtonHook());
|
||||
hooks.add(new ImageViewHook());
|
||||
hooks.add(new TabLayoutHook());
|
||||
hooks.add(new TextViewHook());
|
||||
hooks.add(new ToolbarHook());
|
||||
hooks.add(new VKImageViewHook());
|
||||
hooks.add(new ProgressWheelHook());
|
||||
}
|
||||
|
||||
public static View inject(View view, int i, boolean z) {
|
||||
for (BaseHook hook : hooks) {
|
||||
hook.inject(view, i, z);
|
||||
}
|
||||
if (view instanceof ViewGroup) {
|
||||
var viewGroup = (ViewGroup) view;
|
||||
for (int i2 = 0; i2 < viewGroup.getChildCount(); i2++) {
|
||||
inject(viewGroup.getChildAt(i2), i, false);
|
||||
}
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
public interface BaseHook {
|
||||
void inject(View view, int i, boolean z);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ButtonHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof Button) {
|
||||
var button = (Button) view;
|
||||
if (button.getBackgroundTintList() != null && ColorReferences.isMutedAccentedColor(button.getBackgroundTintList())) {
|
||||
button.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getMutedAccentColor()));
|
||||
}
|
||||
|
||||
if (button.getBackgroundTintList() != null && ColorReferences.isAccentedColor(button.getBackgroundTintList())) {
|
||||
button.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (TextViewHook.isPositiveButton(button) || TextViewHook.isVkUiButton(view)) {
|
||||
button.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.themes.ThemesCore;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ImageViewHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof ImageView) {
|
||||
if (ThemesCore.isCachedAccents()) {
|
||||
var imageView = (ImageView) view;
|
||||
if (imageView.getImageTintList() == null) return;
|
||||
if (ColorReferences.isCslNeedToBeThemed(imageView.getImageTintList())) {
|
||||
imageView.setImageTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.pnikosis.materialishprogress.ProgressWheel;
|
||||
|
||||
import ru.vtosters.lite.themes.ThemesCore;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ProgressWheelHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof ProgressWheel) {
|
||||
if (ThemesCore.isCachedAccents()) {
|
||||
var progressWheel = (ProgressWheel) view;
|
||||
progressWheel.setBarColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.view.View;
|
||||
|
||||
import com.vk.core.view.VKTabLayout;
|
||||
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
|
||||
public class TabLayoutHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof VKTabLayout) {
|
||||
var tabLayout = (VKTabLayout) view;
|
||||
tabLayout.setSelectedTabIndicatorColor(ThemesUtils.getAccentColor());
|
||||
tabLayout.setTabRippleColor(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatCheckedTextView;
|
||||
|
||||
import com.vk.core.extensions.EditTextExt;
|
||||
import com.vk.core.view.OverlayTextView;
|
||||
import com.vk.core.view.TintTextView;
|
||||
import com.vk.core.view.links.LinkedTextView;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.themes.ThemesHacks;
|
||||
import ru.vtosters.lite.themes.utils.VkUiThemer;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class TextViewHook implements BaseHook {
|
||||
|
||||
private static final String TAG = "TextViewHook";
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof TextView) {
|
||||
var textView = (TextView) view;
|
||||
|
||||
if (ColorReferences.isAccentedColor(textView.getCurrentTextColor())) {
|
||||
textView.setTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(textView.getCurrentTextColor())) {
|
||||
textView.setTextColor(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && textView.getCompoundDrawableTintList() != null) {
|
||||
if (ColorReferences.isAccentedColor(textView.getCompoundDrawableTintList())) {
|
||||
textView.setCompoundDrawableTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(textView.getCompoundDrawableTintList())) {
|
||||
textView.setCompoundDrawableTintList(ColorStateList.valueOf(ThemesUtils.getMutedAccentColor()));
|
||||
}
|
||||
}
|
||||
|
||||
if (textView.getLinkTextColors() != null && ColorReferences.isAccentedColor(textView.getLinkTextColors())) {
|
||||
textView.setLinkTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (textView.getLinkTextColors() != null && ColorReferences.isMutedAccentedColor(textView.getLinkTextColors())) {
|
||||
textView.setLinkTextColor(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
if (isPositiveButton(textView) || isVkUiButton(textView)) {
|
||||
view.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (view instanceof OverlayTextView) {
|
||||
if (view.getId() == android.R.id.button1) {
|
||||
view.setBackground(ThemesUtils.recolorDrawable(view.getBackground()));
|
||||
}
|
||||
if (ColorReferences.isAccentedColor(((OverlayTextView) view).getTextColors().getDefaultColor())) {
|
||||
((OverlayTextView) view).setTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
if (view instanceof TintTextView) {
|
||||
if (eligibleForStartTinting((TintTextView) view)) {
|
||||
((TintTextView) view).setDrawableStartTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (eligibleForStartTintingMuted((TintTextView) view)) {
|
||||
((TintTextView) view).setDrawableStartTint(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
if (eligibleForTinting(view.getId())) {
|
||||
((TintTextView) view).setDrawableTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (eligibleForTinting(view.getId())) {
|
||||
((TintTextView) view).setDrawableStartTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
if (view instanceof LinkedTextView) {
|
||||
((LinkedTextView) view).setLinkTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (view instanceof AppCompatCheckedTextView) {
|
||||
var check = (AppCompatCheckedTextView) view;
|
||||
if (ColorReferences.isAccentedColor(check.getCheckMarkTintList())) {
|
||||
check.setCheckMarkTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(check.getCheckMarkTintList())) {
|
||||
check.setCheckMarkTintList(ColorStateList.valueOf(ThemesUtils.getMutedAccentColor()));
|
||||
}
|
||||
}
|
||||
|
||||
if (view instanceof EditText) {
|
||||
ThemesUtils.setCursorColor((EditText) view);
|
||||
}
|
||||
|
||||
ThemesUtils.colorHandles(textView);
|
||||
VkUiThemer.autoThemeVkuiButtons(textView);
|
||||
ThemesHacks.fixProfileSelector(textView);
|
||||
ThemesHacks.fixThemedFeed(textView, i);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean eligibleForStartTinting(TintTextView view) {
|
||||
return ColorReferences.isAccentedColor(view.getTextColors()) || view.getTextColors().getDefaultColor() == ThemesUtils.getAccentColor();
|
||||
}
|
||||
|
||||
public static boolean eligibleForStartTintingMuted(TintTextView view) {
|
||||
return ColorReferences.isMutedAccentedColor(view.getTextColors()) || view.getTextColors().getDefaultColor() == ThemesUtils.getMutedAccentColor();
|
||||
}
|
||||
|
||||
public static boolean eligibleForTinting(int id) {
|
||||
return !ThemesUtils.isDarkTheme() && (id == R.id.attach_title || id == R.id.post_retweet_name);
|
||||
}
|
||||
|
||||
public static boolean isPositiveButton(View view) {
|
||||
return !ThemesUtils.isDarkTheme() && (view.getId() == R.id.positive || view.getId() == R.id.positive_button);
|
||||
}
|
||||
|
||||
public static boolean isVkUiButton(View view) {
|
||||
return !ThemesUtils.isDarkTheme() && (view.getId() == R.id.empty_button || view.getId() == R.id.button);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.view.View;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ToolbarHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof Toolbar) {
|
||||
var color = (ThemesUtils.isMilkshake() && !ThemesUtils.isDarkTheme()) ? ThemesUtils.getAccentColor() : ThemesUtils.getHeaderText();
|
||||
var menu = ((Toolbar) view).getMenu();
|
||||
for (int j = 0; j < menu.size(); ++j) {
|
||||
var item = menu.getItem(j);
|
||||
var icon = item.getIcon();
|
||||
if (icon != null) {
|
||||
if (icon instanceof RecoloredDrawable)
|
||||
((RecoloredDrawable) icon).a(color);
|
||||
else
|
||||
icon = new RecoloredDrawable(icon, color);
|
||||
item.setIcon(icon);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.view.View;
|
||||
|
||||
import com.vk.imageloader.view.VKImageView;
|
||||
|
||||
import ru.vtosters.lite.themes.utils.RecolorUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class VKImageViewHook implements BaseHook {
|
||||
private static Paint paint = new Paint();
|
||||
static {
|
||||
paint.setColorFilter(new PorterDuffColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof VKImageView) {
|
||||
var imageView = (VKImageView) view;
|
||||
if (imageView.getImageTintList() != null) {
|
||||
imageView.setImageTintList(RecolorUtils.recolorCSL(imageView.getImageTintList()));
|
||||
imageView.setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package ru.vtosters.lite.themes.items;
|
||||
|
||||
public class VTLColor {
|
||||
|
||||
public String resName;
|
||||
public int id;
|
||||
public int color;
|
||||
|
||||
public VTLColor(int id, int color) {
|
||||
this.id = id;
|
||||
this.color = color;
|
||||
}
|
||||
public VTLColor(String resName, int id, int color) {
|
||||
this.resName = resName;
|
||||
this.id = id;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public static VTLColor create(int id, int color) {
|
||||
return new VTLColor(id, color);
|
||||
}
|
||||
|
||||
public static VTLColor create(String resName, int id, int color) {
|
||||
return new VTLColor(resName, id, color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package ru.vtosters.lite.themes.items;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VTLPalette {
|
||||
public String id;
|
||||
public String name;
|
||||
public String author;
|
||||
public List<VTLColor> colors = new ArrayList<>();
|
||||
|
||||
public VTLPalette() {
|
||||
|
||||
}
|
||||
|
||||
public VTLPalette(String id, String name, String author, List<VTLColor> colors) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.author = author;
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
public VTLPalette setId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setAuthor(String author) {
|
||||
this.author = author;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setColors(List<VTLColor> colors) {
|
||||
this.colors = colors;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setColor(String name, int color) {
|
||||
this.colors.add(new VTLColor(name, 0, color));
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getColor(String name) {
|
||||
for (var item : colors)
|
||||
if (name.equals(item.resName))
|
||||
return item.color;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static VTLPalette fromJson(JSONObject json) throws JSONException {
|
||||
var palette = new VTLPalette()
|
||||
.setId(json.optString("palette_id"))
|
||||
.setName(json.optString("name"))
|
||||
.setAuthor(json.optString("author"));
|
||||
var paletteNode = json.getJSONArray("palette");
|
||||
for (int i = 0; i < paletteNode.length(); i++) {
|
||||
var colorNode = paletteNode.getJSONObject(i);
|
||||
var name = colorNode.getString("name");
|
||||
if (colorNode.has("colors")) {
|
||||
var colorsNode = colorNode.getJSONArray("colors");
|
||||
for (int j = 0; j < colorsNode.length(); j++) {
|
||||
var subColorNode = colorsNode.getJSONObject(j);
|
||||
var index = subColorNode.getString("index");
|
||||
var subColor = subColorNode.getString("color");
|
||||
if (!subColor.startsWith("#")) subColor = "#" + subColor;
|
||||
palette.setColor(name + " " + index, Color.parseColor(subColor));
|
||||
}
|
||||
} else {
|
||||
var color = colorNode.getString("color");
|
||||
if (!color.startsWith("#")) color = "#" + color;
|
||||
palette.setColor(name, Color.parseColor(color));
|
||||
}
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
|
||||
public static VTLPalette valuesOf(String id, String name, String author, List<VTLColor> colors) {
|
||||
return new VTLPalette()
|
||||
.setId(id)
|
||||
.setName(name)
|
||||
.setAuthor(author)
|
||||
.setColors(colors);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package ru.vtosters.lite.themes.palettes;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.themes.items.VTLPalette;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
public class PalettesManager {
|
||||
|
||||
private final static File PALETTES_DIR = new File(Environment.getExternalStorageDirectory(), "VTL/palettes");
|
||||
private final static String ASSETS_DIR = "vtl_themes/palettes/";
|
||||
|
||||
private static PalettesManager sInstance;
|
||||
|
||||
private final List<VTLPalette> mPalettes = new ArrayList<>();
|
||||
|
||||
public static PalettesManager getInstance() {
|
||||
if (sInstance == null)
|
||||
sInstance = new PalettesManager();
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public PalettesManager() {
|
||||
load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
mPalettes.clear();
|
||||
if (!PALETTES_DIR.exists())
|
||||
PALETTES_DIR.mkdirs();
|
||||
final var palettes = PALETTES_DIR.listFiles((dir, name) -> name.endsWith(".json"));
|
||||
if (palettes == null || palettes.length == 0)
|
||||
copyPaletteFromAssets();
|
||||
parsePalettes();
|
||||
}
|
||||
|
||||
private boolean copyPaletteFromAssets() {
|
||||
try {
|
||||
final var manager = AndroidUtils.getGlobalContext().getAssets();
|
||||
final var assets = manager.list(ASSETS_DIR);
|
||||
if (assets == null || assets.length == 0) return false;
|
||||
for (var asset : assets) {
|
||||
try {
|
||||
IOUtils.copyFile(manager.open(ASSETS_DIR + asset), new File(PALETTES_DIR, asset));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void parsePalettes() {
|
||||
var arr = PALETTES_DIR.listFiles((dir, name) -> name.endsWith(".json"));
|
||||
if (arr == null || arr.length == 0)
|
||||
throw new RuntimeException("Can't load palettes");
|
||||
for (var file : arr) {
|
||||
try {
|
||||
var json = new JSONObject(IOUtils.readAllLines(file));
|
||||
mPalettes.add(VTLPalette.fromJson(json));
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public VTLPalette getPalette(String id) {
|
||||
for (var palette : mPalettes)
|
||||
if (id.equals(palette.id))
|
||||
return palette;
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public VTLPalette getPalette(int i) {
|
||||
return mPalettes.get(i);
|
||||
}
|
||||
|
||||
public int getPalettesCount() {
|
||||
return mPalettes.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package ru.vtosters.lite.themes.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class RecolorUtils {
|
||||
public static Drawable recolorDrawableToolbar(Drawable drawable) {
|
||||
if (drawable == null) return null;
|
||||
|
||||
return new RecoloredDrawable(drawable, ThemesUtils.getHeaderText());
|
||||
} // Recolor toolbar drawable to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public static Drawable recolorDrawableInt(int drawable) {
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables") Drawable res = AndroidUtils.getResources().getDrawable(drawable);
|
||||
return new RecoloredDrawable(res, ThemesUtils.getAccentColor());
|
||||
} // Get res drawable via id and coloring to accent
|
||||
|
||||
public static int recolorHexColor(int i){
|
||||
var accented = ColorReferences.isAccentedColor(i);
|
||||
var mutedaccented = ColorReferences.isMutedAccentedColor(i);
|
||||
return (accented || mutedaccented) ? (accented ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : i;
|
||||
}
|
||||
|
||||
public static ColorStateList recolorCSL(ColorStateList colorStateList) {
|
||||
if (colorStateList == null) return null;
|
||||
|
||||
return ColorStateList.valueOf(ThemesUtils.getAccentColor());
|
||||
} // Recolor ColorStateList to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForColorStateLists")
|
||||
public static ColorStateList themeCSL(Context context, int color) {
|
||||
if (ColorReferences.isColorRefAccented(color)) {
|
||||
return ColorStateList.valueOf(ThemesUtils.getAccentColor());
|
||||
} else if (ColorReferences.isColorRefMutedAccented(color)) {
|
||||
return ColorStateList.valueOf(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
ColorStateList csl;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
csl = context.getColorStateList(color);
|
||||
} else {
|
||||
csl = context.getResources().getColorStateList(color);
|
||||
}
|
||||
|
||||
return themeCSL(csl);
|
||||
} // Recolor ColorStateList
|
||||
|
||||
public static ColorStateList themeCSL(ColorStateList csl){
|
||||
try {
|
||||
int unsel = csl.getColorForState(new int[]{-android.R.attr.state_selected}, Color.BLACK);
|
||||
int sel = csl.getColorForState(new int[]{android.R.attr.state_selected}, Color.BLACK);
|
||||
int enabled = csl.getColorForState(new int[]{android.R.attr.state_enabled}, Color.BLACK);
|
||||
int disabled = csl.getColorForState(new int[]{-android.R.attr.state_enabled}, Color.BLACK);
|
||||
|
||||
boolean isUnselAccent = ColorReferences.isAccentedColor(unsel);
|
||||
boolean isSelAccent = ColorReferences.isAccentedColor(sel);
|
||||
boolean isEnabledAccent = ColorReferences.isAccentedColor(enabled);
|
||||
boolean isDisabledAccent = ColorReferences.isAccentedColor(disabled);
|
||||
|
||||
boolean isUnselMutedAccent = ColorReferences.isMutedAccentedColor(unsel);
|
||||
boolean isSelMutedAccent = ColorReferences.isMutedAccentedColor(sel);
|
||||
boolean isEnabledMutedAccent = ColorReferences.isMutedAccentedColor(enabled);
|
||||
boolean isDisabledMutedAccent = ColorReferences.isMutedAccentedColor(disabled);
|
||||
|
||||
if (isUnselAccent || isSelAccent || isUnselMutedAccent || isSelMutedAccent) {
|
||||
return new ColorStateList(new int[][]{
|
||||
new int[]{android.R.attr.state_selected}, new int[]{-android.R.attr.state_selected}
|
||||
}, new int[]{(isSelAccent || isSelMutedAccent) ? (isSelAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : sel, (isUnselAccent || isUnselMutedAccent) ? (isUnselAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : unsel});
|
||||
}
|
||||
|
||||
if (isDisabledAccent || isEnabledAccent || isEnabledMutedAccent || isDisabledMutedAccent) {
|
||||
return new ColorStateList(new int[][]{
|
||||
new int[]{android.R.attr.state_enabled}, new int[]{-android.R.attr.state_enabled}
|
||||
}, new int[]{(isEnabledAccent || isEnabledMutedAccent) ? (isEnabledAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : enabled, (isDisabledAccent || isDisabledMutedAccent) ? (isDisabledAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : disabled});
|
||||
}
|
||||
|
||||
return csl;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package ru.vtosters.lite.themes.utils;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.DrawableContainer;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.RippleDrawable;
|
||||
import android.graphics.drawable.StateListDrawable;
|
||||
import android.os.Build;
|
||||
import android.widget.TextView;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class VkUiThemer {
|
||||
public static void autoThemeVkuiButtons(TextView view) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
|
||||
if (ThemesUtils.isDarkTheme())
|
||||
return; // no need to theme b/w buttons, well it should skip, but I do it for extra performance
|
||||
|
||||
try {
|
||||
if (!(view.getBackground() instanceof StateListDrawable)) return;
|
||||
|
||||
StateListDrawable states = ((StateListDrawable) view.getBackground());
|
||||
if (states.getConstantState() == null) return;
|
||||
DrawableContainer.DrawableContainerState dStates = (DrawableContainer.DrawableContainerState) states.getConstantState();
|
||||
|
||||
if (dStates.getChildCount() == 2) {
|
||||
Drawable target = dStates.getChildren()[0];
|
||||
if (!(target instanceof RippleDrawable)) return;
|
||||
|
||||
RippleDrawable ripple = (RippleDrawable) target;
|
||||
for (int i = 0; i < ripple.getNumberOfLayers(); i++) {
|
||||
if (ripple.getId(i) == android.R.id.mask) continue;
|
||||
|
||||
Drawable currentTarget = ripple.getDrawable(i);
|
||||
|
||||
if (!(currentTarget instanceof GradientDrawable)) continue;
|
||||
|
||||
//if (TSColorRefs.TS_DEBUG_MODE) Log.d("TSCore", "[tsh] finally, obamium = ["+currentTarget.toString()+"]");
|
||||
|
||||
GradientDrawable spd = (GradientDrawable) currentTarget;
|
||||
if (spd.getShape() != GradientDrawable.RECTANGLE) continue;
|
||||
|
||||
// Log.d("TSCore", "[tsh] got a color!");
|
||||
|
||||
ColorStateList csl = spd.getColor();
|
||||
// if (csl != null) {
|
||||
// Log.d("TSCore", "[tsh] csl2 <def: " + csl.getDefaultColor() + " = " + ThemesUtils.hex(csl.getDefaultColor()) + "> | " + csl);
|
||||
// }
|
||||
|
||||
if (ColorReferences.isAccentedColor(spd.getColor())) {
|
||||
// Log.d("TSCore", "[tsh] theming CSL");
|
||||
spd.setTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
Drawable draw2 = dStates.getChildren()[0];
|
||||
if (!(draw2 instanceof GradientDrawable)) return;
|
||||
GradientDrawable spd = (GradientDrawable) draw2;
|
||||
if (spd.getShape() != GradientDrawable.RECTANGLE) return;
|
||||
|
||||
// Log.d("TSCore", "[tsh:disabled] got a color!");
|
||||
|
||||
ColorStateList csl = spd.getColor();
|
||||
// if (csl != null) {
|
||||
// Log.d("TSCore", "[tsh:disabled] csl2 <def: " + csl.getDefaultColor() + " = " + ThemesUtils.hex(csl.getDefaultColor()) + "> | " + csl);
|
||||
// }
|
||||
|
||||
if (ColorReferences.isAccentedColor(spd.getColor())) {
|
||||
// Log.d("TSCore", "[tsh:disabled] theming CSL");
|
||||
spd.setTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(spd.getColor())) {
|
||||
// Log.d("TSCore", "[tsh:disabled] theming CSL");
|
||||
spd.setTint(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// This must go wrong, so we ignore any exceptions that may occur
|
||||
e.printStackTrace(); // REMOVE THIS!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,10 +16,11 @@ import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
|
||||
public class DeepLTranslator extends BaseTranslator {
|
||||
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
private static final OkHttpClient client = VtOkHttpClient.getInstance();
|
||||
private static final Pattern pattern = Pattern.compile("[i]");
|
||||
private static final String REQUEST_BODY_FORMAT = "{\n" +
|
||||
" \"method\": \"LMT_handle_texts\",\n" +
|
||||
|
||||
@@ -10,10 +10,11 @@ import java.net.URLEncoder;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
|
||||
public class GoogleTranslator extends BaseTranslator {
|
||||
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
private static final OkHttpClient client = VtOkHttpClient.getInstance();
|
||||
private static final String[] devices = new String[]{
|
||||
"Linux; U; Android 10; Pixel 4",
|
||||
"Linux; U; Android 10; Pixel 4 XL",
|
||||
|
||||
@@ -13,10 +13,11 @@ import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
|
||||
public class YandexTranslator extends BaseTranslator {
|
||||
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
private static final OkHttpClient client = VtOkHttpClient.getInstance();
|
||||
private static final String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||
|
||||
private static YandexTranslator instance;
|
||||
|
||||
@@ -1,30 +1,23 @@
|
||||
package ru.vtosters.lite.ui;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.ImageUtils.setTint;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getSTextAttr;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
import com.vtosters.lite.ui.MaterialSwitchPreference;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ImageUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class PreferencesUtil {
|
||||
|
||||
@@ -36,7 +29,7 @@ public class PreferencesUtil {
|
||||
CharSequence[] entries,
|
||||
CharSequence[] entriesValue
|
||||
) {
|
||||
ListPreference preference = new ListPreference(getGlobalContext());
|
||||
ListPreference preference = new ListPreference(fragment.requireContext());
|
||||
preference.setEntries(entries);
|
||||
preference.setEntryValues(entriesValue);
|
||||
preference.setTitle(title); // setTitle
|
||||
@@ -57,7 +50,7 @@ public class PreferencesUtil {
|
||||
CharSequence[] entriesValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
ListPreference preference = new ListPreference(getGlobalContext());
|
||||
ListPreference preference = new ListPreference(fragment.requireContext());
|
||||
preference.setEntries(entries);
|
||||
preference.setEntryValues(entriesValue);
|
||||
preference.setSummary(summary); // setSummary
|
||||
@@ -69,7 +62,7 @@ public class PreferencesUtil {
|
||||
preference.setOnPreferenceChangeListener(listener);
|
||||
|
||||
if (iconRes != 0)
|
||||
preference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
preference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
@@ -80,7 +73,7 @@ public class PreferencesUtil {
|
||||
CharSequence summary,
|
||||
boolean defValue
|
||||
) {
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(materialPreferenceToolbarFragment.requireContext());
|
||||
materialSwitchPreference.setTitle(title); // setTitle
|
||||
materialSwitchPreference.setSummary(summary); // setSummary
|
||||
materialSwitchPreference.setKey(key); // setKey
|
||||
@@ -98,7 +91,7 @@ public class PreferencesUtil {
|
||||
// boolean defValue,
|
||||
// Preference.OnPreferenceChangeListener listener
|
||||
// ) {
|
||||
// MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
// MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(fragment.requireContext());
|
||||
// materialSwitchPreference.setTitle(title); // setTitle
|
||||
// materialSwitchPreference.setSummary(summary); // setSummary
|
||||
// materialSwitchPreference.setKey(key); // setKey
|
||||
@@ -106,7 +99,7 @@ public class PreferencesUtil {
|
||||
// materialSwitchPreference.setOnPreferenceChangeListener(listener); // setOnPreferenceClickListener
|
||||
//
|
||||
// if (iconRes != 0)
|
||||
// materialSwitchPreference.setIcon(setTint(getGlobalContext(), Objects.requireNonNull(ContextCompat.getDrawable(getGlobalContext(), iconRes)))); // preference.setIcon
|
||||
// materialSwitchPreference.setIcon(setTint(fragment.requireContext(), Objects.requireNonNull(ContextCompat.getDrawable(fragment.requireContext(), iconRes)))); // preference.setIcon
|
||||
//
|
||||
// fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
// }
|
||||
@@ -120,7 +113,7 @@ public class PreferencesUtil {
|
||||
boolean defValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(fragment.requireContext());
|
||||
materialSwitchPreference.setTitle(title); // setTitle
|
||||
materialSwitchPreference.setSummary(summary); // setSummary
|
||||
materialSwitchPreference.setKey(key); // setKey
|
||||
@@ -128,7 +121,7 @@ public class PreferencesUtil {
|
||||
fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // materialPreferenceToolbarFragment.getPreferenceScreen().addPreference(preference)
|
||||
|
||||
if (iconRes != 0)
|
||||
materialSwitchPreference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
materialSwitchPreference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
materialSwitchPreference.setOnPreferenceChangeListener(listener); // setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
@@ -140,7 +133,7 @@ public class PreferencesUtil {
|
||||
CharSequence title,
|
||||
CharSequence summary
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
@@ -155,12 +148,12 @@ public class PreferencesUtil {
|
||||
int iconRes,
|
||||
Preference.OnPreferenceClickListener listener
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
|
||||
if (iconRes != 0)
|
||||
preference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
preference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
preference.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
@@ -173,13 +166,13 @@ public class PreferencesUtil {
|
||||
CharSequence summary,
|
||||
int iconRes,
|
||||
Preference.OnPreferenceClickListener listener) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
|
||||
if (iconRes != 0)
|
||||
preference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
preference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
preference.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
@@ -193,7 +186,7 @@ public class PreferencesUtil {
|
||||
@Nullable Drawable icon,
|
||||
Preference.OnPreferenceClickListener listener
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
@@ -206,37 +199,37 @@ public class PreferencesUtil {
|
||||
}
|
||||
|
||||
public static void addPreferenceCategory(MaterialPreferenceToolbarFragment fragment, CharSequence title) {
|
||||
PreferenceCategory preference = new PreferenceCategory(getGlobalContext(), null);
|
||||
PreferenceCategory preference = new PreferenceCategory(fragment.requireContext(), null);
|
||||
preference.setTitle(title); // setTitle
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreferenceCategory(MaterialPreferenceToolbarFragment fragment, CharSequence title, int collapsedSize) {
|
||||
PreferenceCategory preference = new PreferenceCategory(getGlobalContext(), null);
|
||||
PreferenceCategory preference = new PreferenceCategory(fragment.requireContext(), null);
|
||||
preference.setTitle(title); // setTitle
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addEditTextPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, EditTextPrefChangeListener editTextPrefChangeListener) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
preference.setOnPreferenceClickListener(preference1 -> {
|
||||
LinearLayout linearLayout = new LinearLayout(getGlobalContext());
|
||||
LinearLayout linearLayout = new LinearLayout(fragment.requireContext());
|
||||
|
||||
final EditText editText = new EditText(getGlobalContext());
|
||||
editText.setText(PreferenceManager.getDefaultSharedPreferences(getGlobalContext()).getString(key, ""));
|
||||
final EditText editText = new EditText(fragment.requireContext());
|
||||
editText.setText(PreferenceManager.getDefaultSharedPreferences(fragment.requireContext()).getString(key, ""));
|
||||
editText.setHint(title);
|
||||
editText.setTextColor(getTextAttr());
|
||||
editText.setHintTextColor(getSTextAttr());
|
||||
editText.setTextColor(ThemesUtils.getTextAttr());
|
||||
editText.setHintTextColor(ThemesUtils.getSTextAttr());
|
||||
|
||||
editText.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
editText.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
|
||||
linearLayout.addView(editText);
|
||||
editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) editText.getLayoutParams());
|
||||
margin.setMargins(dp2px(20f), 0, dp2px(20f), 0);
|
||||
margin.setMargins(AndroidUtils.dp2px(20f), 0, AndroidUtils.dp2px(20f), 0);
|
||||
editText.setLayoutParams(margin);
|
||||
|
||||
new VkAlertDialog.Builder(fragment.getContext())
|
||||
@@ -247,7 +240,7 @@ public class PreferencesUtil {
|
||||
if (!change)
|
||||
return;
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(getGlobalContext())
|
||||
PreferenceManager.getDefaultSharedPreferences(fragment.requireContext())
|
||||
.edit()
|
||||
.putString(key, editText.getText().toString())
|
||||
.apply();
|
||||
@@ -261,13 +254,13 @@ public class PreferencesUtil {
|
||||
|
||||
public static int getTextColor(Context ctx) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(getTextAttr(), typedValue, true);
|
||||
ctx.getTheme().resolveAttribute(ThemesUtils.getTextAttr(), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
public static int getSTextColor(Context ctx) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(getSTextAttr(), typedValue, true);
|
||||
ctx.getTheme().resolveAttribute(ThemesUtils.getSTextAttr(), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ public class APKInstallActivity extends AppCompatActivity {
|
||||
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, getString(R.string.apk_install_error) + " " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package ru.vtosters.lite.ui.adapters;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vk.core.drawable.BorderDrawable;
|
||||
import com.vk.core.util.Screen;
|
||||
import com.vk.stories.view.StoryCircleImageView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.themes.items.VTLColor;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter.ColorPickerViewHolder> {
|
||||
|
||||
private List<VTLColor> mColors;
|
||||
private OnColorSelectListener mSelectListener;
|
||||
|
||||
public ColorPickerAdapter(List<VTLColor> colors, OnColorSelectListener selectListener) {
|
||||
this.mColors = colors;
|
||||
this.mSelectListener = selectListener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ColorPickerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
var container = LayoutInflater.from(parent.getContext())
|
||||
.inflate(AndroidUtils.getIdentifier("color_picker_item", "layout"), parent, false);
|
||||
return new ColorPickerViewHolder(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ColorPickerViewHolder holder, int pos) {
|
||||
holder.bind(mColors.get(pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mColors.size();
|
||||
}
|
||||
|
||||
public class ColorPickerViewHolder extends RecyclerView.ViewHolder {
|
||||
private View mContainer;
|
||||
private FrameLayout mColorPreviewBorder;
|
||||
private StoryCircleImageView mColorPreview;
|
||||
private TextView mColorName;
|
||||
private TextView mColorValue;
|
||||
|
||||
public ColorPickerViewHolder(@NonNull View view) {
|
||||
super(view);
|
||||
|
||||
mContainer = view;
|
||||
mColorPreviewBorder = view.findViewById(AndroidUtils.getIdentifier("color_preview_border", "id"));
|
||||
mColorPreview = view.findViewById(AndroidUtils.getIdentifier("color_preview", "id"));
|
||||
mColorName = view.findViewById(AndroidUtils.getIdentifier("color_name", "id"));
|
||||
mColorValue = view.findViewById(AndroidUtils.getIdentifier("color_value", "id"));
|
||||
}
|
||||
|
||||
public void bind(VTLColor item) {
|
||||
mContainer.setOnClickListener(v -> mSelectListener.onColorSelected(ColorPickerAdapter.this, item));
|
||||
mColorPreviewBorder.setBackground(new BorderDrawable(ThemesUtils.isDarkTheme() ? Color.WHITE : Color.BLACK, Screen.c(24.0f), Screen.c(1.0f)));
|
||||
mColorPreview.setPlaceholderColor(item.color);
|
||||
mColorName.setText(item.resName);
|
||||
mColorValue.setText("#" + Integer.toHexString(item.color).toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnColorSelectListener {
|
||||
|
||||
void onColorSelected(ColorPickerAdapter adapter, VTLColor vtlcolor);
|
||||
}
|
||||
}
|
||||
@@ -97,8 +97,8 @@ public class ImagineArrayAdapter extends ArrayAdapter<ImagineArrayAdapter.Imagin
|
||||
.inflate(R.layout.select_dialog_singlechoice_material, parent, false);
|
||||
// for amoled
|
||||
var tintList = new ColorStateList(
|
||||
new int[][] { new int[] { android.R.attr.state_checked }, new int[] { -android.R.attr.state_checked }},
|
||||
new int[] { ThemesUtils.getAccentColor(), ThemesUtils.getSTextAttr() });
|
||||
new int[][]{new int[]{android.R.attr.state_checked}, new int[]{-android.R.attr.state_checked}},
|
||||
new int[]{ThemesUtils.getAccentColor(), ThemesUtils.getSTextAttr()});
|
||||
TextViewCompat.setCompoundDrawableTintList(checkedTextView, tintList);
|
||||
checkedTextView.setChecked(position == mSelectedIndex);
|
||||
container.addView(checkedTextView, LayoutUtils.createLinear(AndroidUtils.dp2px(50.0f), -2));
|
||||
|
||||
@@ -1,39 +1,41 @@
|
||||
package ru.vtosters.lite.ui.adapters;
|
||||
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.TypedValue;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vk.core.widget.BubbleFluidLayout;
|
||||
import com.vk.im.ui.components.viewcontrollers.msg_list.entry.MsgTextBuilder;
|
||||
import com.vk.im.ui.views.msg.MsgPartTextView;
|
||||
import com.vk.im.ui.views.msg.bubble.MsgBubbleDrawable;
|
||||
import com.vk.im.ui.views.msg.bubble.MsgBubblePart;
|
||||
import com.vk.im.ui.views.msg.bubble.MsgBubbleStyle;
|
||||
import com.vk.im.ui.views.msg.bubble.MsgBubbleView;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.m0.ToolbarHelper;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class MessagesPreviewAdapter extends RecyclerView.Adapter<MessagesPreviewAdapter.MessagePreviewViewHolder> {
|
||||
private static final int ME = 0x0;
|
||||
private static final int ANONYMOUS = -0x1;
|
||||
|
||||
private final String[] mMessages = AndroidUtils.getArray(R.array.wallpaper_change_dialog);
|
||||
private final String[] mMessages;
|
||||
|
||||
private static int getColorFromAttribute(Context context, int attrId) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
context.getTheme().resolveAttribute(attrId, typedValue, true);
|
||||
return typedValue.data;
|
||||
public MessagesPreviewAdapter(String... messages) {
|
||||
mMessages = messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int i) {
|
||||
return i % 2 == 0 ? ANONYMOUS : ME;
|
||||
return i % 2 == 0 ? Gravity.START : Gravity.END;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -41,7 +43,12 @@ public class MessagesPreviewAdapter extends RecyclerView.Adapter<MessagesPreview
|
||||
public MessagePreviewViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
||||
Context context = viewGroup.getContext();
|
||||
|
||||
var bubbleFluidLayout = (BubbleFluidLayout) LayoutInflater.from(context).inflate(R.layout.vkim_msg_list_item_msg_from_user, viewGroup, false);
|
||||
final var inflater = LayoutInflater.from(context);
|
||||
|
||||
final var bubbleFluidLayout = (BubbleFluidLayout) inflater
|
||||
.inflate(R.layout.vkim_msg_list_item_msg_from_user, viewGroup, false);
|
||||
bubbleFluidLayout.setPadding(0, AndroidUtils.dp2px(4), 0, 0);
|
||||
bubbleFluidLayout.setGravity(viewType);
|
||||
|
||||
bubbleFluidLayout.findViewById(R.id.avatar).setVisibility(View.GONE);
|
||||
bubbleFluidLayout.findViewById(R.id.avatar_space).setVisibility(View.GONE);
|
||||
@@ -49,19 +56,20 @@ public class MessagesPreviewAdapter extends RecyclerView.Adapter<MessagesPreview
|
||||
bubbleFluidLayout.findViewById(R.id.status).setVisibility(View.GONE);
|
||||
bubbleFluidLayout.findViewById(R.id.status_space).setVisibility(View.GONE);
|
||||
|
||||
var messageBubbleView = (MsgBubbleView) bubbleFluidLayout.findViewById(R.id.bubble);
|
||||
messageBubbleView.setContentPaddingLeft(AndroidUtils.dp2px(5));
|
||||
messageBubbleView.setContentPaddingTop(AndroidUtils.dp2px(5));
|
||||
messageBubbleView.setContentPaddingRight(AndroidUtils.dp2px(5));
|
||||
messageBubbleView.setContentPaddingBottom(AndroidUtils.dp2px(5));
|
||||
bubbleFluidLayout.setGravity(viewType == ME ? Gravity.RIGHT : Gravity.LEFT);
|
||||
final var messageBubbleView = (MsgBubbleView) bubbleFluidLayout.findViewById(R.id.bubble);
|
||||
messageBubbleView.setContentPaddingLeft(AndroidUtils.dp2px(10));
|
||||
messageBubbleView.setContentPaddingTop(AndroidUtils.dp2px(4));
|
||||
messageBubbleView.setContentPaddingRight(AndroidUtils.dp2px(4));
|
||||
messageBubbleView.setContentPaddingBottom(AndroidUtils.dp2px(0));
|
||||
if (viewType == Gravity.END)
|
||||
messageBubbleView.a(MsgBubbleStyle.b(false, false), MsgBubblePart.FULL, ThemesUtils.getAccentColor());
|
||||
bubbleFluidLayout.setLayoutDirection(viewType);
|
||||
|
||||
var message = new TextView(context);
|
||||
message.setTag("message");
|
||||
message.setGravity(Gravity.LEFT);
|
||||
message.setTextColor(getTextAttr());
|
||||
final var msgTextView = inflater.inflate(R.layout.vkim_msg_part_text, viewGroup, false);
|
||||
msgTextView.setId(R.id.msg_text);
|
||||
|
||||
messageBubbleView.setContentView(message);
|
||||
final var msgBubbleView = (MsgBubbleView) bubbleFluidLayout.findViewById(R.id.bubble);
|
||||
msgBubbleView.setContentView(msgTextView);
|
||||
|
||||
return new MessagePreviewViewHolder(bubbleFluidLayout);
|
||||
}
|
||||
@@ -77,17 +85,17 @@ public class MessagesPreviewAdapter extends RecyclerView.Adapter<MessagesPreview
|
||||
}
|
||||
|
||||
protected static class MessagePreviewViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private final TextView mMessage;
|
||||
private final MsgPartTextView mMsgTextView;
|
||||
|
||||
public MessagePreviewViewHolder(@NonNull View view) {
|
||||
super(view);
|
||||
|
||||
mMessage = view.findViewWithTag("message");
|
||||
mMsgTextView = view.findViewById(R.id.msg_text);
|
||||
}
|
||||
|
||||
public void bind(String text) {
|
||||
mMessage.setText(text);
|
||||
mMsgTextView.setText(new MsgTextBuilder().a(text));
|
||||
mMsgTextView.setTimeText("12:00");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ public class StickerPackAdapter extends RecyclerView.Adapter<StickerPackAdapter.
|
||||
var holder = new StickerPackViewHolder(view);
|
||||
|
||||
holder.mStickerPreview.setImageResource(R.drawable.icon_vk_104);
|
||||
holder.mUpdateButton.setImageDrawable(recolorDrawable(getResources().getDrawable(R.drawable.ic_camera_switch_48)));
|
||||
holder.mDeleteButton.setImageDrawable(recolorDrawable(getResources().getDrawable(R.drawable.vkim_ic_msg_delete)));
|
||||
holder.mUpdateButton.setImageDrawable(recolorDrawable(getResources().getDrawable(R.drawable.ic_camera_switch_outline_24)));
|
||||
holder.mDeleteButton.setImageDrawable(recolorDrawable(getResources().getDrawable(R.drawable.ic_delete_outline_28)));
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
package ru.vtosters.lite.ui.components;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPackageName;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.Preferences.hasVerification;
|
||||
import static ru.vtosters.lite.utils.Preferences.isValidSignature;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -44,11 +39,11 @@ public class IconManager {
|
||||
);
|
||||
|
||||
public static List<String> icons() {
|
||||
return hasVerification() && isValidSignature() ? sIconsPlusNames : sIconsNames; // delete later sdk check
|
||||
return Preferences.hasVerification() && Preferences.isValidSignature() ? sIconsPlusNames : sIconsNames; // delete later sdk check
|
||||
}
|
||||
|
||||
public static List<String> iconsValues() {
|
||||
return hasVerification() && isValidSignature() ? sIconsPlus : sIcons; // delete later sdk check
|
||||
return Preferences.hasVerification() && Preferences.isValidSignature() ? sIconsPlus : sIcons; // delete later sdk check
|
||||
}
|
||||
|
||||
public static void switchComponent(String icon, String appName, String oldIcon, String oldAppName) {
|
||||
@@ -64,7 +59,7 @@ public class IconManager {
|
||||
|
||||
Log.d("IconManager", "iconSwitcher: icon = " + icon + ", appname = " + appName);
|
||||
|
||||
List<String> iconsList = (hasVerification() && isValidSignature()) ? sIconsPlus : sIcons;
|
||||
List<String> iconsList = (Preferences.hasVerification() && Preferences.isValidSignature()) ? sIconsPlus : sIcons;
|
||||
List<String> labelsList = sLabels;
|
||||
|
||||
if (oldIcon != null && oldAppName != null) {
|
||||
@@ -82,10 +77,15 @@ public class IconManager {
|
||||
// get labels index
|
||||
labelIndex = labelsList.indexOf(appName);
|
||||
|
||||
String currentState = getPreferences().getString("components_enabled", "11");
|
||||
String currentState = "11";
|
||||
|
||||
if (oldIconIndex != -1 && oldLabelIndex != -1) {
|
||||
currentState = oldIconIndex + "" + oldLabelIndex;
|
||||
main: for (int i = 0; i < iconsList.size(); i++) {
|
||||
for (int o = 0; o < labelsList.size(); o++) {
|
||||
if (isComponentEnabled("id" + i + "" + o)) {
|
||||
currentState = i + "" + o;
|
||||
break main;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String newState = iconIndex + "" + labelIndex;
|
||||
@@ -96,17 +96,19 @@ public class IconManager {
|
||||
|
||||
// disable current component to prevent conflict with custom value
|
||||
switchIcon("id" + currentState, false);
|
||||
// save custom value
|
||||
edit().putString("components_enabled", newState).commit();
|
||||
// enable custom value
|
||||
switchIcon("id" + newState, true);
|
||||
}
|
||||
|
||||
// Component switcher for changing app icon
|
||||
public static void switchIcon(String componentName, Boolean enabled) {
|
||||
getGlobalContext().getPackageManager().setComponentEnabledSetting(
|
||||
new ComponentName(getPackageName(), getPackageName() + "." + componentName),
|
||||
AndroidUtils.getGlobalContext().getPackageManager().setComponentEnabledSetting(
|
||||
new ComponentName(AndroidUtils.getPackageName(), AndroidUtils.getPackageName() + "." + componentName),
|
||||
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
public static boolean isComponentEnabled(String componentName) {
|
||||
return AndroidUtils.getGlobalContext().getPackageManager().getComponentEnabledSetting(new ComponentName(AndroidUtils.getPackageName(), AndroidUtils.getPackageName() + "." + componentName)) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class NewsfeedListManager {
|
||||
sendToast(activity.getString(R.string.newsfeed_list_update_feed_to_work));
|
||||
}
|
||||
)
|
||||
));
|
||||
), "newsfeed_items_editor");
|
||||
}
|
||||
|
||||
public static void resetHideItems() {
|
||||
|
||||
@@ -2,18 +2,25 @@ package ru.vtosters.lite.ui.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.downloaders.OTADownloader;
|
||||
import ru.vtosters.lite.ui.vkui.ModalBottomSheetWrapper;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.OTAUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class OTADialog implements OTAUtils.OTAListener {
|
||||
public class OTADialog extends ModalBottomSheetWrapper<OTADialog> implements OTAUtils.OTAListener {
|
||||
private final Activity mActivity;
|
||||
|
||||
private final OTAUtils mHelper;
|
||||
|
||||
public OTADialog(Activity activity) {
|
||||
super(activity);
|
||||
mActivity = activity;
|
||||
|
||||
mHelper = new OTAUtils(this);
|
||||
@@ -28,20 +35,32 @@ public class OTADialog implements OTAUtils.OTAListener {
|
||||
public void onUpdateApplied() {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
// Toast.makeText(mActivity, "Обновления найдены", Toast.LENGTH_SHORT).show();
|
||||
new ModalBottomSheetWrapper(mActivity)
|
||||
.setTitle(mActivity.getString(R.string.newversion) + " " + mHelper.getNewVersionName())
|
||||
.setUpdateInfoView(mHelper.getUpdateDescription())
|
||||
.setPositiveButton(mActivity.getString(R.string.updateanddownload), () -> {
|
||||
OTADownloader.downloadBuild(mHelper.getDownloadUrl());
|
||||
})
|
||||
.show();
|
||||
setTitle(mActivity.getString(R.string.newversion) + " " + mHelper.getNewVersionName())
|
||||
.setView(makeUpdateInfoView(mHelper.getUpdateDescription()))
|
||||
.setPositiveButton(mActivity.getString(R.string.updateanddownload), () -> {
|
||||
OTADownloader.downloadBuild(mHelper.getDownloadUrl(), mHelper.getCommitSHA());
|
||||
})
|
||||
.show("ota");
|
||||
});
|
||||
}
|
||||
|
||||
private View makeUpdateInfoView(String changelog) {
|
||||
var container = new LinearLayout(mActivity);
|
||||
var changelogView = new TextView(mActivity);
|
||||
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
changelogView.setText("Изменения: \n" + changelog);
|
||||
changelogView.setTextColor(ThemesUtils.getTextAttr());
|
||||
container.addView(changelogView, new LinearLayout.LayoutParams(-1, -2));
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateCanceled() {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
// Toast.makeText(mActivity, "Обновлений не найдено", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
// mActivity.runOnUiThread(() -> {
|
||||
// // Toast.makeText(mActivity, "Обновлений не найдено", Toast.LENGTH_SHORT).show();
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package ru.vtosters.lite.ui.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import ru.vtosters.lite.themes.items.VTLPalette;
|
||||
import ru.vtosters.lite.ui.adapters.ColorPickerAdapter;
|
||||
|
||||
public class PalettesBottomSheetDialog {
|
||||
|
||||
private static final String TAG = "palettes_copy_color";
|
||||
|
||||
public static void create(Activity activity, VTLPalette palette, ColorPickerAdapter.OnColorSelectListener action) {
|
||||
var instance = new VTColorPickerBottomSheetDialog(activity);
|
||||
var colorPickerAdapter = new ColorPickerAdapter(palette.colors, (adapter, vtlcolor) -> {
|
||||
action.onColorSelected(adapter, vtlcolor);
|
||||
instance.dismiss();
|
||||
});
|
||||
instance.setTitle(palette.name)
|
||||
.setAdapter(colorPickerAdapter, true)
|
||||
.show(TAG, true);
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,11 @@ import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
|
||||
public class ServerDialog {
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
private static final OkHttpClient client = VtOkHttpClient.getInstance();
|
||||
public static Boolean showAlert;
|
||||
private static String title;
|
||||
private static String message;
|
||||
|
||||
@@ -28,10 +28,10 @@ public class Start {
|
||||
(dialogInterface, i) -> edit().putBoolean("showAlert", false).apply()
|
||||
)
|
||||
.setNeutralButton(R.string.startbtn1,
|
||||
(dialogInterface, i) -> {
|
||||
edit().putBoolean("showAlert", false).apply();
|
||||
activity.startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse("https://t.me/vtosters")));
|
||||
}
|
||||
(dialogInterface, i) -> {
|
||||
edit().putBoolean("showAlert", false).apply();
|
||||
activity.startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse("https://t.me/vtosters")));
|
||||
}
|
||||
)
|
||||
.show();
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package ru.vtosters.lite.ui.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import ru.vtosters.lite.ui.adapters.ColorPickerAdapter;
|
||||
import ru.vtosters.lite.ui.vkui.ModalBottomSheetWrapper;
|
||||
import ru.vtosters.lite.utils.LayoutUtils;
|
||||
|
||||
public class VTColorPickerBottomSheetDialog extends ModalBottomSheetWrapper<VTColorPickerBottomSheetDialog> {
|
||||
|
||||
private Activity mActivity;
|
||||
private LinearLayout mContainer;
|
||||
|
||||
public VTColorPickerBottomSheetDialog(Activity activity) {
|
||||
super(activity);
|
||||
this.mActivity = activity;
|
||||
mContainer = new LinearLayout(mActivity);
|
||||
mContainer.setLayoutParams(LayoutUtils.createLinear(-1, -1));
|
||||
mContainer.setOrientation(LinearLayout.VERTICAL);
|
||||
}
|
||||
|
||||
public VTColorPickerBottomSheetDialog setAdapter(ColorPickerAdapter adapter, boolean searchMode) {
|
||||
var recyclerView = new RecyclerView(mActivity);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
|
||||
var recyclerViewParams = LayoutUtils.createLinear(-1, -1);
|
||||
mContainer.addView(recyclerView, recyclerViewParams);
|
||||
|
||||
mBuilder.a(mContainer);
|
||||
return setView(mContainer);
|
||||
}
|
||||
|
||||
public LinearLayout getContainer() {
|
||||
return mContainer;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public abstract class BaseToolbarFragment extends FragmentImpl {
|
||||
private Toolbar mToolbar;
|
||||
private FrameLayout mContentLayout;
|
||||
|
||||
@CallSuper
|
||||
|
||||
protected void onCreateMenu(Menu menu) {
|
||||
if (menu.size() > 0)
|
||||
for (int i = 0; i < menu.size(); i++)
|
||||
@@ -63,6 +63,10 @@ public abstract class BaseToolbarFragment extends FragmentImpl {
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
public Toolbar getToolbar() {
|
||||
return mToolbar;
|
||||
}
|
||||
|
||||
public abstract View onCreateContent(@NonNull LayoutInflater inflater, @Nullable Bundle bundle);
|
||||
|
||||
private void initToolbar() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.themes.hooks.TextViewHook;
|
||||
import ru.vtosters.lite.ui.adapters.CategorizedAdapter;
|
||||
import ru.vtosters.lite.ui.components.DockBarEditorManager;
|
||||
import ru.vtosters.lite.ui.components.ItemMovingCallback;
|
||||
@@ -54,6 +55,8 @@ public class DockBarEditorFragment extends BaseToolbarFragment {
|
||||
restartApplication();
|
||||
});
|
||||
|
||||
new TextViewHook().inject(save, 0, false);
|
||||
|
||||
LinearLayout.LayoutParams saveParams = new LinearLayout.LayoutParams(0, -2);
|
||||
saveParams.weight = 1.0f;
|
||||
buttonsContainer.addView(save, saveParams);
|
||||
@@ -68,6 +71,8 @@ public class DockBarEditorFragment extends BaseToolbarFragment {
|
||||
restartApplication();
|
||||
});
|
||||
|
||||
new TextViewHook().inject(reset, 0, false);
|
||||
|
||||
LinearLayout.LayoutParams resetParams = new LinearLayout.LayoutParams(0, -2);
|
||||
resetParams.weight = 1.0f;
|
||||
buttonsContainer.addView(reset, resetParams);
|
||||
|
||||
@@ -132,6 +132,11 @@ public class FeedFragment extends MaterialPreferenceToolbarFragment {
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlfeed;
|
||||
}
|
||||
|
||||
public class openofficialsett implements Preference.OnPreferenceClickListener {
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
@@ -142,9 +147,4 @@ public class FeedFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlfeed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public class InterfaceFragment extends MaterialPreferenceToolbarFragment {
|
||||
findPreference("stories").setOnPreferenceClickListener(new restart());
|
||||
findPreference("swipe").setOnPreferenceClickListener(new restart());
|
||||
findPreference("is_likes_on_right").setOnPreferenceClickListener(new restart());
|
||||
findPreference("superapp").setOnPreferenceClickListener(new restart());
|
||||
|
||||
if (isTablet()) {
|
||||
findPreference("menusett").setVisible(false);
|
||||
@@ -53,15 +54,15 @@ public class InterfaceFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlinterface;
|
||||
}
|
||||
|
||||
public class restart implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
return InterfaceFragment.this.restart(preference);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlinterface;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplicationWithTimer;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.isEnableExternalOpening;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getSTextAttr;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
@@ -48,6 +50,7 @@ import ru.vtosters.lite.music.LastFMScrobbler;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.ui.adapters.ImagineArrayAdapter;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
private static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
@@ -55,7 +58,7 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
public static void download(Context ctx) {
|
||||
final EditText input = new EditText(ctx);
|
||||
input.setTextColor(getTextAttr());
|
||||
input.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
input.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
|
||||
var lp = new FrameLayout.LayoutParams(-1, -2);
|
||||
lp.leftMargin = AndroidUtils.dp2px(16);
|
||||
@@ -90,6 +93,12 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
prefs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
findPreference("maxquality").setEnabled(isEnableExternalOpening());
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
private void prefs() {
|
||||
findPreference("download_video").setOnPreferenceClickListener(new MediaFragment.download());
|
||||
findPreference("clearvideohistory").setOnPreferenceClickListener(preference -> {
|
||||
@@ -131,6 +140,12 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
findPreference("vkx_sett").setVisible(false);
|
||||
}
|
||||
|
||||
findPreference("musicdefcatalog").setVisible(!getBoolValue("useOldAppVer", false));
|
||||
findPreference("useOldAppVer").setOnPreferenceClickListener(preference -> {
|
||||
restartApplicationWithTimer();
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("select_photo_search_engine").setOnPreferenceClickListener(preference -> {
|
||||
var items = Arrays.asList(
|
||||
new ImagineArrayAdapter.ImagineArrayAdapterItem(R.drawable.yandex, "Yandex"),
|
||||
@@ -149,6 +164,8 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
.show();
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("maxquality").setEnabled(isEnableExternalOpening());
|
||||
}
|
||||
|
||||
private void lastfmAuth(Context ctx) {
|
||||
@@ -159,7 +176,7 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
fn.setHint(R.string.lastfm_login);
|
||||
fn.setTextColor(getTextAttr());
|
||||
fn.setHintTextColor(getSTextAttr());
|
||||
fn.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
fn.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
linearLayout.addView(fn);
|
||||
fn.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) fn.getLayoutParams());
|
||||
@@ -170,7 +187,7 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
ln.setHint(R.string.lastfm_password);
|
||||
ln.setTextColor(getTextAttr());
|
||||
ln.setHintTextColor(getSTextAttr());
|
||||
ln.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
ln.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
linearLayout.addView(ln);
|
||||
ln.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ln.setLayoutParams(margin);
|
||||
@@ -212,7 +229,7 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
private void dlaudio(Context ctx) {
|
||||
if (LibVKXClient.isIntegrationEnabled()) {
|
||||
sendToast("Включена интеграция VKX. Глобальное кеширование доступно внутри VKX");
|
||||
sendToast(AndroidUtils.getString("vkx_integration_enabled_info"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -269,6 +286,11 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlmedia;
|
||||
}
|
||||
|
||||
private static class restart implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
@@ -285,9 +307,4 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlmedia;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,14 @@ import static ru.vtosters.lite.utils.ThemesUtils.recolorDrawable;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.navigation.Navigator;
|
||||
import com.vk.stickers.Stickers;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
@@ -84,6 +86,11 @@ public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlmessages;
|
||||
}
|
||||
|
||||
public class restart implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
@@ -108,9 +115,4 @@ public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlmessages;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@ import static ru.vtosters.lite.ui.components.BackupManager.restoreBackup;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplication;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplicationWithTimer;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
@@ -23,10 +25,13 @@ import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
@@ -55,11 +60,13 @@ import java.io.IOException;
|
||||
import b.h.g.m.FileUtils;
|
||||
import ru.vtosters.lite.ui.activities.VKAdminTokenActivity;
|
||||
import ru.vtosters.lite.ui.components.BackupManager;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ContactsUtils;
|
||||
|
||||
public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
private static final int VK_ADMIN_TOKEN_REQUEST_CODE = 1;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
@@ -90,6 +97,11 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
cacheCleanDialog();
|
||||
return true;
|
||||
});
|
||||
findPreference("copyownlink").setOnPreferenceClickListener(preference -> {
|
||||
((ClipboardManager) requireContext().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", "https://vk.com/id" + AccountManagerUtils.getUserId()));
|
||||
ToastUtils.a(requireContext().getString(R.string.link_copied));
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("deviceinfo").setOnPreferenceClickListener(preference -> {
|
||||
Context context = requireContext();
|
||||
@@ -155,52 +167,25 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
@SuppressLint({"CommitPrefEdits", "SetTextI18n"})
|
||||
private void cacheAutoCleanDialog() {
|
||||
String[] cacheText = {null, "100 MB", "500 MB", "1 GB", "2 GB", "5 GB"};
|
||||
|
||||
var val = getDefaultPrefs().getInt("autoclearcache_size", 0);
|
||||
RadioGroup rg = new RadioGroup(getContext());
|
||||
|
||||
rg.setPadding(dp2px(18f), dp2px(12f), dp2px(18f), 0);
|
||||
|
||||
RadioButton zero = new RadioButton(new ContextThemeWrapper(getContext(), R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton one = new RadioButton(new ContextThemeWrapper(getContext(), R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton two = new RadioButton(new ContextThemeWrapper(getContext(), R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton three = new RadioButton(new ContextThemeWrapper(getContext(), R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton four = new RadioButton(new ContextThemeWrapper(getContext(), R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton five = new RadioButton(new ContextThemeWrapper(getContext(), R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
for (int item = 0; item <= 5; item++) {
|
||||
RadioButton rb = new RadioButton(new ContextThemeWrapper(getContext(), com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
rg.addView(rb);
|
||||
rb.setId(item);
|
||||
rb.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
|
||||
rg.addView(zero);
|
||||
rg.addView(one);
|
||||
rg.addView(two);
|
||||
rg.addView(three);
|
||||
rg.addView(four);
|
||||
rg.addView(five);
|
||||
var text = cacheText[item];
|
||||
rb.setText(text != null ? text : AndroidUtils.getString("autoclearcachedisabled"));
|
||||
|
||||
zero.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
one.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
two.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
three.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
four.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
five.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
|
||||
zero.setText(requireContext().getString(R.string.autoclearcachedisabled));
|
||||
one.setText("100 MB");
|
||||
two.setText("500 MB");
|
||||
three.setText("1 GB");
|
||||
four.setText("2 GB");
|
||||
five.setText("5 GB");
|
||||
|
||||
zero.setTextColor(getTextAttr());
|
||||
one.setTextColor(getTextAttr());
|
||||
two.setTextColor(getTextAttr());
|
||||
three.setTextColor(getTextAttr());
|
||||
four.setTextColor(getTextAttr());
|
||||
five.setTextColor(getTextAttr());
|
||||
|
||||
zero.setChecked(val == 0);
|
||||
one.setChecked(val == 1);
|
||||
two.setChecked(val == 2);
|
||||
three.setChecked(val == 3);
|
||||
four.setChecked(val == 4);
|
||||
five.setChecked(val == 5);
|
||||
rb.setTextColor(getTextAttr());
|
||||
rb.setChecked(val == item);
|
||||
}
|
||||
|
||||
new VkAlertDialog.Builder(getContext())
|
||||
.setTitle(requireContext().getString(R.string.cache_clean_title))
|
||||
@@ -209,7 +194,7 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
.setNegativeButton(requireContext().getString(R.string.cancel), null)
|
||||
.setView(rg)
|
||||
.setPositiveButton(requireContext().getString(R.string.save), (dialog, which) -> {
|
||||
var sizes = new String[] { "Default", "100mb", "500mb", "1gb", "2gb", "5gb" };
|
||||
var sizes = new String[]{"Default", "100mb", "500mb", "1gb", "2gb", "5gb"};
|
||||
var id = rg.getCheckedRadioButtonId();
|
||||
getDefaultPrefs().edit()
|
||||
.putInt("autoclearcache_size", id)
|
||||
@@ -273,7 +258,7 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
private void delprefs(Context context) {
|
||||
new VkAlertDialog.Builder(context)
|
||||
.setTitle(requireContext().getString(R.string.warning))
|
||||
.setTitle(requireContext().getString(R.string.warning))
|
||||
.setMessage(requireContext().getString(R.string.settings_reset_confirm))
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(requireContext().getString(R.string.yes), (dialogInterface, i) -> {
|
||||
@@ -284,6 +269,11 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlother;
|
||||
}
|
||||
|
||||
public static class d implements Preference.OnPreferenceClickListener {
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
@@ -346,8 +336,17 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
AndroidUtils.getGlobalContext().getSharedPreferences("gcm", 0).edit().clear().apply();
|
||||
OtherFragment.this.getListView().postDelayed(() -> {
|
||||
PushSubscriber.e.a(true);
|
||||
ToastUtils.a(requireContext().getString(R.string.fcmtokenget));
|
||||
ToastUtils.a(requireContext().getString(R.string.fcmtokenfixed));
|
||||
|
||||
Context ctx;
|
||||
|
||||
try {
|
||||
ctx = requireContext();
|
||||
} catch (Exception unused) {
|
||||
ctx = getGlobalContext();
|
||||
}
|
||||
|
||||
ToastUtils.a(ctx.getString(R.string.fcmtokenget));
|
||||
ToastUtils.a(ctx.getString(R.string.fcmtokenfixed));
|
||||
}, 1000);
|
||||
return true;
|
||||
}
|
||||
@@ -357,12 +356,20 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
var arr = BackupManager.getBackupsNames();
|
||||
var adapter = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1, arr);
|
||||
var adapter = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1, arr) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
TextView textView = (TextView) super.getView(position, convertView, parent);
|
||||
textView.setTextColor(getTextAttr());
|
||||
return textView;
|
||||
}
|
||||
};
|
||||
new VkAlertDialog.Builder(getContext())
|
||||
.setTitle(requireContext().getString(R.string.select_backup))
|
||||
.setAdapter(adapter, (dialog, which) -> {
|
||||
try {
|
||||
restoreBackup(arr[which]);
|
||||
restartApplicationWithTimer();
|
||||
Toast.makeText(getContext(), requireContext().getString(R.string.backup_success), LENGTH_LONG).show();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -373,9 +380,4 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlother;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user