Compare commits
264
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4cb73d669a | ||
|
|
dfddb13d2d | ||
|
|
f17c57bac2 | ||
|
|
a6c4c376c3 | ||
|
|
3e4f14678e | ||
|
|
f860eb2cc0 | ||
|
|
2a6b9da4ef | ||
|
|
6224a4afdf | ||
|
|
8650124860 | ||
|
|
5e35a61473 | ||
|
|
578f1a2221 | ||
|
|
0fb3ff6c53 | ||
|
|
7fbfbd1e1e | ||
|
|
71de558e5c | ||
|
|
606b89a4ec | ||
|
|
b4bdb3070a | ||
|
|
9f4b5990b7 | ||
|
|
93b28b0a8f | ||
|
|
ed0587b9b6 | ||
|
|
6ce72dfc8b | ||
|
|
65f44d32ca | ||
|
|
8e57d5ab44 | ||
|
|
c2b6bffb17 | ||
|
|
550fbf8f6c | ||
|
|
79d3287143 | ||
|
|
2242e37315 | ||
|
|
7099da0387 | ||
|
|
9b29288351 | ||
|
|
e000bd7971 | ||
|
|
8eb725148f | ||
|
|
af1d175415 | ||
|
|
92edbd4686 | ||
|
|
8d9812ebe0 | ||
|
|
33477e809c | ||
|
|
04f4f7d2ad | ||
|
|
80b8399cb8 | ||
|
|
483c9eda4d | ||
|
|
c76a7a5332 | ||
|
|
c470062d70 | ||
|
|
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 |
Binary file not shown.
|
After Width: | Height: | Size: 545 B |
Binary file not shown.
|
After Width: | Height: | Size: 819 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 730 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
@@ -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/`
|
||||
|
||||
+69
-3
@@ -1,3 +1,5 @@
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipFile
|
||||
import java.util.zip.ZipInputStream
|
||||
@@ -7,9 +9,15 @@ plugins {
|
||||
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 +77,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"
|
||||
@@ -94,3 +108,55 @@ dependencies {
|
||||
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'
|
||||
}
|
||||
}
|
||||
|
||||
task buildAndLaunchVTL(type: Exec) {
|
||||
dependsOn('buildAndInstallVTL')
|
||||
if (Os.isFamily("unix") || Os.isFamily("mac"))
|
||||
commandLine 'bash', '-c', 'adb shell monkey -p com.vtosters.lite -c android.intent.category.LAUNCHER 1'
|
||||
else
|
||||
commandLine 'adb', 'shell', 'monkey', '-p', 'com.vtosters.lite', '-c', 'android.intent.category.LAUNCHER', '1'
|
||||
}
|
||||
|
||||
exportDex.dependsOn('assembleRelease')
|
||||
clean.dependsOn('cleanVersionFile')
|
||||
versionFile.dependsOn('cleanVersionFile')
|
||||
preBuild.dependsOn('versionFile')
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package com.aefyr.tsg.g2;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.aefyr.tsg.g2.sql.TelegramStickersDbHelper;
|
||||
import com.aefyr.tsg.g2.stickersgrabber.TelegramStickersGrabber;
|
||||
import com.aefyr.tsg.g2.stickersgrabber.TelegramStickersPackInfo;
|
||||
import ru.vtosters.lite.ui.fragments.tgstickers.StickersFragment;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -19,7 +17,7 @@ import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import ru.vtosters.lite.ui.fragments.tgstickers.StickersFragment;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
/**
|
||||
* Created by Aefyr on 19.05.2018.
|
||||
@@ -227,6 +225,7 @@ public class TelegramStickersService {
|
||||
currentlyDownloading.add(id.toLowerCase());
|
||||
notificationsHelper.packStartedDownloading(newPack);
|
||||
|
||||
|
||||
grabber.enableProxy();
|
||||
grabber.grabPack(id, packFolder, pack.version, new TelegramStickersGrabber.PackDownloadListener() {
|
||||
@Override
|
||||
@@ -383,7 +382,7 @@ public class TelegramStickersService {
|
||||
getPacksListReference().set(li1, p2);
|
||||
}
|
||||
|
||||
interface StickersEventsListener {
|
||||
public interface StickersEventsListener {
|
||||
void onPackAdded(TelegramStickersPack pack, int atIndex);
|
||||
|
||||
void onPackRemoved(TelegramStickersPack pack, int atIndex);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -191,7 +191,7 @@ public class DownloadUtils {
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
}
|
||||
Intent intent = new Intent("android.intent.action.VIEW");
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
var mimeType = FileUtils.f(file);
|
||||
var uri = FileUtils.uriFromFile(file);
|
||||
@@ -222,7 +222,7 @@ public class DownloadUtils {
|
||||
var mimeType = FileUtils.f(file);
|
||||
var uri = FileUtils.uriFromFile(file);
|
||||
|
||||
Intent intent = new Intent("android.intent.action.VIEW");
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, mimeType);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Log.d("DownloadUtils", "openFile: " + file.getAbsolutePath() + "| mimetype " + mimeType + "| uri " + uri);
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
package com.vk.stickers.details;
|
||||
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.vk.core.ui.themes.VKThemeHelper;
|
||||
import com.vk.core.util.Screen;
|
||||
import com.vk.dto.stickers.StickerItem;
|
||||
import com.vk.dto.stickers.StickerStockItem;
|
||||
import com.vk.extensions.ViewExtKt;
|
||||
import com.vk.imageloader.view.VKImageView;
|
||||
import com.vk.stickers.views.VKStickerImageView;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class StickerDetailsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private final List<StickerItem> mItems;
|
||||
|
||||
private final StickerStockItem mItem;
|
||||
private boolean mIsTelegramPack = false;
|
||||
|
||||
public StickerDetailsAdapter(StickerStockItem stickerStockItem) {
|
||||
this.mItem = stickerStockItem;
|
||||
this.mItems = this.mItem.T1();
|
||||
}
|
||||
|
||||
public void setTelegramPack(boolean state) {
|
||||
mIsTelegramPack = state;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return new c(viewGroup);
|
||||
case 1:
|
||||
return new d(viewGroup);
|
||||
case 2:
|
||||
return new b(viewGroup);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown viewType: " + i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
||||
switch(getItemViewType(i)) {
|
||||
case 0:
|
||||
((c) viewHolder).a(this.mItem);
|
||||
break;
|
||||
case 1:
|
||||
((d) viewHolder).a(this.mItems.get(H(i)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mIsTelegramPack ? mItems.size() : this.mItems.size() + 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int i) {
|
||||
if (mIsTelegramPack) return 1;
|
||||
if (i == 0) {
|
||||
return 0;
|
||||
}
|
||||
return i == k() ? 2 : 1;
|
||||
}
|
||||
|
||||
public int H(int i) {
|
||||
return mIsTelegramPack ? i : i - j();
|
||||
}
|
||||
|
||||
public boolean I(int i) {
|
||||
return getItemViewType(i) == 1;
|
||||
}
|
||||
|
||||
public int j() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int k() {
|
||||
return l() + 1;
|
||||
}
|
||||
|
||||
public int l() {
|
||||
return (this.mItems.size() + j()) - 1;
|
||||
}
|
||||
|
||||
public int m() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public List<StickerItem> n() {
|
||||
return this.mItems;
|
||||
}
|
||||
|
||||
public boolean v() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final class b extends RecyclerView.ViewHolder {
|
||||
public b(ViewGroup viewGroup) {
|
||||
super(ViewExtKt.a(viewGroup, R.layout.sticker_details_hold_to_view_item, false));
|
||||
}
|
||||
}
|
||||
|
||||
private final class c extends RecyclerView.ViewHolder {
|
||||
private final VKImageView mImageBg;
|
||||
private final VKImageView mPackImage;
|
||||
private final ImageView mAnimPack;
|
||||
private final TextView mPackTitle;
|
||||
private final TextView mPackAuthor;
|
||||
private final TextView mPackSubtitle;
|
||||
private final TextView mDescription;
|
||||
|
||||
public c(ViewGroup viewGroup) {
|
||||
super(LayoutInflater.from(VKThemeHelper.u()).inflate(R.layout.sticker_details_info_item, viewGroup, false));
|
||||
this.mImageBg = this.itemView.findViewById(R.id.pack_image_bg);
|
||||
this.mPackImage = this.itemView.findViewById(R.id.pack_image);
|
||||
this.mAnimPack = this.itemView.findViewById(R.id.anim_pack);
|
||||
this.mPackTitle = this.itemView.findViewById(R.id.pack_title);
|
||||
this.mPackAuthor = this.itemView.findViewById(R.id.pack_author);
|
||||
this.mPackSubtitle = this.itemView.findViewById(R.id.pack_subtitle);
|
||||
this.mDescription = this.itemView.findViewById(R.id.description);
|
||||
}
|
||||
|
||||
public void a(StickerStockItem stickerStockItem) {
|
||||
this.mImageBg.a(stickerStockItem.R1());
|
||||
this.mImageBg.getHierarchy().a().setVisible(true, true);
|
||||
this.mImageBg.getHierarchy().a(0);
|
||||
this.mImageBg.getHierarchy().e(new ColorDrawable(VKThemeHelper.d(R.attr.placeholder_icon_background)));
|
||||
|
||||
this.mPackImage.a(stickerStockItem.h(Screen.a(68)));
|
||||
this.mPackImage.getHierarchy().a().setVisible(true, true);
|
||||
this.mPackImage.getHierarchy().a(0);
|
||||
|
||||
if (stickerStockItem.E1()) {
|
||||
ViewExtKt.r(this.mAnimPack);
|
||||
} else {
|
||||
ViewExtKt.p(this.mAnimPack);
|
||||
}
|
||||
|
||||
this.mPackTitle.setText(stickerStockItem.getTitle());
|
||||
|
||||
this.mPackAuthor.setText(stickerStockItem.v1());
|
||||
|
||||
ViewExtKt.p(this.mPackSubtitle);
|
||||
|
||||
this.mDescription.setText(stickerStockItem.C1());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class d extends RecyclerView.ViewHolder {
|
||||
private final VKStickerImageView mImage;
|
||||
|
||||
public d(ViewGroup viewGroup) {
|
||||
super(new VKStickerImageView(viewGroup.getContext()));
|
||||
this.mImage = (VKStickerImageView) itemView;
|
||||
this.mImage.setAspectRatio(1.0f);
|
||||
this.mImage.setClickable(true);
|
||||
this.mImage.getHierarchy().a().setVisible(true, true);
|
||||
this.mImage.getHierarchy().a(0);
|
||||
this.mImage.setContentDescription(this.mImage.getContext().getString(R.string.stickers_accessibility_sticker));
|
||||
}
|
||||
|
||||
public void a(StickerItem stickerItem) {
|
||||
this.mImage.a(stickerItem.h(Screen.a(80)));
|
||||
this.mImage.setTag(R.id.id, stickerItem.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
+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")
|
||||
|
||||
@@ -25,14 +25,15 @@ public class VTExecutors {
|
||||
}
|
||||
|
||||
static class VTMusicDownloadExecutor {
|
||||
private VTMusicDownloadExecutor() {}
|
||||
|
||||
private static class LazyHolder {
|
||||
public static final ExecutorService INSTANCE = Executors.newSingleThreadExecutor();
|
||||
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() {
|
||||
|
||||
@@ -3,11 +3,11 @@ package ru.vtosters.lite.di.singleton;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class VtOkHttpClient extends OkHttpClient {
|
||||
private static class LazyHolder {
|
||||
private static final VtOkHttpClient instance = new VtOkHttpClient();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -23,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;
|
||||
|
||||
/**
|
||||
@@ -63,6 +64,7 @@ public class AudioDownloader {
|
||||
|
||||
if (CacheDatabaseDelegate.isCached(trackId)) {
|
||||
CacheDatabaseDelegate.removeTrackFromCache(LibVKXClient.asId(track));
|
||||
AndroidUtils.sendToast(AndroidUtils.getString("audio_deleted_from_cache"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class OTADownloader {
|
||||
|
||||
var request = new DownloadManager.Request(uri);
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setTitle("Скачивание обновления");
|
||||
request.setTitle(AndroidUtils.getString("downloading_update"));
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "VTLite-" + commitSHA + ".apk");
|
||||
|
||||
var manager = (DownloadManager) AndroidUtils.getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
|
||||
@@ -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,38 +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 static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
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 ru.vtosters.lite.utils.LifecycleUtils;
|
||||
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;
|
||||
@@ -60,76 +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()];
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
max[i] = list.get(i);
|
||||
}
|
||||
|
||||
if (context == null) context = LifecycleUtils.getCurrentActivity();
|
||||
|
||||
var adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_1, max) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
TextView textView = (TextView) super.getView(position, convertView, parent);
|
||||
textView.setTextColor(getTextAttr());
|
||||
return textView;
|
||||
}
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
new VkAlertDialog.Builder(context)
|
||||
new VkAlertDialog.Builder(finalContext)
|
||||
.setAdapter(adapter, (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) getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class EncryptProvider {
|
||||
public static CharSequence decryptMessage(CharSequence msgBody, MsgFromUser msgFromUser, boolean showEmoji) {
|
||||
try {
|
||||
return decryptMessage((String) msgBody, msgFromUser.v1(), showEmoji);
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
return decryptMessage((String) msgBody, 0, showEmoji);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,162 +34,6 @@ import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class JsonInjectors {
|
||||
private static final OkHttpClient mClient = VtOkHttpClient.getInstance();
|
||||
|
||||
public static JSONObject profileButton(JSONObject orig) throws JSONException {
|
||||
var id = orig.getInt("id");
|
||||
|
||||
var newItem = new JSONArray();
|
||||
|
||||
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);
|
||||
|
||||
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";
|
||||
|
||||
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);
|
||||
|
||||
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 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);
|
||||
|
||||
json.put("icons", icons);
|
||||
|
||||
json.put("text_color", text_color);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
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 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);
|
||||
|
||||
json.put("icons", icons);
|
||||
|
||||
json.put("text_color", text_color);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSONObject convBar(JSONObject orig) throws JSONException {
|
||||
var peerid = Objects.requireNonNull(orig.optJSONObject("peer")).optInt("id");
|
||||
|
||||
var pic = "https://image.pngaaa.com/641/326641-middle.png"; // can be null
|
||||
var text = AndroidUtils.getString(R.string.no_data_error);
|
||||
var link = "https://vtosters.app"; // can be null
|
||||
var linktitle = "Test button"; // can be null
|
||||
|
||||
var hasIcon = !pic.isEmpty();
|
||||
var hasButton = !link.isEmpty();
|
||||
|
||||
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 (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);
|
||||
|
||||
if (!isVerified(peerid) || text.equals("") || peerid == AccountManagerUtils.getUserId() || peerid == 0) {
|
||||
if (getBoolValue("convBarRecomm", false)) {
|
||||
return null;
|
||||
} else {
|
||||
return orig.optJSONObject("conversation_bar");
|
||||
}
|
||||
}
|
||||
|
||||
if (!dev()) return orig.optJSONObject("conversation_bar"); // for devs only
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSONObject menu(JSONObject orig) throws JSONException {
|
||||
var Special = orig.optJSONArray("special");
|
||||
var Main = orig.getJSONArray("main");
|
||||
@@ -232,7 +76,6 @@ public class JsonInjectors {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static JSONObject setOnlineInfo(JSONObject json) throws JSONException {
|
||||
var id = json.optInt("id");
|
||||
if (id == AccountManagerUtils.getUserId()) {
|
||||
@@ -410,8 +253,4 @@ public class JsonInjectors {
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static boolean haveDonateButton() {
|
||||
return hasVerification() || new Random().nextInt(6) != 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,14 @@ 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 ru.vtosters.lite.downloaders.notifications.NotificationChannels;
|
||||
import ru.vtosters.lite.concurrent.VTExecutors;
|
||||
import ru.vtosters.lite.downloaders.notifications.NotificationChannels;
|
||||
import ru.vtosters.lite.ssfs.UsersList;
|
||||
import ru.vtosters.lite.ui.dialogs.DisableBattery;
|
||||
import ru.vtosters.lite.ui.dialogs.InstallGMS;
|
||||
import ru.vtosters.lite.ui.dialogs.OTADialog;
|
||||
@@ -23,6 +22,7 @@ public class MainActivityInjector {
|
||||
public static void inject(Activity activity) {
|
||||
setNeededTheme(activity);
|
||||
sendRequest();
|
||||
UsersList.getUsersList();
|
||||
if (checkupdates()) OTADialog.checkUpdates(activity);
|
||||
VTExecutors.getIoScheduler().a(DeletedMessagesHandler::reloadMessagesList); // ioScheduler
|
||||
Start.alert(activity);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
@@ -17,7 +16,9 @@ import android.widget.Toast;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.vk.core.dialogs.actionspopup.ActionsPopup;
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
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;
|
||||
@@ -39,7 +40,7 @@ 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;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
|
||||
public class PhotoViewer {
|
||||
static OkHttpClient client = VtOkHttpClient.getInstance();
|
||||
@@ -47,12 +48,12 @@ public class PhotoViewer {
|
||||
public static boolean interceptClick(AttachmentWithMedia attachment, MenuItem item, View view) {
|
||||
if (item.getItemId() == R.id.search_photo) {
|
||||
if (attachment instanceof PhotoAttachment) {
|
||||
searchPhoto(getUrlFromPhotoAttachment((PhotoAttachment) attachment));
|
||||
searchDialog(LifecycleUtils.getCurrentActivity(), getUrlFromPhotoAttachment((PhotoAttachment) attachment));
|
||||
} else if (attachment instanceof DocumentAttachment) {
|
||||
var documentAttachment = (DocumentAttachment) attachment;
|
||||
if (documentAttachment.J != null)
|
||||
try {
|
||||
searchPhoto(getUrlFromDocumentAttachment(documentAttachment));
|
||||
searchDialog(LifecycleUtils.getCurrentActivity(), getUrlFromDocumentAttachment(documentAttachment));
|
||||
} catch (Exception e) {
|
||||
ToastUtils.a(R.string.photo_get_error);
|
||||
}
|
||||
@@ -97,18 +98,16 @@ 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) {
|
||||
searchPhoto(getUrlFromPhotoAttachment((PhotoAttachment) attachment));
|
||||
searchDialog(LifecycleUtils.getCurrentActivity(), getUrlFromPhotoAttachment((PhotoAttachment) attachment));
|
||||
} else if (attachment instanceof DocumentAttachment) {
|
||||
var documentAttachment = (DocumentAttachment) attachment;
|
||||
if (documentAttachment.J != null)
|
||||
try {
|
||||
searchPhoto(getUrlFromDocumentAttachment(documentAttachment));
|
||||
searchDialog(LifecycleUtils.getCurrentActivity(), getUrlFromDocumentAttachment(documentAttachment));
|
||||
} catch (Exception e) {
|
||||
ToastUtils.a(R.string.photo_get_error);
|
||||
}
|
||||
@@ -119,9 +118,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) {
|
||||
@@ -141,10 +138,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) {
|
||||
@@ -192,21 +186,58 @@ public class PhotoViewer {
|
||||
return max.url;
|
||||
}
|
||||
|
||||
private static void searchPhoto(String url) {
|
||||
if (url == null || url.isEmpty()) return;
|
||||
switch (getPreferences().getInt("search_engine", 0)) {
|
||||
case 0:
|
||||
private static void searchDialog(Context context, String url) {
|
||||
if (selectedEngine() == 0) {
|
||||
var items = new String[]{
|
||||
"Yandex", "Google", "Bing", "TraceMoe", "Ascii2d", "Saucenao"
|
||||
};
|
||||
|
||||
new VkAlertDialog.Builder(context)
|
||||
.setItems(items, (dl, i) -> {
|
||||
searchPhoto(i + 1, url);
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
searchPhoto(selectedEngine(), url);
|
||||
}
|
||||
}
|
||||
|
||||
private static int selectedEngine() {
|
||||
return getPreferences().getInt("search_engine", 0);
|
||||
}
|
||||
|
||||
private static void searchPhoto(int i, String url) {
|
||||
if (url == null || url.isEmpty()) {
|
||||
Log.d("PhotoViewer", "url is null or empty");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (i) {
|
||||
case 1:
|
||||
searchWithYandex(url);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
searchWithGoogle(url);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
searchWithBing(url);
|
||||
break;
|
||||
case 4:
|
||||
searchWithTraceMoe(url);
|
||||
break;
|
||||
case 5:
|
||||
searchWithAscii2d(url);
|
||||
break;
|
||||
case 6:
|
||||
searchWithSaucenao(url);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void searchPhoto(String url) {
|
||||
searchPhoto(selectedEngine(), url);
|
||||
}
|
||||
|
||||
private static void searchWithYandex(String url) {
|
||||
var request = new Request.a()
|
||||
.b(String.format("https://yandex.ru/images-apphost/image-download?url=%s&images_avatars_size=preview&images_avatars_namespace=images-cbir",
|
||||
@@ -234,8 +265,19 @@ 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 searchWithTraceMoe(String url) {
|
||||
openUrl("https://trace.moe/?url=" + URLEncoder.encode(url));
|
||||
}
|
||||
|
||||
private static void searchWithAscii2d(String url) {
|
||||
openUrl("https://ascii2d.net/search/url/" + URLEncoder.encode(url));
|
||||
}
|
||||
|
||||
private static void searchWithSaucenao(String url) {
|
||||
openUrl("https://saucenao.com/search.php?url=" + URLEncoder.encode(url));
|
||||
}
|
||||
|
||||
private static void searchWithBing(String url) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package ru.vtosters.lite.hooks;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
public class PromoStickersHook {
|
||||
public static String hook(){
|
||||
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) {
|
||||
|
||||
@@ -56,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);
|
||||
@@ -101,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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -25,9 +25,8 @@ import ru.vtosters.lite.music.cache.helpers.PlaylistHelper;
|
||||
import ru.vtosters.lite.music.cache.helpers.TracklistHelper;
|
||||
|
||||
public class PlaylistInjector {
|
||||
private static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
public final static String CHANNEL_NAME = "VTCH";
|
||||
private static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
public static void injectDownloadPlaylist(Playlist playlist) {
|
||||
executor.submit(() -> AudioDownloader.cachePlaylist(playlist));
|
||||
|
||||
@@ -9,7 +9,6 @@ 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 static ru.vtosters.lite.utils.Preferences.podcastcatalog;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
@@ -46,7 +45,7 @@ public class CatalogJsonInjector {
|
||||
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) {
|
||||
if (isUsersCatalog) {
|
||||
var blocks = oldItems.optJSONObject(0).optJSONArray("blocks");
|
||||
|
||||
if (!useOldAppVer) {
|
||||
@@ -94,19 +93,6 @@ public class CatalogJsonInjector {
|
||||
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");
|
||||
|
||||
@@ -58,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("\"");
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ru.vtosters.lite.feature.music;
|
||||
package ru.vtosters.lite.music.hook;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
+21
-4
@@ -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;
|
||||
@@ -22,6 +22,8 @@ import java.util.ArrayList;
|
||||
|
||||
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 {
|
||||
public static ArrayList<MusicAction> hook(ArrayList<MusicAction> actions, MusicTrack musicTrack) {
|
||||
@@ -36,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()) {
|
||||
@@ -85,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());
|
||||
}
|
||||
|
||||
@@ -121,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 -> {
|
||||
@@ -29,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,39 @@
|
||||
package ru.vtosters.lite.ssfs;
|
||||
|
||||
import android.util.Log;
|
||||
import okhttp3.Request;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Handler {
|
||||
private static final String TAG = "SSFSHandler";
|
||||
|
||||
public static JSONObject getBanner(int id) {
|
||||
Request request = new Request.a()
|
||||
.b(Utils.getDomain() + "/api/getChatBanner" + "?user_id=" + id)
|
||||
.a();
|
||||
|
||||
try {
|
||||
return new JSONObject(VtOkHttpClient.getInstance().a(request).execute().a().g()).getJSONObject("response");
|
||||
} catch (JSONException | IOException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDescription(int id) {
|
||||
Request request = new Request.a()
|
||||
.b(Utils.getDomain() + "/api/getServiceDescription" + "?user_id=" + id)
|
||||
.a();
|
||||
|
||||
try {
|
||||
return new JSONObject(VtOkHttpClient.getInstance().a(request).execute().a().g()).getString("response");
|
||||
} catch (JSONException | IOException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package ru.vtosters.lite.ssfs;
|
||||
|
||||
import android.util.Log;
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
public class ImBanner {
|
||||
private static final String TAG = "ImBanner";
|
||||
|
||||
public static JSONObject convBar(JSONObject orig) throws JSONException {
|
||||
var user_id = orig.getJSONObject("peer").getInt("id");
|
||||
|
||||
if (!UsersList.hasBanner(user_id) || user_id == 0) {
|
||||
if (getBoolValue("convBarRecomm", false)) {
|
||||
return null;
|
||||
} else {
|
||||
return orig.optJSONObject("conversation_bar");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
var jsonBanner = Handler.getBanner(user_id);
|
||||
var pic = jsonBanner.optString("picture");
|
||||
var text = jsonBanner.getString("text");
|
||||
|
||||
var link = jsonBanner.optString("link");
|
||||
var link_text = jsonBanner.optString("link_text");
|
||||
|
||||
var hasIcon = !pic.isEmpty();
|
||||
var hasButton = !link.isEmpty();
|
||||
var isPicture = pic.endsWith(".png") || pic.endsWith(".jpg") || pic.endsWith(".jpeg") || pic.endsWith(".webp");
|
||||
|
||||
var json = new JSONObject();
|
||||
|
||||
var buttonsJson = new JSONObject();
|
||||
buttonsJson.put("layout", "tertiary");
|
||||
buttonsJson.put("text", link_text);
|
||||
buttonsJson.put("type", "link");
|
||||
buttonsJson.put("link", link);
|
||||
|
||||
var buttons = new JSONArray(); // max 3 buttons in array
|
||||
|
||||
if (hasButton) buttons.put(buttonsJson);
|
||||
|
||||
json.put("name", "group_admin_welcome");
|
||||
json.put("text", text);
|
||||
json.put("buttons", buttons);
|
||||
|
||||
if (hasIcon && isPicture) {
|
||||
json.put("icon", pic);
|
||||
}
|
||||
|
||||
return json;
|
||||
} catch (JSONException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean showAlert() {
|
||||
var context = LifecycleUtils.getCurrentActivity();
|
||||
var bool = Preferences.getBoolValue("linkalert", false);
|
||||
|
||||
if (!bool) {
|
||||
new VkAlertDialog.Builder(context)
|
||||
.setTitle("Внимание!")
|
||||
.setMessage("Разработчики клиента не несут никакой ответственности за пользовательские ссылки. Будьте внимательны!")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("Продолжить", (dialogInterface, i) -> {
|
||||
Preferences.preferences.edit().putBoolean("linkalert", true).commit();
|
||||
})
|
||||
.setNeutralButton("Отмена", (dialogInterface, i) -> {
|
||||
dialogInterface.cancel();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
return bool;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package ru.vtosters.lite.ssfs;
|
||||
|
||||
import android.util.Log;
|
||||
import com.vk.core.util.LangUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.VTVerifications;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getStatic;
|
||||
|
||||
public class ProfileButtons {
|
||||
private static final String TAG = "ProfileButtons";
|
||||
|
||||
public static JSONObject profileButton(JSONObject orig) {
|
||||
try {
|
||||
int id = orig.getInt("id");
|
||||
|
||||
var newItem = new JSONArray();
|
||||
|
||||
if (orig.has("buttons")) {
|
||||
newItem = orig.getJSONArray("buttons");
|
||||
}
|
||||
|
||||
if (!VTVerifications.haveDonateButton() && id == AccountManagerUtils.getUserId()) {
|
||||
var map = new HashMap<>();
|
||||
map.put("20", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/donate_icon/20.png");
|
||||
map.put("40", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/donate_icon/40.png");
|
||||
map.put("80", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/donate_icon/80.png");
|
||||
|
||||
newItem.put(generateJsonObject(
|
||||
AndroidUtils.getString(com.vtosters.lite.R.string.donate_to_vtl),
|
||||
"https://vk.com/vtosters_official",
|
||||
"2D81E0",
|
||||
"open_url",
|
||||
map
|
||||
));
|
||||
}
|
||||
|
||||
if (!orig.has("type") && AccountManagerUtils.isVKTester()) {
|
||||
var map = new HashMap<>();
|
||||
map.put("20", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/bug_icon/20.png");
|
||||
map.put("40", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/bug_icon/40.png");
|
||||
map.put("80", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/bug_icon/80.png");
|
||||
|
||||
newItem.put(generateJsonObject(
|
||||
AndroidUtils.getString(com.vtosters.lite.R.string.tester_profile),
|
||||
"https://" + getStatic() + "/bugs?lang=" + LangUtils.a() + "#/reporter" + id,
|
||||
"2D81E0",
|
||||
"open_internal_vkui",
|
||||
map
|
||||
));
|
||||
}
|
||||
|
||||
orig.put("buttons", newItem);
|
||||
} catch (JSONException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
}
|
||||
|
||||
return orig;
|
||||
}
|
||||
|
||||
public static JSONObject generateJsonObject(String title, String link, String text_color, String url_type, HashMap<Object, Object> iconsList) {
|
||||
try {
|
||||
var json = new JSONObject();
|
||||
var icons = new JSONArray();
|
||||
|
||||
var action = new JSONObject().put("target", "internal");
|
||||
action.put("type", url_type); // 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);
|
||||
|
||||
for (var entry : iconsList.entrySet()) {
|
||||
var icon = new JSONObject();
|
||||
icon.put("url", entry.getValue());
|
||||
icon.put("width", entry.getKey());
|
||||
icon.put("height", entry.getKey());
|
||||
icons.put(icon);
|
||||
}
|
||||
|
||||
json.put("icons", icons);
|
||||
|
||||
json.put("text_color", text_color);
|
||||
|
||||
return json;
|
||||
} catch (JSONException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package ru.vtosters.lite.ssfs;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.vk.profile.presenter.UserPresenter;
|
||||
import com.vtosters.lite.api.ExtendedUserProfile;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserID;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
public class ProfileHider {
|
||||
private static final String TAG = "ProfileHider";
|
||||
|
||||
public static boolean isService(Integer id) {
|
||||
return UsersList.hasDescription(id) || id == 100 || id == 101 || id == 333;
|
||||
}
|
||||
|
||||
public static void fetchInfo(ExtendedUserProfile extendedUserProfile, JSONObject jsonObject) {
|
||||
int userID = getUserID(extendedUserProfile);
|
||||
|
||||
if (UsersList.hasDescription(userID)) {
|
||||
try {
|
||||
extendedUserProfile.z2 = Handler.getDescription(userID);
|
||||
} catch (NullPointerException e) {
|
||||
Log.e(TAG, "null \"profiles\" node\n" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getInfo(ExtendedUserProfile extendedUserProfile) {
|
||||
int userID = getUserID(extendedUserProfile);
|
||||
if (UsersList.hasDescription(userID)) {
|
||||
if (!TextUtils.isEmpty(extendedUserProfile.z2)) {
|
||||
return extendedUserProfile.z2;
|
||||
} else {
|
||||
return Handler.getDescription(userID);
|
||||
}
|
||||
}
|
||||
return getGlobalContext().getString(UserPresenter.q0.a(userID));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package ru.vtosters.lite.ssfs;
|
||||
|
||||
import android.util.Log;
|
||||
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.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.NetworkUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static ru.vtosters.lite.utils.Preferences.dev;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
public class UsersList {
|
||||
private static final String TAG = "UsersList";
|
||||
private static final List<Integer> descriptionsList = new ArrayList<>();
|
||||
private static final List<Integer> bannersList = new ArrayList<>();
|
||||
|
||||
public static void getUsersList() {
|
||||
var prefs = AndroidUtils.getGlobalContext().getSharedPreferences("vt_another_data", 0);
|
||||
|
||||
if ((!NetworkUtils.isNetworkConnected() || getBoolValue("isRoamingState", false)) && prefs.contains("ids")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Request request = new Request.a()
|
||||
.b(Utils.getDomain() + "/api/getUsersWithServiceDescriptionsAndBanners")
|
||||
.a();
|
||||
|
||||
VtOkHttpClient.getInstance().a(request).a(new Callback() {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(Call call, Response response) {
|
||||
try {
|
||||
parseJson(new JSONObject(response.a().g()).getJSONObject("response"));
|
||||
} catch (JSONException | IOException e) {
|
||||
Log.d(TAG, e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean hasDescription(int id) {
|
||||
return descriptionsList.contains(id) && id != AccountManagerUtils.getUserId();
|
||||
}
|
||||
|
||||
public static boolean hasBanner(int id) {
|
||||
return bannersList.contains(id) && id != AccountManagerUtils.getUserId();
|
||||
}
|
||||
|
||||
static void parseJson(JSONObject json) throws JSONException {
|
||||
var idsDescription = json.getJSONArray("with_service_descriptions");
|
||||
var idsBanner = json.getJSONArray("with_chat_banners");
|
||||
|
||||
if (dev()) {
|
||||
Log.d(TAG, idsDescription.toString());
|
||||
Log.d(TAG, idsBanner.toString());
|
||||
}
|
||||
|
||||
processIds(idsBanner, bannersList);
|
||||
processIds(idsDescription, descriptionsList);
|
||||
}
|
||||
|
||||
static void processIds(JSONArray jsonIds, List<Integer> member) {
|
||||
for (int i = 0; i < jsonIds.length(); i++)
|
||||
member.add(jsonIds.optInt(i));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package ru.vtosters.lite.ssfs;
|
||||
|
||||
import com.vk.core.network.Network;
|
||||
import ru.vtosters.lite.hooks.DateHook;
|
||||
import ru.vtosters.lite.proxy.ProxyUtils;
|
||||
import ru.vtosters.lite.utils.*;
|
||||
|
||||
public class Utils {
|
||||
public static String getVKUILink() {
|
||||
return getDomain() +
|
||||
"?token=" + AccountManagerUtils.getUserToken() +
|
||||
"&vt_dark=" + (ThemesUtils.isDarkTheme() ? "1" : "0") +
|
||||
"&vt_amoled=" + (ThemesUtils.isAmoledTheme() && ThemesUtils.isDarkTheme() ? "1" : "0") +
|
||||
"&secret=" + AccountManagerUtils.getUserSecret() +
|
||||
"&proxy=" + (ProxyUtils.isAnyProxyEnabled() ? "1" : "0") +
|
||||
"&lang=" + DateHook.getLocale() +
|
||||
"&vt=1" +
|
||||
"&useragent=" + Base64Utils.encodeValue(Base64Utils.encode(Network.l.c().a())) +
|
||||
"&vt_debug=" + (Preferences.dev() ? "1" : "0");
|
||||
}
|
||||
|
||||
public static String getDomain() {
|
||||
String string = AndroidUtils.getPrefsValue("ssfscustom");
|
||||
|
||||
if (!string.isEmpty()) return string;
|
||||
|
||||
return "https://ssfs.vtosters.app";
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package ru.vtosters.lite.tgs;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import com.aefyr.tsg.g2.TelegramStickersPack;
|
||||
import com.aefyr.tsg.g2.TelegramStickersService;
|
||||
import com.vk.dto.common.Attachment;
|
||||
@@ -15,15 +12,15 @@ import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.attachments.PendingGraffitiAttachment;
|
||||
import com.vtosters.lite.im.AppAttachToImAttachConverter;
|
||||
import com.vtosters.lite.upload.Upload;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
public class TGRoot {
|
||||
public static final int N = 76820000;
|
||||
@@ -101,7 +98,7 @@ public class TGRoot {
|
||||
}
|
||||
}
|
||||
|
||||
private static StickerStockItem toStickerPack(TelegramStickersPack p) throws JSONException {
|
||||
public static StickerStockItem toStickerPack(TelegramStickersPack p) throws JSONException {
|
||||
JSONArray arr = new JSONArray();
|
||||
|
||||
for (int j = 0; j < p.stickersCount; j++)
|
||||
|
||||
@@ -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,190 @@
|
||||
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 outgoinging_msg;
|
||||
private static int outgoinging_msg_highlight;
|
||||
|
||||
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);
|
||||
|
||||
outgoinging_msg = ThemesUtils.lighten(accentColor, 0.76f);
|
||||
outgoinging_msg_highlight = ThemesUtils.lighten(accentColor, 0.5f);
|
||||
|
||||
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) {
|
||||
return outgoinging_msg;
|
||||
} else if (attr == R.attr.im_bubble_outgoing_highlighted) {
|
||||
return outgoinging_msg_highlight;
|
||||
}
|
||||
|
||||
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,54 @@
|
||||
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.getResources().getColor(color))) {
|
||||
return ThemesUtils.getAccentColor();
|
||||
}
|
||||
|
||||
if (ThemesCore.isCachedAccents() && ColorReferences.isMutedAccentedColor(context.getResources().getColor(color))) {
|
||||
return ThemesUtils.getMutedAccentColor();
|
||||
}
|
||||
|
||||
return Build.VERSION.SDK_INT > 23 ? context.getColor(color) : 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,113 @@
|
||||
package ru.vtosters.lite.themes.palettes;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.themes.items.VTLPalette;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.widget.Toast.makeText;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
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();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23 && !Environment.getExternalStorageDirectory().canWrite()) {
|
||||
makeText(getGlobalContext(), AndroidUtils.getString("cannot_write"), Toast.LENGTH_LONG).show();
|
||||
LifecycleUtils.getCurrentActivity().requestPermissions(new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, 228);
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
Log.d("PalettesManager", "arr.length null");
|
||||
return;
|
||||
}
|
||||
|
||||
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!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
package ru.vtosters.lite.ui;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.preference.PreferenceManager;
|
||||
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 androidx.preference.PreferenceScreen;
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
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 PreferenceFragmentUtils {
|
||||
|
||||
public static ListPreference addListPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
String def,
|
||||
int titleRes,
|
||||
CharSequence[] entries,
|
||||
CharSequence[] entriesValue
|
||||
) {
|
||||
return addListPreference(screen, key, def, titleRes, 0, 0, entries, entriesValue, null);
|
||||
}
|
||||
|
||||
public static ListPreference addListPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
String def,
|
||||
CharSequence title,
|
||||
CharSequence[] entries,
|
||||
CharSequence[] entriesValue
|
||||
) {
|
||||
return addListPreference(screen, key, def, title, null, "", entries, entriesValue, null);
|
||||
}
|
||||
|
||||
// change icon accent color
|
||||
public static ListPreference addListPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
String def,
|
||||
int titleRes,
|
||||
int iconRes,
|
||||
int summaryRes,
|
||||
CharSequence[] entries,
|
||||
CharSequence[] entriesValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
var icon = iconRes > 0
|
||||
? ImageUtils.setTint(screen.getContext(), ContextCompat.getDrawable(screen.getContext(), iconRes))
|
||||
: null;
|
||||
var title = titleRes > 0
|
||||
? screen.getContext().getString(titleRes)
|
||||
: "";
|
||||
var summary = summaryRes > 0
|
||||
? screen.getContext().getString(summaryRes)
|
||||
: "";
|
||||
return addListPreference(screen, key, def, title, icon, summary, entries, entriesValue, listener);
|
||||
}
|
||||
|
||||
// change icon accent color
|
||||
public static ListPreference addListPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
String def,
|
||||
CharSequence title,
|
||||
int iconRes,
|
||||
CharSequence summary,
|
||||
CharSequence[] entries,
|
||||
CharSequence[] entriesValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
var icon = iconRes > 0
|
||||
? ImageUtils.setTint(screen.getContext(), ContextCompat.getDrawable(screen.getContext(), iconRes))
|
||||
: null;
|
||||
return addListPreference(screen, key, def, title, icon, summary, entries, entriesValue, listener);
|
||||
}
|
||||
|
||||
public static ListPreference addListPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
String def,
|
||||
CharSequence title,
|
||||
@Nullable Drawable icon,
|
||||
CharSequence summary,
|
||||
CharSequence[] entries,
|
||||
CharSequence[] entriesValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
ListPreference preference = new ListPreference(screen.getContext());
|
||||
preference.setEntries(entries);
|
||||
preference.setEntryValues(entriesValue);
|
||||
preference.setSummary(summary);
|
||||
preference.setTitle(title);
|
||||
preference.setDialogTitle(title);
|
||||
preference.setKey(key);
|
||||
preference.setDefaultValue(def);
|
||||
preference.setValue(def);
|
||||
preference.setOnPreferenceChangeListener(listener);
|
||||
|
||||
if (icon != null)
|
||||
preference.setIcon(icon);
|
||||
|
||||
screen.addPreference(preference);
|
||||
|
||||
return preference;
|
||||
}
|
||||
|
||||
public static MaterialSwitchPreference addMaterialSwitchPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence summary,
|
||||
boolean defValue
|
||||
) {
|
||||
return addMaterialSwitchPreference(screen, key, title, summary, 0, defValue, null);
|
||||
}
|
||||
|
||||
// change icon accent color
|
||||
public static MaterialSwitchPreference addMaterialSwitchPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
int titleRes,
|
||||
int summaryRes,
|
||||
int iconRes,
|
||||
boolean defValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
var icon = iconRes > 0
|
||||
? ImageUtils.setTint(screen.getContext(), ContextCompat.getDrawable(screen.getContext(), iconRes))
|
||||
: null;
|
||||
var title = titleRes > 0
|
||||
? screen.getContext().getString(titleRes)
|
||||
: "";
|
||||
var summary = summaryRes > 0
|
||||
? screen.getContext().getString(summaryRes)
|
||||
: "";
|
||||
return addMaterialSwitchPreference(screen, key, title, summary, icon, defValue, listener);
|
||||
}
|
||||
|
||||
// change icon accent color
|
||||
public static MaterialSwitchPreference addMaterialSwitchPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence summary,
|
||||
int iconRes,
|
||||
boolean defValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
var icon = iconRes > 0
|
||||
? ImageUtils.setTint(screen.getContext(), ContextCompat.getDrawable(screen.getContext(), iconRes))
|
||||
: null;
|
||||
return addMaterialSwitchPreference(screen, key, title, summary, icon, defValue, listener);
|
||||
}
|
||||
|
||||
public static MaterialSwitchPreference addMaterialSwitchPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence summary,
|
||||
@Nullable Drawable icon,
|
||||
boolean defValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
MaterialSwitchPreference preference = new MaterialSwitchPreference(screen.getContext());
|
||||
preference.setTitle(title);
|
||||
preference.setSummary(summary);
|
||||
preference.setKey(key);
|
||||
preference.setDefaultValue(defValue);
|
||||
|
||||
if (icon != null)
|
||||
preference.setIcon(icon);
|
||||
preference.setOnPreferenceChangeListener(listener);
|
||||
|
||||
screen.addPreference(preference);
|
||||
|
||||
return preference;
|
||||
}
|
||||
|
||||
public static Preference addPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
int titleRes,
|
||||
int summaryRes
|
||||
) {
|
||||
var title = titleRes > 0
|
||||
? screen.getContext().getString(titleRes)
|
||||
: "";
|
||||
var summary = summaryRes > 0
|
||||
? screen.getContext().getString(summaryRes)
|
||||
: "";
|
||||
return addPreference(screen, key, title, summary, null, null);
|
||||
}
|
||||
|
||||
public static Preference addPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence summary
|
||||
) {
|
||||
return addPreference(screen, key, title, summary, null, null);
|
||||
}
|
||||
|
||||
// change icon accent color
|
||||
public static Preference addPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
int titleRes,
|
||||
int summaryRes,
|
||||
int iconRes,
|
||||
Preference.OnPreferenceClickListener listener) {
|
||||
var icon = iconRes > 0
|
||||
? ImageUtils.setTint(screen.getContext(), screen.getContext().getDrawable(iconRes))
|
||||
: null;
|
||||
var title = titleRes > 0
|
||||
? screen.getContext().getString(titleRes)
|
||||
: "";
|
||||
var summary = summaryRes > 0
|
||||
? screen.getContext().getString(summaryRes)
|
||||
: "";
|
||||
return addPreference(screen, key, title, summary, icon, listener);
|
||||
}
|
||||
|
||||
// change icon accent color
|
||||
public static Preference addPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence summary,
|
||||
int iconRes,
|
||||
Preference.OnPreferenceClickListener listener) {
|
||||
var icon = iconRes > 0
|
||||
? ImageUtils.setTint(screen.getContext(), screen.getContext().getDrawable(iconRes))
|
||||
: null;
|
||||
return addPreference(screen, key, title, summary, icon, listener);
|
||||
}
|
||||
|
||||
public static Preference addPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence summary,
|
||||
@Nullable Drawable icon,
|
||||
Preference.OnPreferenceClickListener listener
|
||||
) {
|
||||
Preference preference = new Preference(screen.getContext());
|
||||
preference.setSummary(summary);
|
||||
preference.setTitle(title);
|
||||
preference.setKey(key);
|
||||
|
||||
if (icon != null)
|
||||
preference.setIcon(icon);
|
||||
preference.setOnPreferenceClickListener(listener);
|
||||
|
||||
screen.addPreference(preference);
|
||||
|
||||
return preference;
|
||||
}
|
||||
|
||||
public static PreferenceCategory addPreferenceCategory(PreferenceScreen screen, int titleRes) {
|
||||
var title = titleRes > 0
|
||||
? screen.getContext().getString(titleRes)
|
||||
: "";
|
||||
return addPreferenceCategory(screen, title);
|
||||
}
|
||||
|
||||
public static PreferenceCategory addPreferenceCategory(PreferenceScreen screen, CharSequence title) {
|
||||
PreferenceCategory preference = new PreferenceCategory(screen.getContext(), null);
|
||||
preference.setTitle(title);
|
||||
screen.addPreference(preference);
|
||||
|
||||
return preference;
|
||||
}
|
||||
|
||||
public static Preference addEditTextPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
int titleRes,
|
||||
onPreferenceTextValueChangeListener editTextPrefChangeListener
|
||||
) {
|
||||
var title = titleRes > 0
|
||||
? screen.getContext().getString(titleRes)
|
||||
: "";
|
||||
return addEditTextPreference(screen, key, title, editTextPrefChangeListener);
|
||||
}
|
||||
|
||||
public static Preference addEditTextPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
CharSequence title,
|
||||
onPreferenceTextValueChangeListener editTextPrefChangeListener
|
||||
) {
|
||||
return addPreference(screen, key, title, null, null, preference -> {
|
||||
LinearLayout linearLayout = new LinearLayout(screen.getContext());
|
||||
|
||||
final EditText editText = new EditText(screen.getContext());
|
||||
editText.setText(PreferenceManager.getDefaultSharedPreferences(screen.getContext()).getString(key, ""));
|
||||
editText.setHint(title);
|
||||
editText.setTextColor(ThemesUtils.getTextAttr());
|
||||
editText.setHintTextColor(ThemesUtils.getSTextAttr());
|
||||
|
||||
editText.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
|
||||
linearLayout.addView(editText);
|
||||
editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) editText.getLayoutParams());
|
||||
margin.setMargins(AndroidUtils.dp2px(20f), 0, AndroidUtils.dp2px(20f), 0);
|
||||
editText.setLayoutParams(margin);
|
||||
|
||||
new VkAlertDialog.Builder(screen.getContext())
|
||||
.setTitle(title)
|
||||
.setView(linearLayout)
|
||||
.setPositiveButton("OK", (dialog, which) -> {
|
||||
boolean change = editTextPrefChangeListener.onChanged(preference, editText.getText().toString());
|
||||
if (!change)
|
||||
return;
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(screen.getContext())
|
||||
.edit()
|
||||
.putString(key, editText.getText().toString())
|
||||
.apply();
|
||||
})
|
||||
.show();
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
public interface onPreferenceTextValueChangeListener {
|
||||
boolean onChanged(Preference preference, String newValue);
|
||||
}
|
||||
}
|
||||
@@ -1,281 +0,0 @@
|
||||
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;
|
||||
|
||||
public class PreferencesUtil {
|
||||
|
||||
public static void addListPreference(
|
||||
MaterialPreferenceToolbarFragment fragment,
|
||||
String key,
|
||||
String def,
|
||||
CharSequence title,
|
||||
CharSequence[] entries,
|
||||
CharSequence[] entriesValue
|
||||
) {
|
||||
ListPreference preference = new ListPreference(getGlobalContext());
|
||||
preference.setEntries(entries);
|
||||
preference.setEntryValues(entriesValue);
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setDialogTitle(title); // setDialogTitle
|
||||
preference.setKey(key); // setKey
|
||||
preference.setDefaultValue(def); // setDefaultValue
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addListPreferenceIcon(
|
||||
MaterialPreferenceToolbarFragment fragment,
|
||||
String key,
|
||||
String def,
|
||||
CharSequence title,
|
||||
int iconRes,
|
||||
CharSequence summary,
|
||||
CharSequence[] entries,
|
||||
CharSequence[] entriesValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
ListPreference preference = new ListPreference(getGlobalContext());
|
||||
preference.setEntries(entries);
|
||||
preference.setEntryValues(entriesValue);
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setDialogTitle(title); // setDialogTitle
|
||||
preference.setKey(key); // setKey
|
||||
preference.setDefaultValue(def); // setDefaultValue
|
||||
preference.setValue(def);
|
||||
preference.setOnPreferenceChangeListener(listener);
|
||||
|
||||
if (iconRes != 0)
|
||||
preference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addMaterialSwitchPreference(
|
||||
MaterialPreferenceToolbarFragment materialPreferenceToolbarFragment,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence summary,
|
||||
boolean defValue
|
||||
) {
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
materialSwitchPreference.setTitle(title); // setTitle
|
||||
materialSwitchPreference.setSummary(summary); // setSummary
|
||||
materialSwitchPreference.setKey(key); // setKey
|
||||
materialSwitchPreference.setDefaultValue(defValue); // setDefaultValue
|
||||
|
||||
materialPreferenceToolbarFragment.getPreferenceScreen().addPreference(materialSwitchPreference); // materialPreferenceToolbarFragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
// public static void addMaterialSwitchPreference(
|
||||
// MaterialPreferenceToolbarFragment fragment,
|
||||
// String key,
|
||||
// CharSequence title,
|
||||
// CharSequence summary,
|
||||
// int iconRes,
|
||||
// boolean defValue,
|
||||
// Preference.OnPreferenceChangeListener listener
|
||||
// ) {
|
||||
// MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
// materialSwitchPreference.setTitle(title); // setTitle
|
||||
// materialSwitchPreference.setSummary(summary); // setSummary
|
||||
// materialSwitchPreference.setKey(key); // setKey
|
||||
// materialSwitchPreference.setDefaultValue(defValue); // setDefaultValue
|
||||
// materialSwitchPreference.setOnPreferenceChangeListener(listener); // setOnPreferenceClickListener
|
||||
//
|
||||
// if (iconRes != 0)
|
||||
// materialSwitchPreference.setIcon(setTint(getGlobalContext(), Objects.requireNonNull(ContextCompat.getDrawable(getGlobalContext(), iconRes)))); // preference.setIcon
|
||||
//
|
||||
// fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
// }
|
||||
|
||||
public static void addMaterialSwitchPreference(
|
||||
MaterialPreferenceToolbarFragment fragment,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence summary,
|
||||
int iconRes,
|
||||
boolean defValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
materialSwitchPreference.setTitle(title); // setTitle
|
||||
materialSwitchPreference.setSummary(summary); // setSummary
|
||||
materialSwitchPreference.setKey(key); // setKey
|
||||
materialSwitchPreference.setDefaultValue(defValue); // setDefaultValue
|
||||
fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // materialPreferenceToolbarFragment.getPreferenceScreen().addPreference(preference)
|
||||
|
||||
if (iconRes != 0)
|
||||
materialSwitchPreference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
materialSwitchPreference.setOnPreferenceChangeListener(listener); // setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreference(
|
||||
MaterialPreferenceToolbarFragment fragment,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence summary
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreference(
|
||||
MaterialPreferenceToolbarFragment fragment,
|
||||
CharSequence title,
|
||||
CharSequence summary,
|
||||
int iconRes,
|
||||
Preference.OnPreferenceClickListener listener
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
|
||||
if (iconRes != 0)
|
||||
preference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
preference.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreference(
|
||||
MaterialPreferenceToolbarFragment fragment,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence summary,
|
||||
int iconRes,
|
||||
Preference.OnPreferenceClickListener listener) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
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.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreferenceDrawable(
|
||||
MaterialPreferenceToolbarFragment fragment,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence summary,
|
||||
@Nullable Drawable icon,
|
||||
Preference.OnPreferenceClickListener listener
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
|
||||
if (icon != null)
|
||||
preference.setIcon(icon); // preference.setIcon
|
||||
preference.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreferenceCategory(MaterialPreferenceToolbarFragment fragment, CharSequence title) {
|
||||
PreferenceCategory preference = new PreferenceCategory(getGlobalContext(), 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);
|
||||
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.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
preference.setOnPreferenceClickListener(preference1 -> {
|
||||
LinearLayout linearLayout = new LinearLayout(getGlobalContext());
|
||||
|
||||
final EditText editText = new EditText(getGlobalContext());
|
||||
editText.setText(PreferenceManager.getDefaultSharedPreferences(getGlobalContext()).getString(key, ""));
|
||||
editText.setHint(title);
|
||||
editText.setTextColor(getTextAttr());
|
||||
editText.setHintTextColor(getSTextAttr());
|
||||
|
||||
editText.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
|
||||
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);
|
||||
editText.setLayoutParams(margin);
|
||||
|
||||
new VkAlertDialog.Builder(fragment.getContext())
|
||||
.setTitle(title)
|
||||
.setView(linearLayout)
|
||||
.setPositiveButton("OK", (dialog, which) -> {
|
||||
boolean change = editTextPrefChangeListener.onChanged(preference, editText.getText().toString());
|
||||
if (!change)
|
||||
return;
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(getGlobalContext())
|
||||
.edit()
|
||||
.putString(key, editText.getText().toString())
|
||||
.apply();
|
||||
})
|
||||
.show();
|
||||
return false;
|
||||
}); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static int getTextColor(Context ctx) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(getTextAttr(), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
public static int getSTextColor(Context ctx) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(getSTextAttr(), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
private static Drawable getDrawable(Context ctx, int drawableRes) {
|
||||
return ContextCompat.getDrawable(ctx, drawableRes);
|
||||
}
|
||||
|
||||
public interface EditTextPrefChangeListener {
|
||||
boolean onChanged(Preference preference, Object obj);
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
package ru.vtosters.lite.ui.adapters;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getResources;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getSTextAttr;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.recolorDrawable;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.net.Uri;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -14,19 +8,32 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.aefyr.tsg.g2.TelegramStickersPack;
|
||||
import com.aefyr.tsg.g2.TelegramStickersService;
|
||||
import com.vk.core.dialogs.bottomsheet.ContentSnapStrategy1;
|
||||
import com.vk.core.dialogs.bottomsheet.ModalBottomSheet;
|
||||
import com.vk.core.util.ContextExtKt;
|
||||
import com.vk.core.util.DrawableUtils;
|
||||
import com.vk.sharing.Sharing;
|
||||
import com.vk.stickers.LongtapRecyclerView;
|
||||
import com.vk.stickers.bridge.GiftData;
|
||||
import com.vk.stickers.details.StickerDetailsAdapter;
|
||||
import com.vk.stickers.details.StickerDetailsView;
|
||||
import com.vtosters.lite.R;
|
||||
import org.json.JSONException;
|
||||
import ru.vtosters.lite.tgs.TGPref;
|
||||
import ru.vtosters.lite.tgs.TGRoot;
|
||||
import ru.vtosters.lite.ui.components.IItemMovingListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ru.vtosters.lite.tgs.TGPref;
|
||||
import ru.vtosters.lite.ui.components.IItemMovingListener;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getResources;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.*;
|
||||
|
||||
public class StickerPackAdapter extends RecyclerView.Adapter<StickerPackAdapter.StickerPackViewHolder> implements IItemMovingListener {
|
||||
private static final TelegramStickersService sService = TelegramStickersService.getInstance(getGlobalContext());
|
||||
@@ -108,10 +115,11 @@ public class StickerPackAdapter extends RecyclerView.Adapter<StickerPackAdapter.
|
||||
final TelegramStickersPack pack = sService.getPacksListReference().get(position);
|
||||
if (pack.state != TelegramStickersPack.DOWNLOADED) return;
|
||||
|
||||
File f = new File(pack.folder, "001.png");
|
||||
var uri = Uri.parse("file://" + f.getAbsolutePath());
|
||||
try {
|
||||
File f = new File(pack.folder, "001.png");
|
||||
if (f.exists()) {
|
||||
mStickerPreview.setImageURI(Uri.parse("file://" + f.getAbsolutePath()));
|
||||
mStickerPreview.setImageURI(uri);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -129,7 +137,7 @@ public class StickerPackAdapter extends RecyclerView.Adapter<StickerPackAdapter.
|
||||
});
|
||||
mName.setText(pack.title);
|
||||
mSwitch.setChecked(pack.enabled);
|
||||
mSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> sService.setPackEnabled(pack, isChecked, false));
|
||||
mSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> sService.setPackEnabled(pack, isChecked, true));
|
||||
mStickersCount.setText(pack.stickersCount + " " + mStickersCount.getContext().getString(R.string.stickerscount));
|
||||
|
||||
// Color костыль
|
||||
@@ -138,6 +146,35 @@ public class StickerPackAdapter extends RecyclerView.Adapter<StickerPackAdapter.
|
||||
|
||||
mName.setTextColor(color);
|
||||
mStickersCount.setTextColor(secondary);
|
||||
|
||||
if (pack.state == TelegramStickersPack.DOWNLOADED)
|
||||
mContainer.setOnClickListener(v -> {
|
||||
try {
|
||||
ViewGroup root = (ViewGroup) ContextExtKt.c(v.getContext()).inflate(R.layout.sticker_details_bottom_container, null);
|
||||
StickerDetailsView stickersDetailsView = new StickerDetailsView(v.getContext());
|
||||
|
||||
stickersDetailsView.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
|
||||
stickersDetailsView.a(TGRoot.toStickerPack(pack), new GiftData(new ArrayList<>(), false), root);
|
||||
|
||||
var recycler = (LongtapRecyclerView) stickersDetailsView.findViewById(R.id.recycler);
|
||||
((StickerDetailsAdapter) recycler.getAdapter()).setTelegramPack(true);
|
||||
|
||||
var builder = new ModalBottomSheet.a(v.getContext());
|
||||
builder.d(pack.title);
|
||||
builder.d(stickersDetailsView);
|
||||
builder.a(DrawableUtils.a(v.getContext(), R.drawable.share_outline_28, R.color.accent_blue));
|
||||
builder.c(R.attr.content_tint_background);
|
||||
builder.b(view -> {
|
||||
Sharing.a(view.getContext(), "https://t.me/addstickers/" + pack.id);
|
||||
return null;
|
||||
});
|
||||
builder.a(new ContentSnapStrategy1(false));
|
||||
|
||||
builder.a("stickers_preview");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.io.StringWriter;
|
||||
|
||||
import ru.vtosters.lite.deviceinfo.DeviceInfoCollector;
|
||||
import ru.vtosters.lite.services.LogWriterService;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class CrashReporter {
|
||||
protected static String logString;
|
||||
@@ -41,7 +42,7 @@ public class CrashReporter {
|
||||
logString = getStackTrace(th) + "\n\n" + new DeviceInfoCollector().collect().toDeviceName();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
var notificationChannel = new NotificationChannel("crashes", "crash", NotificationManager.IMPORTANCE_DEFAULT);
|
||||
var notificationChannel = new NotificationChannel("crashes", AndroidUtils.getString("crash_service_name"), NotificationManager.IMPORTANCE_DEFAULT);
|
||||
notificationChannel.enableVibration(true);
|
||||
notificationChannel.enableLights(true);
|
||||
((NotificationManager) getGlobalContext().getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(notificationChannel);
|
||||
@@ -51,7 +52,7 @@ public class CrashReporter {
|
||||
foxbinIntent.putExtra("android.intent.extra.TEXT", logString);
|
||||
foxbinIntent.setType("text/plain");
|
||||
if (!isFoxbinInstalled()) {
|
||||
foxbinIntent = new Intent("android.intent.action.VIEW");
|
||||
foxbinIntent = new Intent(Intent.ACTION_VIEW);
|
||||
foxbinIntent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.f0x1d.dogbin"));
|
||||
foxbinIntent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
|
||||
}
|
||||
|
||||
@@ -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(), mHelper.getCommitSHA());
|
||||
})
|
||||
.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(AndroidUtils.getString("changelog") + ": \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);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,17 @@
|
||||
package ru.vtosters.lite.ui.dialogs;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.deviceinfo.OEMDetector;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
public class Start {
|
||||
public static void alert(final Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
@@ -28,10 +26,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(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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,5 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static ru.vtosters.lite.ui.PreferencesUtil.addPreference;
|
||||
import static ru.vtosters.lite.ui.PreferencesUtil.addPreferenceCategory;
|
||||
import static ru.vtosters.lite.ui.PreferencesUtil.addPreferenceDrawable;
|
||||
import static ru.vtosters.lite.ui.components.IconManager.icons;
|
||||
import static ru.vtosters.lite.ui.components.IconManager.iconsValues;
|
||||
import static ru.vtosters.lite.ui.components.IconManager.sIconsPlus;
|
||||
import static ru.vtosters.lite.ui.components.IconManager.sIconsPlusNames;
|
||||
import static ru.vtosters.lite.ui.components.IconManager.switchComponent;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.hasVerification;
|
||||
import static ru.vtosters.lite.utils.Preferences.preferences;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -26,44 +9,47 @@ import android.os.Bundle;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
import ru.vtosters.lite.ui.PreferenceFragmentUtils;
|
||||
import ru.vtosters.lite.ui.components.IconManager;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class IconsFragment extends MaterialPreferenceToolbarFragment {
|
||||
@SuppressLint("SetTextI18n")
|
||||
public static void callSelectDialog(Context ctx, String appicon) {
|
||||
var defname = preferences.getString("appname", "vt");
|
||||
var deficon = preferences.getString("selectedicon", "vt");
|
||||
var defname = Preferences.preferences.getString("appname", "vt");
|
||||
var deficon = Preferences.preferences.getString("selectedicon", "vt");
|
||||
|
||||
RadioGroup rg = new RadioGroup(ctx);
|
||||
|
||||
RadioButton rgDefault = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton rgVK = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton rgVKontakte = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton rgDefault = new RadioButton(new ContextThemeWrapper(ctx, R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton rgVK = new RadioButton(new ContextThemeWrapper(ctx, R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
RadioButton rgVKontakte = new RadioButton(new ContextThemeWrapper(ctx, R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
|
||||
rg.addView(rgDefault);
|
||||
rg.addView(rgVK);
|
||||
rg.addView(rgVKontakte);
|
||||
|
||||
rgDefault.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
rgVK.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
rgVKontakte.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
rgDefault.setTextSize(TypedValue.COMPLEX_UNIT_PX, AndroidUtils.dp2px(14f));
|
||||
rgVK.setTextSize(TypedValue.COMPLEX_UNIT_PX, AndroidUtils.dp2px(14f));
|
||||
rgVKontakte.setTextSize(TypedValue.COMPLEX_UNIT_PX, AndroidUtils.dp2px(14f));
|
||||
|
||||
rg.setPadding(dp2px(18f), dp2px(12f), dp2px(18f), 0);
|
||||
rg.setPadding(AndroidUtils.dp2px(18f), AndroidUtils.dp2px(12f), AndroidUtils.dp2px(18f), 0);
|
||||
|
||||
rgDefault.setText("VTLite");
|
||||
rgDefault.setTextColor(getTextAttr());
|
||||
rgDefault.setTextColor(ThemesUtils.getTextAttr());
|
||||
|
||||
rgVK.setText("VK");
|
||||
rgVK.setTextColor(getTextAttr());
|
||||
rgVK.setTextColor(ThemesUtils.getTextAttr());
|
||||
|
||||
rgVKontakte.setText(ctx.getString(R.string.app_name_alter));
|
||||
rgVKontakte.setTextColor(getTextAttr());
|
||||
rgVKontakte.setTextColor(ThemesUtils.getTextAttr());
|
||||
|
||||
rgVKontakte.setChecked(defname.contains("vkontakte"));
|
||||
rgVK.setChecked(defname.contains("standard"));
|
||||
@@ -74,20 +60,20 @@ public class IconsFragment extends MaterialPreferenceToolbarFragment {
|
||||
.setView(rg)
|
||||
.setPositiveButton(R.string.vtl_confirm, ((dialog, which) -> {
|
||||
if (rgDefault.isChecked()) {
|
||||
edit().putString("appname", "vt").commit();
|
||||
edit().putString("selectedicon", appicon).commit();
|
||||
AndroidUtils.edit().putString("appname", "vt").commit();
|
||||
AndroidUtils.edit().putString("selectedicon", appicon).commit();
|
||||
|
||||
switchComponent(appicon, "vt", deficon, defname);
|
||||
IconManager.switchComponent(appicon, "vt", deficon, defname);
|
||||
} else if (rgVK.isChecked()) {
|
||||
edit().putString("appname", "standard").commit();
|
||||
edit().putString("selectedicon", appicon).commit();
|
||||
AndroidUtils.edit().putString("appname", "standard").commit();
|
||||
AndroidUtils.edit().putString("selectedicon", appicon).commit();
|
||||
|
||||
switchComponent(appicon, "standard", deficon, defname);
|
||||
IconManager.switchComponent(appicon, "standard", deficon, defname);
|
||||
} else if (rgVKontakte.isChecked()) {
|
||||
edit().putString("appname", "vkontakte").commit();
|
||||
edit().putString("selectedicon", appicon).commit();
|
||||
AndroidUtils.edit().putString("appname", "vkontakte").commit();
|
||||
AndroidUtils.edit().putString("selectedicon", appicon).commit();
|
||||
|
||||
switchComponent(appicon, "vkontakte", deficon, defname);
|
||||
IconManager.switchComponent(appicon, "vkontakte", deficon, defname);
|
||||
}
|
||||
}))
|
||||
.setNegativeButton(R.string.cancel,
|
||||
@@ -102,20 +88,20 @@ public class IconsFragment extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
this.addPreferencesFromResource(R.xml.empty);
|
||||
|
||||
if (!hasVerification() && !getBoolValue("dialogrecomm", false)) {
|
||||
addPreference(this, "", requireContext().getString(R.string.icons_warning), requireContext().getString(R.string.icons_warning_info), R.drawable.ic_about_outline_28, preference -> {
|
||||
getContext().startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse("https://vtosters.app/donate/")));
|
||||
if (!Preferences.hasVerification() && !Preferences.getBoolValue("dialogrecomm", false)) {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", requireContext().getString(R.string.icons_warning), requireContext().getString(R.string.icons_warning_info), R.drawable.ic_about_outline_28, preference -> {
|
||||
getContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://vtosters.app/donate/")));
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
addPreferenceCategory(this, requireContext().getString(R.string.icons_title));
|
||||
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), requireContext().getString(R.string.icons_title));
|
||||
|
||||
for (var i = 0; i < icons().size(); i++) {
|
||||
if (icons().get(i) == null || iconsValues().get(i) == null) return;
|
||||
for (var i = 0; i < IconManager.icons().size(); i++) {
|
||||
if (IconManager.icons().get(i) == null || IconManager.iconsValues().get(i) == null) return;
|
||||
|
||||
String iconname = icons().get(i);
|
||||
String icon = iconsValues().get(i);
|
||||
String iconname = IconManager.icons().get(i);
|
||||
String icon = IconManager.iconsValues().get(i);
|
||||
|
||||
int iconRes;
|
||||
|
||||
@@ -124,7 +110,7 @@ public class IconsFragment extends MaterialPreferenceToolbarFragment {
|
||||
} else if (icon.contains("standard")) {
|
||||
iconRes = R.mipmap.ic_launcher_round;
|
||||
} else {
|
||||
iconRes = getIdentifier("ic_launcher_" + icon, "mipmap");
|
||||
iconRes = AndroidUtils.getIdentifier("ic_launcher_" + icon, "mipmap");
|
||||
}
|
||||
|
||||
Drawable drawable = ResourcesCompat.getDrawable(getResources(), iconRes, null);
|
||||
@@ -133,20 +119,20 @@ public class IconsFragment extends MaterialPreferenceToolbarFragment {
|
||||
drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_bug_outline_28, null);
|
||||
}
|
||||
|
||||
addPreferenceDrawable(this, icon, iconname, "", drawable, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), icon, iconname, "", drawable, preference -> {
|
||||
callSelectDialog(this.getContext(), icon);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (!hasVerification() && !getBoolValue("dialogrecomm", false)) {
|
||||
addPreferenceCategory(this, requireContext().getString(R.string.unavailable_icons));
|
||||
if (!Preferences.hasVerification() && !Preferences.getBoolValue("dialogrecomm", false)) {
|
||||
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), requireContext().getString(R.string.unavailable_icons));
|
||||
|
||||
for (var i = 2; i < sIconsPlusNames.size(); i++) {
|
||||
if (sIconsPlusNames.get(i) == null || sIconsPlus.get(i) == null) return;
|
||||
for (var i = 2; i < IconManager.sIconsPlusNames.size(); i++) {
|
||||
if (IconManager.sIconsPlusNames.get(i) == null || IconManager.sIconsPlus.get(i) == null) return;
|
||||
|
||||
String iconname = sIconsPlusNames.get(i);
|
||||
String icon = sIconsPlus.get(i);
|
||||
String iconname = IconManager.sIconsPlusNames.get(i);
|
||||
String icon = IconManager.sIconsPlus.get(i);
|
||||
|
||||
int iconRes;
|
||||
|
||||
@@ -155,7 +141,7 @@ public class IconsFragment extends MaterialPreferenceToolbarFragment {
|
||||
} else if (icon.contains("standard")) {
|
||||
iconRes = R.mipmap.ic_launcher_round;
|
||||
} else {
|
||||
iconRes = getIdentifier("ic_launcher_" + icon, "mipmap");
|
||||
iconRes = AndroidUtils.getIdentifier("ic_launcher_" + icon, "mipmap");
|
||||
}
|
||||
|
||||
Drawable drawable = ResourcesCompat.getDrawable(getResources(), iconRes, null);
|
||||
@@ -164,8 +150,8 @@ public class IconsFragment extends MaterialPreferenceToolbarFragment {
|
||||
drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_bug_outline_28, null);
|
||||
}
|
||||
|
||||
addPreferenceDrawable(this, icon, iconname, "", drawable, preference -> {
|
||||
sendToast(requireContext().getString(R.string.unavailable_icon_warning));
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), icon, iconname, "", drawable, preference -> {
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.unavailable_icon_warning));
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,7 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.isVkxInstalled;
|
||||
import static ru.vtosters.lite.music.LastFMScrobbler.isLoggedIn;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
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.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.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
@@ -24,31 +9,39 @@ import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.core.network.Network;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.downloaders.AudioDownloader;
|
||||
import ru.vtosters.lite.downloaders.VideoDownloader;
|
||||
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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.isVkxInstalled;
|
||||
import static ru.vtosters.lite.music.LastFMScrobbler.isLoggedIn;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.*;
|
||||
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.getSTextAttr;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
private static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
@@ -56,7 +49,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);
|
||||
@@ -91,6 +84,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 -> {
|
||||
@@ -140,10 +139,14 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
findPreference("select_photo_search_engine").setOnPreferenceClickListener(preference -> {
|
||||
var items = Arrays.asList(
|
||||
new ImagineArrayAdapter.ImagineArrayAdapterItem(null, "По выбору"),
|
||||
new ImagineArrayAdapter.ImagineArrayAdapterItem(R.drawable.yandex, "Yandex"),
|
||||
new ImagineArrayAdapter.ImagineArrayAdapterItem(R.drawable.google, "Google"),
|
||||
new ImagineArrayAdapter.ImagineArrayAdapterItem(R.drawable.microsoft, "Bing")
|
||||
);
|
||||
new ImagineArrayAdapter.ImagineArrayAdapterItem(R.drawable.microsoft, "Bing"),
|
||||
new ImagineArrayAdapter.ImagineArrayAdapterItem(null, "TraceMoe"),
|
||||
new ImagineArrayAdapter.ImagineArrayAdapterItem(null, "Ascii2d"),
|
||||
new ImagineArrayAdapter.ImagineArrayAdapterItem(null, "Saucenao")
|
||||
);
|
||||
|
||||
var adapter = new ImagineArrayAdapter(getContext(), items);
|
||||
adapter.setSelected(getPreferences().getInt("search_engine", 0));
|
||||
@@ -156,6 +159,8 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
.show();
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("maxquality").setEnabled(isEnableExternalOpening());
|
||||
}
|
||||
|
||||
private void lastfmAuth(Context ctx) {
|
||||
@@ -166,7 +171,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());
|
||||
@@ -177,7 +182,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);
|
||||
@@ -276,6 +281,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) {
|
||||
@@ -292,9 +302,4 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlmedia;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
findPreference("vkme_notifs").setOnPreferenceClickListener(new MessagesFragment.restart());
|
||||
findPreference("systememoji").setOnPreferenceClickListener(new MessagesFragment.restart());
|
||||
findPreference("wallpapers").setOnPreferenceClickListener(new MessagesFragment.openwp());
|
||||
findPreference("promotedstickers").setOnPreferenceChangeListener(new clearStickersCache());
|
||||
|
||||
findPreference("autotranslate").setEnabled(!autoalltranslate());
|
||||
|
||||
@@ -79,7 +78,6 @@ public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
findPreference("autotranslate").setEnabled(!autoalltranslate());
|
||||
findPreference("vkme_notifs").setEnabled(vkme());
|
||||
findPreference("promotedstickers").setOnPreferenceChangeListener(new clearStickersCache());
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
@@ -88,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) {
|
||||
@@ -102,16 +105,6 @@ public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
}
|
||||
|
||||
public class clearStickersCache implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
SharedPreferences prefs2 = getContext().getSharedPreferences("stickers_storage", Context.MODE_PRIVATE);
|
||||
prefs2.edit().clear().commit();
|
||||
Stickers.l.c();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class openwp implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
@@ -122,9 +115,4 @@ public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlmessages;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,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);
|
||||
@@ -95,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();
|
||||
@@ -187,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)
|
||||
@@ -251,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) -> {
|
||||
@@ -262,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) {
|
||||
@@ -368,9 +380,4 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
return R.string.vtlother;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,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.ItemMovingCallback;
|
||||
import ru.vtosters.lite.ui.components.SuperAppEditorManager;
|
||||
@@ -70,6 +71,8 @@ public class SuperAppEditorFragment 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);
|
||||
@@ -84,6 +87,8 @@ public class SuperAppEditorFragment 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);
|
||||
|
||||
@@ -1,34 +1,17 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.getEmuiVersionCode;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.getMiuiUiVersionCode;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.getMiuiUiVersionIncrementalCode;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.getMiuiUiVersionName;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.getOneUiMajorVersion;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.getOneUiMinorVersion;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.hasMiuiIncrCode;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.isEMUI;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.isFlyme;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.isMIUI;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.isOneUi;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.isSamsung;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.isVivo;
|
||||
import static ru.vtosters.lite.deviceinfo.OEMDetector.isZenUI;
|
||||
import static ru.vtosters.lite.ui.PreferencesUtil.addPreference;
|
||||
import static ru.vtosters.lite.ui.PreferencesUtil.addPreferenceCategory;
|
||||
import static ru.vtosters.lite.utils.About.getBuildNumber;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.isTablet;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.Preferences.isValidSignature;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
import ru.vtosters.lite.deviceinfo.OEMDetector;
|
||||
import ru.vtosters.lite.ui.PreferenceFragmentUtils;
|
||||
import ru.vtosters.lite.utils.About;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
|
||||
public class SystemInfo extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
@@ -37,8 +20,8 @@ public class SystemInfo extends MaterialPreferenceToolbarFragment {
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(R.xml.empty);
|
||||
|
||||
var oneUiMajorVersion = String.valueOf(getOneUiMajorVersion());
|
||||
var oneUiMinorVersion = String.valueOf(getOneUiMinorVersion());
|
||||
var oneUiMajorVersion = String.valueOf(OEMDetector.getOneUiMajorVersion());
|
||||
var oneUiMinorVersion = String.valueOf(OEMDetector.getOneUiMinorVersion());
|
||||
var sdkVersion = String.valueOf(Build.VERSION.SDK_INT);
|
||||
var productName = Build.PRODUCT;
|
||||
var deviceName = Build.DEVICE;
|
||||
@@ -46,145 +29,145 @@ public class SystemInfo extends MaterialPreferenceToolbarFragment {
|
||||
var manufacturerName = Build.MANUFACTURER;
|
||||
var brandName = Build.BRAND;
|
||||
var modelName = Build.MODEL;
|
||||
var miuiUiVersionName = getMiuiUiVersionName();
|
||||
var miuiIncrementalCodeName = getMiuiUiVersionIncrementalCode();
|
||||
var miuiUiVersionCodeName = getMiuiUiVersionCode();
|
||||
var emuiVersionCode = getEmuiVersionCode();
|
||||
var miuiUiVersionName = OEMDetector.getMiuiUiVersionName();
|
||||
var miuiIncrementalCodeName = OEMDetector.getMiuiUiVersionIncrementalCode();
|
||||
var miuiUiVersionCodeName = OEMDetector.getMiuiUiVersionCode();
|
||||
var emuiVersionCode = OEMDetector.getEmuiVersionCode();
|
||||
var packageName = requireContext().getPackageName();
|
||||
var commit = getBuildNumber();
|
||||
var commit = About.getBuildNumber();
|
||||
|
||||
var isMiui = isMIUI();
|
||||
var isFlyme = isFlyme();
|
||||
var isSamsung = isSamsung();
|
||||
var isOneUi = isOneUi();
|
||||
var isVivo = isVivo();
|
||||
var isZenUI = isZenUI();
|
||||
var isEMUI = isEMUI();
|
||||
var hasMiuiIncrCode = hasMiuiIncrCode();
|
||||
var isMiui = OEMDetector.isMIUI();
|
||||
var isFlyme = OEMDetector.isFlyme();
|
||||
var isSamsung = OEMDetector.isSamsung();
|
||||
var isOneUi = OEMDetector.isOneUi();
|
||||
var isVivo = OEMDetector.isVivo();
|
||||
var isZenUI = OEMDetector.isZenUI();
|
||||
var isEMUI = OEMDetector.isEMUI();
|
||||
var hasMiuiIncrCode = OEMDetector.hasMiuiIncrCode();
|
||||
|
||||
var isValidSignature = isValidSignature();
|
||||
var isTablet = isTablet();
|
||||
var isValidSignature = Preferences.isValidSignature();
|
||||
var isTablet = AndroidUtils.isTablet();
|
||||
|
||||
addPreferenceCategory(this, "App information");
|
||||
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), "App information");
|
||||
|
||||
addPreference(this, "", "Package name", packageName, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "Package name", packageName, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", packageName));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", "Commit", commit, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "Commit", commit, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", commit));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", "Valid Signature", "Value: " + isValidSignature, 0, null);
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "Valid Signature", "Value: " + isValidSignature, 0, null);
|
||||
|
||||
addPreference(this, "", "isTablet", "Value: " + isTablet, 0, null);
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "isTablet", "Value: " + isTablet, 0, null);
|
||||
|
||||
addPreferenceCategory(this, "System information");
|
||||
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), "System information");
|
||||
|
||||
addPreference(this, "", "SDK Version", sdkVersion, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "SDK Version", sdkVersion, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", sdkVersion));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", "Product Name", productName, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "Product Name", productName, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", productName));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", "Device Name", deviceName, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "Device Name", deviceName, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", deviceName));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", "Board Name", boardName, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "Board Name", boardName, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", boardName));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", "Manufacturer Name", manufacturerName, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "Manufacturer Name", manufacturerName, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", manufacturerName));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", "Brand Name", brandName, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "Brand Name", brandName, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", brandName));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", "Model Name", modelName, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "Model Name", modelName, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", modelName));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreferenceCategory(this, "OEM Information");
|
||||
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), "OEM Information");
|
||||
|
||||
if (isOneUi){
|
||||
addPreference(this, "", "OneUiMajorVersion", oneUiMajorVersion, 0, preference -> {
|
||||
if (isOneUi) {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "OneUiMajorVersion", oneUiMajorVersion, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", oneUiMajorVersion));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", "OneUiMinorVersion", oneUiMinorVersion, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "OneUiMinorVersion", oneUiMinorVersion, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", oneUiMinorVersion));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
} else if (isMiui) {
|
||||
addPreference(this, "", "miuiUiVersionName", miuiUiVersionName, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "miuiUiVersionName", miuiUiVersionName, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", miuiUiVersionName));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", "miuiUiVersionCodeName", miuiUiVersionCodeName, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "miuiUiVersionCodeName", miuiUiVersionCodeName, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", miuiUiVersionCodeName));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
|
||||
if (hasMiuiIncrCode) {
|
||||
addPreference(this, "", "miuiIncrementalCodeName", miuiIncrementalCodeName, 0, preference -> {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "miuiIncrementalCodeName", miuiIncrementalCodeName, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", miuiIncrementalCodeName));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
}
|
||||
} else if (isEMUI){
|
||||
addPreference(this, "", "emuiVersionCode", emuiVersionCode, 0, preference -> {
|
||||
} else if (isEMUI) {
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "emuiVersionCode", emuiVersionCode, 0, preference -> {
|
||||
((ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", emuiVersionCode));
|
||||
sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
AndroidUtils.sendToast(requireContext().getString(R.string.copied_to_clipboard));
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
addPreference(this, "", "No info", "No information about OEM", 0, null);
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "No info", "No information about OEM", 0, null);
|
||||
}
|
||||
|
||||
addPreferenceCategory(this, "OEM List");
|
||||
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), "OEM List");
|
||||
|
||||
addPreference(this, "", "isOneUi", "Value: " + isOneUi, 0, null);
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "isOneUi", "Value: " + isOneUi, 0, null);
|
||||
|
||||
addPreference(this, "", "isMiui", "Value: " + isMiui, 0, null);
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "isMiui", "Value: " + isMiui, 0, null);
|
||||
|
||||
addPreference(this, "", "isEMUI", "Value: " + isEMUI, 0, null);
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "isEMUI", "Value: " + isEMUI, 0, null);
|
||||
|
||||
addPreference(this, "", "isFlyme", "Value: " + isFlyme, 0, null);
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "isFlyme", "Value: " + isFlyme, 0, null);
|
||||
|
||||
addPreference(this, "", "isSamsung", "Value: " + isSamsung, 0, null);
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "isSamsung", "Value: " + isSamsung, 0, null);
|
||||
|
||||
addPreference(this, "", "isVivo", "Value: " + isVivo, 0, null);
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "isVivo", "Value: " + isVivo, 0, null);
|
||||
|
||||
addPreference(this, "", "isZenUI", "Value: " + isZenUI, 0, null);
|
||||
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", "isZenUI", "Value: " + isZenUI, 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user