Compare commits
197
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52f69c792d | ||
|
|
33f150eb43 | ||
|
|
e165f388f5 | ||
|
|
761ff263be | ||
|
|
8918f203fc | ||
|
|
6039d0cf43 | ||
|
|
af902f945e | ||
|
|
a90d96b00f | ||
|
|
550d3dadd8 | ||
|
|
82720adb61 | ||
|
|
2a3e12b39a | ||
|
|
87407b0007 | ||
|
|
ff2e33d9a2 | ||
|
|
61b6b0a1ec | ||
|
|
9db18f526a | ||
|
|
043253ffff | ||
|
|
756ab2b7c0 | ||
|
|
2ba5aef993 | ||
|
|
ab3bd09ab7 | ||
|
|
7990d269aa | ||
|
|
fffda61a83 | ||
|
|
d817ccd292 | ||
|
|
02de3699cc | ||
|
|
81b214bcff | ||
|
|
5dcf50fdc2 | ||
|
|
81d4f9ec99 | ||
|
|
29596b5dd1 | ||
|
|
b789840498 | ||
|
|
fce6c2b14f | ||
|
|
f2ac2c6a37 | ||
|
|
61881f4e9d | ||
|
|
92f74aa5fb | ||
|
|
0c968de977 | ||
|
|
51efc8f4c6 | ||
|
|
4dbf1756e1 | ||
|
|
8d4d88e099 | ||
|
|
dd953d39e7 | ||
|
|
4902938016 | ||
|
|
54de4fd060 | ||
|
|
6d9f3029d3 | ||
|
|
332fe678b9 | ||
|
|
04eee5cc26 | ||
|
|
bc94f1ac77 | ||
|
|
fc423d5ccd | ||
|
|
f0993bee15 | ||
|
|
22ef4bd646 | ||
|
|
c4cc678c82 | ||
|
|
350c25faff | ||
|
|
89ea35dd82 | ||
|
|
cd858266a8 | ||
|
|
0549b07c49 | ||
|
|
a7fd5536f6 | ||
|
|
1397653b55 | ||
|
|
ec1a0fc2d5 | ||
|
|
b75dca5515 | ||
|
|
f31fade75a | ||
|
|
347e0fb9c4 | ||
|
|
bf1a73f606 | ||
|
|
82e268ffa7 | ||
|
|
f3acbf74a8 | ||
|
|
7126af6240 | ||
|
|
ef2946a700 | ||
|
|
8821574412 | ||
|
|
8257a374da | ||
|
|
3985593842 | ||
|
|
92d8c9a90d | ||
|
|
6f9c325b0d | ||
|
|
1010821cf4 | ||
|
|
012dfa7063 | ||
|
|
01adf656e2 | ||
|
|
bb64ed8d2a | ||
|
|
1ec78a8fbd | ||
|
|
f1436ebbde | ||
|
|
c4efb751c9 | ||
|
|
6e902d4bca | ||
|
|
07b49a4a74 | ||
|
|
c6fdf65137 | ||
|
|
18e2554d5e | ||
|
|
04488314b5 | ||
|
|
3eec52db3b | ||
|
|
132df6080e | ||
|
|
d8f91bc730 | ||
|
|
270c2af5c1 | ||
|
|
99c500ed69 | ||
|
|
8174be1768 | ||
|
|
a88f59bac1 | ||
|
|
1eaa3748c4 | ||
|
|
27836f72f5 | ||
|
|
70e048a1ad | ||
|
|
e915b26918 | ||
|
|
8a6a92f77b | ||
|
|
cb492b5949 | ||
|
|
f15e4c004d | ||
|
|
f7f2cf3e58 | ||
|
|
578fa86f19 | ||
|
|
a9bcb19ebf | ||
|
|
cf6b993172 | ||
|
|
145a6a668b | ||
|
|
6b2752db67 | ||
|
|
58fb6224f4 | ||
|
|
b6406bcebf | ||
|
|
6c7733f1a0 | ||
|
|
5373002666 | ||
|
|
4005ac2ef1 | ||
|
|
30de30cf64 | ||
|
|
0feeacb533 | ||
|
|
de511d15a6 | ||
|
|
dc1be1434a | ||
|
|
6b88996962 | ||
|
|
bb35b2b252 | ||
|
|
b2f1cfea5e | ||
|
|
2748ec6902 | ||
|
|
17b9c7075e | ||
|
|
fd070323b0 | ||
|
|
03a43326b7 | ||
|
|
a0b28b6c12 | ||
|
|
5d46edb91a | ||
|
|
0e751533b5 | ||
|
|
32d5ba792a | ||
|
|
eb96137c3a | ||
|
|
09f7a07226 | ||
|
|
251f9935aa | ||
|
|
a75070f8d3 | ||
|
|
972921a05c | ||
|
|
3b2586ade5 | ||
|
|
58ea05cc9d | ||
|
|
441baac671 | ||
|
|
a1efd38048 | ||
|
|
d8be2fe7b7 | ||
|
|
27fdbf2407 | ||
|
|
fd954f5bab | ||
|
|
3295e40231 | ||
|
|
f88596025f | ||
|
|
9c5f584d1b | ||
|
|
537a3759d0 | ||
|
|
f2fcc5f4d1 | ||
|
|
db651c462a | ||
|
|
4f06fda96d | ||
|
|
1344e88b95 | ||
|
|
23dd5a71e0 | ||
|
|
810e5c72c1 | ||
|
|
045daeea47 | ||
|
|
f45de44c75 | ||
|
|
d2911e5b6b | ||
|
|
576890189c | ||
|
|
5ce6ab3aa8 | ||
|
|
1451e2d3ac | ||
|
|
95958a85e9 | ||
|
|
9f2b3edbe8 | ||
|
|
ee4249c688 | ||
|
|
2f46c193dd | ||
|
|
09807a2954 | ||
|
|
163cd44dcc | ||
|
|
2bdff722d4 | ||
|
|
e206e85324 | ||
|
|
40159a2a9f | ||
|
|
54d59e1f2f | ||
|
|
1b797325f0 | ||
|
|
63c3c0ee32 | ||
|
|
4b6a7aeb84 | ||
|
|
38f65997a6 | ||
|
|
d718851d0c | ||
|
|
b30ad26f54 | ||
|
|
5f5fb650f2 | ||
|
|
76260981c5 | ||
|
|
ceb84ed6f6 | ||
|
|
e8a2c3af56 | ||
|
|
80e78fa2c1 | ||
|
|
7b35501461 | ||
|
|
c9cfc5e749 | ||
|
|
f0a915be05 | ||
|
|
f2b8624cc4 | ||
|
|
ccaa10d224 | ||
|
|
6325d8fe68 | ||
|
|
e243522f95 | ||
|
|
d87a59bcb0 | ||
|
|
724fafc3fd | ||
|
|
8c03ab60fc | ||
|
|
985ced6e3c | ||
|
|
88339feb12 | ||
|
|
2bcf5d1c2d | ||
|
|
77f9c60be7 | ||
|
|
76468d8863 | ||
|
|
c17e604db6 | ||
|
|
1a96f77aa1 | ||
|
|
3fd0757fd4 | ||
|
|
989075a3d2 | ||
|
|
802d88cad7 | ||
|
|
95a0451c6b | ||
|
|
3b83f05bf0 | ||
|
|
c7d350f5b1 | ||
|
|
d3eeaf5f23 | ||
|
|
4dcea46be7 | ||
|
|
96de61fd15 | ||
|
|
47f4c5c911 | ||
|
|
fcbf9238cf | ||
|
|
4a8a2adb4e |
@@ -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/`
|
||||
|
||||
+62
-3
@@ -1,15 +1,24 @@
|
||||
import java.nio.file.Files
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipFile
|
||||
import java.util.zip.ZipInputStream
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
|
||||
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'net.nemerosa.versioning' version '2.15.1'
|
||||
}
|
||||
|
||||
def smaliFolder = projectDir.toPath().resolve("../smali").normalize()
|
||||
def scriptsFolder = projectDir.toPath().resolve("../scripts").normalize()
|
||||
|
||||
versionFile {
|
||||
File moduleDir = projectDir
|
||||
file = new File(moduleDir.getAbsolutePath() + "/src/main/assets/version.properties")
|
||||
file = projectDir.toPath().resolve("src/main/assets/version.properties").toFile()
|
||||
}
|
||||
|
||||
task cleanVersionFile {
|
||||
projectDir.toPath().resolve("src/main/assets/version.properties").toFile().delete()
|
||||
}
|
||||
|
||||
task exportDex {
|
||||
@@ -69,7 +78,13 @@ task exportDex {
|
||||
|
||||
android {
|
||||
compileSdkVersion 32
|
||||
buildToolsVersion '33.0.0'
|
||||
buildToolsVersion '32.0.0'
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java.srcDirs += 'build/generated/aidl_source_output_dir/release/out'
|
||||
}
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId "ru.vtosters.lite.utils.lite"
|
||||
@@ -94,3 +109,47 @@ 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'
|
||||
}
|
||||
}
|
||||
|
||||
exportDex.dependsOn('assembleRelease')
|
||||
clean.dependsOn('cleanVersionFile')
|
||||
versionFile.dependsOn('cleanVersionFile')
|
||||
preBuild.dependsOn('versionFile')
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+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")
|
||||
|
||||
@@ -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,620 +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 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);
|
||||
|
||||
@@ -1,40 +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.util.Log;
|
||||
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;
|
||||
@@ -62,58 +57,60 @@ 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);
|
||||
}
|
||||
|
||||
final Context finalContext = context != null ? context : LifecycleUtils.getCurrentActivity();
|
||||
|
||||
var adapter = new ArrayAdapter(finalContext, 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(finalContext)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,7 @@ public class DockBarInjector {
|
||||
item.setStaticMode(true);
|
||||
item.setIconsMode(false);
|
||||
item.setShiftingMode(false);
|
||||
item.setTextColor(getCSTDock());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,11 +41,11 @@ public class GcmHook {
|
||||
}
|
||||
|
||||
public static String requestTokenV2(String orig) {
|
||||
return isValidSignature() ? "eyJhbGciOiAibm9uZSJ9eyJub25jZSI6ICJudWxsIn0=" : "e251bGx9";
|
||||
return isValidSignature() ? "eyJhbGciOiAibm9uZSJ9.eyJub25jZSI6ICJ0ZXN0PT0ifQ." : "e251bGx9";
|
||||
}
|
||||
|
||||
public static String requestToken(String orig) {
|
||||
return requestToken();
|
||||
return "yssp9o9p9pamz5t-nvmq8spgwtin3e0==";
|
||||
}
|
||||
|
||||
public static String requestToken() {
|
||||
|
||||
@@ -34,113 +34,125 @@ 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) {
|
||||
try {
|
||||
int id = orig.getInt("id");
|
||||
|
||||
public static JSONObject profileButton(JSONObject orig) throws JSONException {
|
||||
var id = orig.getInt("id");
|
||||
var newItem = new JSONArray();
|
||||
|
||||
var newItem = new JSONArray();
|
||||
if (orig.has("buttons")) {
|
||||
newItem = orig.getJSONArray("buttons");
|
||||
}
|
||||
|
||||
if (orig.has("buttons")) {
|
||||
newItem = orig.getJSONArray("buttons");
|
||||
if (!haveDonateButton() && id == AccountManagerUtils.getUserId()) {
|
||||
newItem.put(donateRecomm());
|
||||
}
|
||||
|
||||
if (!orig.has("type") && AccountManagerUtils.isVKTester()) {
|
||||
newItem.put(vktesters(id));
|
||||
}
|
||||
|
||||
orig.put("buttons", newItem);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!haveDonateButton() && id == AccountManagerUtils.getUserId()) {
|
||||
newItem.put(donateRecomm());
|
||||
}
|
||||
|
||||
if (!orig.has("type") && AccountManagerUtils.isVKTester()) {
|
||||
newItem.put(vktesters(id));
|
||||
}
|
||||
|
||||
orig.put("buttons", newItem);
|
||||
|
||||
return orig;
|
||||
}
|
||||
|
||||
public static JSONObject donateRecomm() throws JSONException {
|
||||
var title = AndroidUtils.getString(R.string.donate_to_vtl);
|
||||
var link = "https://vk.com/vtosters_official";
|
||||
var text_color = "2D81E0";
|
||||
public static JSONObject donateRecomm() {
|
||||
try {
|
||||
var title = AndroidUtils.getString(R.string.donate_to_vtl);
|
||||
var link = "https://vk.com/vtosters_official";
|
||||
var text_color = "2D81E0";
|
||||
|
||||
var json = new JSONObject();
|
||||
var icons = new JSONArray();
|
||||
var json = new JSONObject();
|
||||
var icons = new JSONArray();
|
||||
|
||||
var action = new JSONObject();
|
||||
action.put("target", "internal");
|
||||
action.put("type", "open_url"); // may be open_url, open_internal_vkui, open_game, help_hint, show_full_post, open_vkapp, show_recommendations_for_post and groups_advertisement
|
||||
action.put("url", link);
|
||||
json.put("action", action);
|
||||
var action = new JSONObject().put("target", "internal");
|
||||
action.put("type", "open_url"); // may be open_url, open_internal_vkui, open_game, help_hint, show_full_post, open_vkapp, show_recommendations_for_post and groups_advertisement
|
||||
action.put("url", link);
|
||||
json.put("action", action);
|
||||
|
||||
json.put("title", title);
|
||||
json.put("title", title);
|
||||
|
||||
var icon1 = new JSONObject();
|
||||
icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
|
||||
icon1.put("width", "20");
|
||||
icon1.put("height", "20");
|
||||
icons.put(icon1);
|
||||
var icon1 = new JSONObject();
|
||||
icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
|
||||
icon1.put("width", "20");
|
||||
icon1.put("height", "20");
|
||||
icons.put(icon1);
|
||||
|
||||
var icon2 = new JSONObject();
|
||||
icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
|
||||
icon2.put("width", "40");
|
||||
icon2.put("height", "40");
|
||||
icons.put(icon2);
|
||||
var icon2 = new JSONObject();
|
||||
icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
|
||||
icon2.put("width", "40");
|
||||
icon2.put("height", "40");
|
||||
icons.put(icon2);
|
||||
|
||||
var icon3 = new JSONObject();
|
||||
icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png");
|
||||
icon3.put("width", "80");
|
||||
icon3.put("height", "80");
|
||||
icons.put(icon3);
|
||||
var icon3 = new JSONObject();
|
||||
icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png");
|
||||
icon3.put("width", "80");
|
||||
icon3.put("height", "80");
|
||||
icons.put(icon3);
|
||||
|
||||
json.put("icons", icons);
|
||||
json.put("icons", icons);
|
||||
|
||||
json.put("text_color", text_color);
|
||||
json.put("text_color", text_color);
|
||||
|
||||
return json;
|
||||
return json;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject vktesters(int id) throws JSONException {
|
||||
var title = AndroidUtils.getString(R.string.tester_profile);
|
||||
var text_color = "2D81E0";
|
||||
var link = "https://" + getStatic() + "/bugs?lang=" + LangUtils.a() + "#/reporter" + id;
|
||||
public static JSONObject vktesters(int id) {
|
||||
try {
|
||||
var title = AndroidUtils.getString(R.string.tester_profile);
|
||||
var text_color = "2D81E0";
|
||||
var link = "https://" + getStatic() + "/bugs?lang=" + LangUtils.a() + "#/reporter" + id;
|
||||
|
||||
var json = new JSONObject();
|
||||
var icons = new JSONArray();
|
||||
var json = new JSONObject();
|
||||
var icons = new JSONArray();
|
||||
|
||||
var action = new JSONObject();
|
||||
action.put("target", "internal");
|
||||
action.put("type", "open_internal_vkui");
|
||||
action.put("url", link);
|
||||
json.put("action", action);
|
||||
var action = new JSONObject();
|
||||
action.put("target", "internal");
|
||||
action.put("type", "open_internal_vkui");
|
||||
action.put("url", link);
|
||||
json.put("action", action);
|
||||
|
||||
json.put("title", title);
|
||||
json.put("title", title);
|
||||
|
||||
var icon1 = new JSONObject();
|
||||
icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
|
||||
icon1.put("width", "20");
|
||||
icon1.put("height", "20");
|
||||
icons.put(icon1);
|
||||
var icon1 = new JSONObject();
|
||||
icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
|
||||
icon1.put("width", "20");
|
||||
icon1.put("height", "20");
|
||||
icons.put(icon1);
|
||||
|
||||
var icon2 = new JSONObject();
|
||||
icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
|
||||
icon2.put("width", "40");
|
||||
icon2.put("height", "40");
|
||||
icons.put(icon2);
|
||||
var icon2 = new JSONObject();
|
||||
icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
|
||||
icon2.put("width", "40");
|
||||
icon2.put("height", "40");
|
||||
icons.put(icon2);
|
||||
|
||||
var icon3 = new JSONObject();
|
||||
icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png");
|
||||
icon3.put("width", "80");
|
||||
icon3.put("height", "80");
|
||||
icons.put(icon3);
|
||||
var icon3 = new JSONObject();
|
||||
icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png");
|
||||
icon3.put("width", "80");
|
||||
icon3.put("height", "80");
|
||||
icons.put(icon3);
|
||||
|
||||
json.put("icons", icons);
|
||||
json.put("icons", icons);
|
||||
|
||||
json.put("text_color", text_color);
|
||||
json.put("text_color", text_color);
|
||||
return json;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return json;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject convBar(JSONObject orig) throws JSONException {
|
||||
public static JSONObject convBar(JSONObject orig) {
|
||||
var peerid = Objects.requireNonNull(orig.optJSONObject("peer")).optInt("id");
|
||||
|
||||
var pic = "https://image.pngaaa.com/641/326641-middle.png"; // can be null
|
||||
@@ -169,25 +181,30 @@ public class JsonInjectors {
|
||||
|
||||
if (!dev()) return orig.optJSONObject("conversation_bar"); // for devs only
|
||||
|
||||
var json = new JSONObject();
|
||||
try {
|
||||
var json = new JSONObject();
|
||||
|
||||
var buttonsJson = new JSONObject();
|
||||
buttonsJson.put("layout", "tertiary");
|
||||
buttonsJson.put("text", linktitle);
|
||||
buttonsJson.put("type", "link");
|
||||
buttonsJson.put("link", link);
|
||||
var buttonsJson = new JSONObject();
|
||||
buttonsJson.put("layout", "tertiary");
|
||||
buttonsJson.put("text", linktitle);
|
||||
buttonsJson.put("type", "link");
|
||||
buttonsJson.put("link", link);
|
||||
|
||||
var buttonsjson = new JSONArray(); // max 3 buttons in array
|
||||
if (hasButton) buttonsjson.put(buttonsJson);
|
||||
var buttonsjson = new JSONArray(); // max 3 buttons in array
|
||||
if (hasButton) buttonsjson.put(buttonsJson);
|
||||
|
||||
json.put("name", "group_admin_welcome");
|
||||
json.put("text", text);
|
||||
json.put("buttons", buttonsjson);
|
||||
if (hasIcon && isPicture) {
|
||||
json.put("icon", pic);
|
||||
json.put("name", "group_admin_welcome");
|
||||
json.put("text", text);
|
||||
json.put("buttons", buttonsjson);
|
||||
if (hasIcon && isPicture) {
|
||||
json.put("icon", pic);
|
||||
}
|
||||
return json;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return json;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject menu(JSONObject orig) throws JSONException {
|
||||
|
||||
@@ -18,6 +18,8 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.vk.core.dialogs.actionspopup.ActionsPopup;
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
import com.vk.core.ui.themes.VKThemeHelper;
|
||||
import com.vk.core.util.ContextExtKt;
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vk.dto.common.AttachmentWithMedia;
|
||||
import com.vk.dto.common.ImageSize;
|
||||
@@ -97,9 +99,7 @@ public class PhotoViewer {
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public static void addMenuItems(AttachmentWithMedia attachment, ActionsPopup.b actionPopup, int i, boolean z) {
|
||||
actionPopup.a(R.string.search_photo_content,
|
||||
ThemesUtils.isDarkTheme()
|
||||
? AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_menu_search_outline_28)
|
||||
: new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_menu_search_outline_28), ThemesUtils.getAccentColor()),
|
||||
ContextExtKt.b(AndroidUtils.getGlobalContext(), R.drawable.ic_menu_search_outline_28, VKThemeHelper.g(R.attr.header_tint)),
|
||||
false,
|
||||
() -> {
|
||||
if (attachment instanceof PhotoAttachment) {
|
||||
@@ -119,9 +119,7 @@ public class PhotoViewer {
|
||||
}
|
||||
);
|
||||
actionPopup.a(R.string.copy_photo_url_content,
|
||||
!ThemesUtils.isDarkTheme()
|
||||
? new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_copy_outline_28), ThemesUtils.getAccentColor())
|
||||
: new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_copy_outline_28), Color.WHITE),
|
||||
ContextExtKt.b(AndroidUtils.getGlobalContext(), R.drawable.ic_copy_outline_28, VKThemeHelper.g(R.attr.header_tint)),
|
||||
false,
|
||||
() -> {
|
||||
if (attachment instanceof PhotoAttachment) {
|
||||
@@ -141,10 +139,7 @@ public class PhotoViewer {
|
||||
}
|
||||
);
|
||||
actionPopup.a(R.string.open_original_photo_content,
|
||||
ThemesUtils.isDarkTheme()
|
||||
? AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_link_outline_28)
|
||||
: new RecoloredDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_link_outline_28),
|
||||
ThemesUtils.getAccentColor()),
|
||||
ContextExtKt.b(AndroidUtils.getGlobalContext(), R.drawable.ic_link_outline_28, VKThemeHelper.g(R.attr.header_tint)),
|
||||
false,
|
||||
() -> {
|
||||
if (attachment instanceof PhotoAttachment) {
|
||||
@@ -234,8 +229,7 @@ public class PhotoViewer {
|
||||
}
|
||||
|
||||
private static void searchWithGoogle(String url) {
|
||||
openUrl("https://www.google.ru/searchbyimage?image_url=" +
|
||||
URLEncoder.encode(url));
|
||||
openUrl("https://www.google.com/searchbyimage?image_url=" + URLEncoder.encode(url) + "&client=app");
|
||||
}
|
||||
|
||||
private static void searchWithBing(String url) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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("\"");
|
||||
|
||||
|
||||
@@ -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 -> {
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.vtosters.lite.R.color.*;
|
||||
|
||||
public class ColorReferences {
|
||||
public static List<Integer> accentColors = Arrays.asList(
|
||||
Color.parseColor("#3f8ae0"), // azure_300 (light accent)
|
||||
Color.parseColor("#4986cc"), // azure_a400
|
||||
Color.parseColor("#528bcc"), // another light accent
|
||||
Color.parseColor("#71aaeb"), // vk_sky_300 (dark accent)
|
||||
Color.parseColor("#5181b8"), // header_blue
|
||||
Color.parseColor("#5a9eff"),
|
||||
Color.parseColor("#5692d7"),
|
||||
Color.parseColor("#5c9ce6"),
|
||||
Color.parseColor("#518bcc"),
|
||||
Color.parseColor("#74a2d6")
|
||||
);
|
||||
|
||||
public static List<Integer> mutedAccentColors = Arrays.asList(
|
||||
Color.parseColor("#663f8ae0"),
|
||||
Color.parseColor("#19528bcc"),
|
||||
Color.parseColor("#66528bcc"),
|
||||
Color.parseColor("#1971aaeb"),
|
||||
Color.parseColor("#665181b8"),
|
||||
Color.parseColor("#1a003973"),
|
||||
Color.parseColor("#a800244d"),
|
||||
Color.parseColor("#14001c3d"),
|
||||
Color.parseColor("#3d001c3d"),
|
||||
Color.parseColor("#67a5eb"),
|
||||
Color.parseColor("#45678f"),
|
||||
Color.parseColor("#6645678f"),
|
||||
Color.parseColor("#0099cc"),
|
||||
Color.parseColor("#664986cc")
|
||||
);
|
||||
|
||||
public static List<Integer> accents = Arrays.asList(
|
||||
viewer_retry_button_text_color,
|
||||
azure_300,
|
||||
picker_camera_button,
|
||||
music_check_button_bg_pressed,
|
||||
notification_color,
|
||||
music_text_counter,
|
||||
music_follow_button_bg_pressed,
|
||||
music_blue_button_normal,
|
||||
music_check_button_bg_normal,
|
||||
vk_terms_link,
|
||||
vk_blue_200,
|
||||
accent_blue,
|
||||
azure_A400,
|
||||
vk_azure_A400,
|
||||
blue,
|
||||
blue_200,
|
||||
vk_blue_300,
|
||||
vk_blue_400,
|
||||
blue_300,
|
||||
blue_400,
|
||||
cool_blue,
|
||||
cornflower_blue,
|
||||
cornflower_blue_two,
|
||||
dot_unread,
|
||||
fave_promo_btn_pressed,
|
||||
header_blue,
|
||||
colorAccent,
|
||||
live_emoji_butt_hide,
|
||||
music_action_button_blue,
|
||||
name,
|
||||
picker_blue,
|
||||
picker_blue_pressed,
|
||||
picker_tab_bg_selected,
|
||||
picker_tab_text_selected,
|
||||
sharing_blue_btn_normal,
|
||||
sharing_blue_btn_pressed,
|
||||
vk_sky_300,
|
||||
vk_blue_A400,
|
||||
blue_A400,
|
||||
sky_300,
|
||||
text_blue,
|
||||
tip_background,
|
||||
tw__blue_default,
|
||||
tw__blue_pressed,
|
||||
vkim_msg_sending_ic,
|
||||
vkim_playing_drawable_rect,
|
||||
vk_white_blue32,
|
||||
date_picker_selector,
|
||||
post_suggest_blue,
|
||||
list_dialog_blue,
|
||||
music_tab_bg_normal,
|
||||
toolbar_blue_background,
|
||||
toolbar_blue_statusBarColorBack
|
||||
);
|
||||
|
||||
public static List<Integer> mutedAccents = Arrays.asList(
|
||||
blue_200_muted,
|
||||
vk_blue_200_muted,
|
||||
white_blue32,
|
||||
vk_white_blue32,
|
||||
header_blue_opacity16,
|
||||
black_blue45_alpha10,
|
||||
music_check_button_bg_checked,
|
||||
vk_black_blue45_alpha10,
|
||||
black_blue30_alpha66,
|
||||
vk_black_blue30_alpha66,
|
||||
attachpicker_item_background,
|
||||
black_blue24_alpha8,
|
||||
music_placeholder_artist_bg,
|
||||
black_blue24_alpha24,
|
||||
vk_black_blue24_alpha24,
|
||||
azure_100_muted,
|
||||
vk_azure_100_muted,
|
||||
muted_blue,
|
||||
blue_600,
|
||||
light_blue,
|
||||
vk_blue_600,
|
||||
muted_blue_opacity40,
|
||||
muted_blue_old,
|
||||
darker_blue,
|
||||
header_blue_opacity40
|
||||
);
|
||||
|
||||
public static boolean isAccentedColor(ColorStateList target) {
|
||||
return target != null && isAccentedColor(target.getDefaultColor());
|
||||
}
|
||||
|
||||
public static boolean isAccentedColor(int target) {
|
||||
return accentColors.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isMutedAccentedColor(ColorStateList target) {
|
||||
return target != null && isMutedAccentedColor(target.getDefaultColor());
|
||||
}
|
||||
|
||||
public static boolean isMutedAccentedColor(int target) {
|
||||
return mutedAccentColors.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isColorRefAccented(int target) {
|
||||
return accents.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isColorRefMutedAccented(int target) {
|
||||
return mutedAccents.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isCslNeedToBeThemed(ColorStateList csl) {
|
||||
int unsel = csl.getColorForState(new int[]{-android.R.attr.state_selected}, Color.BLACK);
|
||||
int sel = csl.getColorForState(new int[]{android.R.attr.state_selected}, Color.BLACK);
|
||||
boolean isUnselAccent = isAccentedColor(unsel);
|
||||
boolean isSelAccent = isAccentedColor(sel);
|
||||
return ThemesCore.isCachedAccents() && (isUnselAccent || isSelAccent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
|
||||
public class ThemesCore {
|
||||
private static final String TAG = "ThemesCore";
|
||||
|
||||
public static SparseIntArray themedColors = new SparseIntArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_DARK = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_NOMILK_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_NOMILK = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_MILK_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_MILK_DARK = new SparseBooleanArray();
|
||||
|
||||
private static boolean cachedAccents = false;
|
||||
private static int wallLightColor;
|
||||
|
||||
static {
|
||||
setExceptions();
|
||||
setThemedColors(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
public static void setExceptions() {
|
||||
ACCENT_THEME_ONLY_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_DARK.clear();
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_NOMILK.clear();
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_MILK_DARK.clear();
|
||||
|
||||
ACCENT_THEME_ONLY_LIGHT.put(R.attr.attach_picker_tab_active_background, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(R.attr.attach_picker_tab_active_text, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(R.attr.newsfeed_action_color, false);
|
||||
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(R.attr.header_background, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.header_background, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(R.attr.header_alternate_background, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.header_alternate_background, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(R.attr.header_background_before_blur, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.header_background_before_blur, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(R.attr.header_background_before_blur_alternate, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.header_background_before_blur_alternate, false);
|
||||
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(R.attr.header_tint, false);
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(R.attr.header_tint_alternate, false);
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(R.attr.toolbarIconsColor, false);
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(R.attr.header_tab_active_indicator, false);
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(R.attr.header_alternate_tab_active_indicator, false);
|
||||
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(R.attr.im_dropdown_arrow_tint, false);
|
||||
|
||||
ACCENT_THEME_ONLY_NOMILK.put(R.attr.im_dropdown_icon_color, false);
|
||||
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.icon_name, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.text_name, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.button_primary_background, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.button_secondary_foreground, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.button_tertiary_foreground, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.button_muted_foreground, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.button_outline_border, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.newsfeed_post_title_color, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.counter_primary_background, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.action_sheet_action_foreground, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.im_bubble_wallpaper_outgoing, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.im_bubble_outgoing, false);
|
||||
ACCENT_THEME_ONLY_DARK.put(R.attr.im_bubble_outgoing_highlighted, false);
|
||||
}
|
||||
|
||||
public static void setThemedColors(int accentColor) {
|
||||
int mutedAccentColor = ThemesUtils.getMutedColor(accentColor);
|
||||
|
||||
cachedAccents = true;
|
||||
themedColors.clear();
|
||||
|
||||
themedColors.put(R.attr.text_link, accentColor);
|
||||
themedColors.put(R.attr.accent, accentColor);
|
||||
themedColors.put(R.attr.newsfeed_dropdown_color, accentColor);
|
||||
themedColors.put(R.attr.icon_name, accentColor);
|
||||
|
||||
themedColors.put(R.attr.vk_accent, accentColor);
|
||||
themedColors.put(R.attr.accentColor, accentColor);
|
||||
themedColors.put(R.attr.text_name, accentColor);
|
||||
themedColors.put(R.attr.tabbar_active_icon, accentColor);
|
||||
|
||||
// themedColors.put(com.vtosters.lite.R.attr.header_background, accentColor);
|
||||
// themedColors.put(com.vtosters.lite.R.attr.header_alternate_background, accentColor);
|
||||
// themedColors.put(com.vtosters.lite.R.attr.header_background_before_blur, accentColor);
|
||||
// themedColors.put(com.vtosters.lite.R.attr.header_background_before_blur_alternate, accentColor);
|
||||
|
||||
themedColors.put(R.attr.header_tint, accentColor);
|
||||
themedColors.put(R.attr.header_tint_alternate, accentColor);
|
||||
themedColors.put(R.attr.activity_indicator_tint, accentColor);
|
||||
themedColors.put(R.attr.toolbarIconsColor, accentColor);
|
||||
|
||||
themedColors.put(R.attr.button_primary_background, accentColor);
|
||||
themedColors.put(R.attr.button_secondary_foreground, accentColor);
|
||||
themedColors.put(R.attr.button_tertiary_foreground, accentColor);
|
||||
themedColors.put(R.attr.button_outline_border, accentColor);
|
||||
themedColors.put(R.attr.button_muted_foreground, accentColor);
|
||||
themedColors.put(R.attr.header_tab_active_indicator, accentColor);
|
||||
themedColors.put(R.attr.header_alternate_tab_active_indicator, accentColor);
|
||||
|
||||
themedColors.put(R.attr.button_primary_background_disabled, mutedAccentColor);
|
||||
themedColors.put(R.attr.button_secondary_foreground_disabled, mutedAccentColor);
|
||||
themedColors.put(R.attr.button_tertiary_foreground_disabled, mutedAccentColor);
|
||||
themedColors.put(R.attr.button_outline_border_disabled, mutedAccentColor);
|
||||
themedColors.put(R.attr.button_muted_foreground_disabled, mutedAccentColor);
|
||||
|
||||
themedColors.put(R.attr.im_dropdown_icon_color, accentColor);
|
||||
themedColors.put(R.attr.im_dropdown_arrow_tint, accentColor);
|
||||
|
||||
themedColors.put(R.attr.im_attach_tint, accentColor);
|
||||
themedColors.put(R.attr.im_forward_line_tint, accentColor);
|
||||
themedColors.put(R.attr.link_alternate, accentColor);
|
||||
themedColors.put(R.attr.newsfeed_post_title_color, accentColor);
|
||||
|
||||
themedColors.put(R.attr.attach_picker_tab_active_background, accentColor);
|
||||
themedColors.put(R.attr.attach_picker_tab_active_text, accentColor);
|
||||
themedColors.put(R.attr.newsfeed_action_color, accentColor);
|
||||
themedColors.put(R.attr.counter_primary_background, accentColor);
|
||||
|
||||
themedColors.put(R.attr.dynamic_blue, accentColor);
|
||||
|
||||
themedColors.put(R.attr.action_sheet_action_foreground, accentColor);
|
||||
|
||||
// messages
|
||||
themedColors.put(R.attr.im_reply_separator, accentColor);
|
||||
themedColors.put(R.attr.im_text_name, accentColor);
|
||||
|
||||
wallLightColor = ThemesUtils.lighten(accentColor, 0.67f);
|
||||
|
||||
themedColors.put(R.attr.im_ic_send_msg, accentColor);
|
||||
themedColors.put(R.attr.im_bubble_wallpaper_outgoing, accentColor);
|
||||
themedColors.put(R.attr.im_bubble_outgoing, accentColor);
|
||||
themedColors.put(R.attr.im_bubble_outgoing_highlighted, accentColor);
|
||||
}
|
||||
|
||||
public static int getThemedAttr(Context context, @IdRes int attr) {
|
||||
if (attr == R.attr.im_bubble_wallpaper_outgoing || attr == R.attr.im_bubble_outgoing || attr == R.attr.im_bubble_outgoing_highlighted) {
|
||||
return wallLightColor;
|
||||
}
|
||||
|
||||
return themedColors.get(attr);
|
||||
}
|
||||
|
||||
public static boolean hasThemedAttr(Context context, int attrID) {
|
||||
// try {
|
||||
// Log.d(TAG, "Requesting color by attr " + context.getResources().getResourceName(attrID));
|
||||
// } catch (Exception e) {
|
||||
// }
|
||||
|
||||
if (isCachedAccents()) {
|
||||
if (ThemesUtils.isDarkTheme()) {
|
||||
return (themedColors.get(attrID) != 0 && ACCENT_THEME_ONLY_DARK.get(attrID, true) && (
|
||||
ThemesUtils.isMilkshake() ?
|
||||
ACCENT_THEME_ONLY_MILK_DARK.get(attrID, true) :
|
||||
ACCENT_THEME_ONLY_NOMILK.get(attrID, true)));
|
||||
} else {
|
||||
return (themedColors.get(attrID) != 0 && ACCENT_THEME_ONLY_LIGHT.get(attrID, true) && (
|
||||
ThemesUtils.isMilkshake() ?
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.get(attrID, true) :
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.get(attrID, true)));
|
||||
}
|
||||
} else {
|
||||
return themedColors.get(attrID) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
cachedAccents = false;
|
||||
themedColors.clear();
|
||||
}
|
||||
|
||||
public static boolean isCachedAccents() {
|
||||
return cachedAccents;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.*;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.vtosters.lite.R;
|
||||
import ru.vtosters.lite.themes.utils.RecolorUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ThemesHacks {
|
||||
// Фиксит селектор (все/свои/архив) в профиле
|
||||
public static void fixProfileSelector(View view) {
|
||||
if (!ThemesUtils.isMilkshake()) return;
|
||||
var id = view.getId();
|
||||
|
||||
if (id == R.id.profile_wall_owner_posts || id == R.id.profile_wall_all_posts || id == R.id.profile_wall_archived_posts) {
|
||||
StateListDrawable states = (StateListDrawable) ((LayerDrawable) view.getBackground()).getDrawable(0);
|
||||
LayerDrawable selected = (LayerDrawable) ((DrawableContainer.DrawableContainerState) states.getConstantState()).getChildren()[0];
|
||||
((ColorDrawable) selected.getDrawable(0)).setColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
public static void fixThemedFeed(TextView textView, int i) {
|
||||
if (i != R.layout.themed_feed_tab_2) {
|
||||
return;
|
||||
}
|
||||
textView.setTextColor(RecolorUtils.recolorCSL(textView.getTextColors()));
|
||||
((InsetDrawable) ((DrawableContainer.DrawableContainerState) textView.getBackground().getConstantState()).getChildren()[0]).getDrawable().setTint(ThemesUtils.lighten(ThemesUtils.getAccentColor(), 0.15f));
|
||||
}
|
||||
|
||||
public static void fixDropdown(Drawable drawable) {
|
||||
if (!ThemesUtils.isDarkTheme() && ThemesUtils.isMilkshake() && ThemesCore.isCachedAccents()) {
|
||||
StateListDrawable stateListDrawable = (StateListDrawable) drawable;
|
||||
((DrawableContainer.DrawableContainerState) stateListDrawable.getConstantState()).getChildren()[0].setTint(ThemesUtils.getAccentColor());
|
||||
((DrawableContainer.DrawableContainerState) stateListDrawable.getConstantState()).getChildren()[1].setTint(ThemesUtils.halfAlpha(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
|
||||
public static int getHackedColor(@NonNull Context context, @ColorRes int color) {
|
||||
if (ThemesCore.isCachedAccents() && ColorReferences.isAccentedColor(context.getColor(color))) {
|
||||
return ThemesUtils.getAccentColor();
|
||||
}
|
||||
|
||||
if (ThemesCore.isCachedAccents() && ColorReferences.isMutedAccentedColor(context.getColor(color))) {
|
||||
return ThemesUtils.getMutedAccentColor();
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT > 23) {
|
||||
return context.getColor(color);
|
||||
} else return context.getResources().getColor(color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class VTLResources extends Resources {
|
||||
private static final String TAG = "VTLResources";
|
||||
private final Context context;
|
||||
private static Field typedArrayField;
|
||||
|
||||
private static final List<Integer> attributesToTheme = new ArrayList<>();
|
||||
|
||||
static {
|
||||
try {
|
||||
typedArrayField = TypedArray.class.getDeclaredField("mData");
|
||||
typedArrayField.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
attributesToTheme.add(16843041);
|
||||
attributesToTheme.add(android.R.attr.backgroundTint);
|
||||
attributesToTheme.add(16843173);
|
||||
}
|
||||
|
||||
public VTLResources(Context context, Resources parent) {
|
||||
super(parent.getAssets(), parent.getDisplayMetrics(), parent.getConfiguration());
|
||||
this.context = context;
|
||||
// Log.d(TAG, "VTLResources: init");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
|
||||
var typedArray = super.obtainAttributes(set, attrs);
|
||||
var data = getArrayData(typedArray);
|
||||
for (int i = 0; i < attrs.length; i++) {
|
||||
try {
|
||||
int attrID = attrs[i];
|
||||
if (attributesToTheme.contains(attrID)) {
|
||||
int type = data[i*6];
|
||||
int cnt = data[(i*6)+1];
|
||||
|
||||
if (type == TypedValue.TYPE_ATTRIBUTE && isAttrThemeable(cnt)) {
|
||||
data[i*6] = TypedValue.TYPE_INT_COLOR_RGB8;
|
||||
data[(i*6)+1] = ThemesUtils.getAccentColor();
|
||||
data[(i*6)+2] = 0; // clear reference content
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "TAVzlom failed! (obtainAttributes)");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return typedArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getDrawable(int id, @Nullable Theme theme) throws NotFoundException {
|
||||
var drawable = super.getDrawable(id, theme);
|
||||
if (id == com.vtosters.lite.R.drawable.newsfeed_tab_dropdown_16) {
|
||||
ThemesHacks.fixDropdown(drawable);
|
||||
}
|
||||
return drawable;
|
||||
}
|
||||
|
||||
private static boolean isAttrThemeable(int attrID) {
|
||||
return !ThemesUtils.isDarkTheme() && attrID == com.vtosters.lite.R.attr.button_primary_background;
|
||||
}
|
||||
|
||||
private static int[] getArrayData(TypedArray arr) {
|
||||
try {
|
||||
return (int[]) typedArrayField.get(arr);
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.e(TAG, "getArrayData: ", e);
|
||||
e.printStackTrace();
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ru.vtosters.lite.themes.hooks.BaseHook;
|
||||
import ru.vtosters.lite.themes.hooks.ButtonHook;
|
||||
import ru.vtosters.lite.themes.hooks.ImageViewHook;
|
||||
import ru.vtosters.lite.themes.hooks.ProgressWheelHook;
|
||||
import ru.vtosters.lite.themes.hooks.TabLayoutHook;
|
||||
import ru.vtosters.lite.themes.hooks.TextViewHook;
|
||||
import ru.vtosters.lite.themes.hooks.ToolbarHook;
|
||||
import ru.vtosters.lite.themes.hooks.VKImageViewHook;
|
||||
|
||||
public class ViewInjector {
|
||||
public static ArrayList<BaseHook> hooks = new ArrayList<>();
|
||||
|
||||
static {
|
||||
hooks.add(new ButtonHook());
|
||||
hooks.add(new ImageViewHook());
|
||||
hooks.add(new TabLayoutHook());
|
||||
hooks.add(new TextViewHook());
|
||||
hooks.add(new ToolbarHook());
|
||||
hooks.add(new VKImageViewHook());
|
||||
hooks.add(new ProgressWheelHook());
|
||||
}
|
||||
|
||||
public static View inject(View view, int i, boolean z) {
|
||||
for (BaseHook hook : hooks) {
|
||||
hook.inject(view, i, z);
|
||||
}
|
||||
if (view instanceof ViewGroup) {
|
||||
var viewGroup = (ViewGroup) view;
|
||||
for (int i2 = 0; i2 < viewGroup.getChildCount(); i2++) {
|
||||
inject(viewGroup.getChildAt(i2), i, false);
|
||||
}
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
public interface BaseHook {
|
||||
void inject(View view, int i, boolean z);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ButtonHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof Button) {
|
||||
var button = (Button) view;
|
||||
if (button.getBackgroundTintList() != null && ColorReferences.isMutedAccentedColor(button.getBackgroundTintList())) {
|
||||
button.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getMutedAccentColor()));
|
||||
}
|
||||
|
||||
if (button.getBackgroundTintList() != null && ColorReferences.isAccentedColor(button.getBackgroundTintList())) {
|
||||
button.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (TextViewHook.isPositiveButton(button) || TextViewHook.isVkUiButton(view)) {
|
||||
button.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.themes.ThemesCore;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ImageViewHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof ImageView) {
|
||||
if (ThemesCore.isCachedAccents()) {
|
||||
var imageView = (ImageView) view;
|
||||
if (imageView.getImageTintList() == null) return;
|
||||
if (ColorReferences.isCslNeedToBeThemed(imageView.getImageTintList())) {
|
||||
imageView.setImageTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.pnikosis.materialishprogress.ProgressWheel;
|
||||
|
||||
import ru.vtosters.lite.themes.ThemesCore;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ProgressWheelHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof ProgressWheel) {
|
||||
if (ThemesCore.isCachedAccents()) {
|
||||
var progressWheel = (ProgressWheel) view;
|
||||
progressWheel.setBarColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.view.View;
|
||||
|
||||
import com.vk.core.view.VKTabLayout;
|
||||
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
|
||||
public class TabLayoutHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof VKTabLayout) {
|
||||
var tabLayout = (VKTabLayout) view;
|
||||
tabLayout.setSelectedTabIndicatorColor(ThemesUtils.getAccentColor());
|
||||
tabLayout.setTabRippleColor(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatCheckedTextView;
|
||||
|
||||
import com.vk.core.extensions.EditTextExt;
|
||||
import com.vk.core.view.OverlayTextView;
|
||||
import com.vk.core.view.TintTextView;
|
||||
import com.vk.core.view.links.LinkedTextView;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.themes.ThemesHacks;
|
||||
import ru.vtosters.lite.themes.utils.VkUiThemer;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class TextViewHook implements BaseHook {
|
||||
|
||||
private static final String TAG = "TextViewHook";
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof TextView) {
|
||||
var textView = (TextView) view;
|
||||
|
||||
if (ColorReferences.isAccentedColor(textView.getCurrentTextColor())) {
|
||||
textView.setTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(textView.getCurrentTextColor())) {
|
||||
textView.setTextColor(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && textView.getCompoundDrawableTintList() != null) {
|
||||
if (ColorReferences.isAccentedColor(textView.getCompoundDrawableTintList())) {
|
||||
textView.setCompoundDrawableTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(textView.getCompoundDrawableTintList())) {
|
||||
textView.setCompoundDrawableTintList(ColorStateList.valueOf(ThemesUtils.getMutedAccentColor()));
|
||||
}
|
||||
}
|
||||
|
||||
if (textView.getLinkTextColors() != null && ColorReferences.isAccentedColor(textView.getLinkTextColors())) {
|
||||
textView.setLinkTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (textView.getLinkTextColors() != null && ColorReferences.isMutedAccentedColor(textView.getLinkTextColors())) {
|
||||
textView.setLinkTextColor(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
if (isPositiveButton(textView) || isVkUiButton(textView)) {
|
||||
view.setBackgroundTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (view instanceof OverlayTextView) {
|
||||
if (view.getId() == android.R.id.button1) {
|
||||
view.setBackground(ThemesUtils.recolorDrawable(view.getBackground()));
|
||||
}
|
||||
if (ColorReferences.isAccentedColor(((OverlayTextView) view).getTextColors().getDefaultColor())) {
|
||||
((OverlayTextView) view).setTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
if (view instanceof TintTextView) {
|
||||
if (eligibleForStartTinting((TintTextView) view)) {
|
||||
((TintTextView) view).setDrawableStartTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (eligibleForStartTintingMuted((TintTextView) view)) {
|
||||
((TintTextView) view).setDrawableStartTint(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
if (eligibleForTinting(view.getId())) {
|
||||
((TintTextView) view).setDrawableTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (eligibleForTinting(view.getId())) {
|
||||
((TintTextView) view).setDrawableStartTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
if (view instanceof LinkedTextView) {
|
||||
((LinkedTextView) view).setLinkTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (view instanceof AppCompatCheckedTextView) {
|
||||
var check = (AppCompatCheckedTextView) view;
|
||||
if (ColorReferences.isAccentedColor(check.getCheckMarkTintList())) {
|
||||
check.setCheckMarkTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(check.getCheckMarkTintList())) {
|
||||
check.setCheckMarkTintList(ColorStateList.valueOf(ThemesUtils.getMutedAccentColor()));
|
||||
}
|
||||
}
|
||||
|
||||
if (view instanceof EditText) {
|
||||
ThemesUtils.setCursorColor((EditText) view);
|
||||
}
|
||||
|
||||
ThemesUtils.colorHandles(textView);
|
||||
VkUiThemer.autoThemeVkuiButtons(textView);
|
||||
ThemesHacks.fixProfileSelector(textView);
|
||||
ThemesHacks.fixThemedFeed(textView, i);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean eligibleForStartTinting(TintTextView view) {
|
||||
return ColorReferences.isAccentedColor(view.getTextColors()) || view.getTextColors().getDefaultColor() == ThemesUtils.getAccentColor();
|
||||
}
|
||||
|
||||
public static boolean eligibleForStartTintingMuted(TintTextView view) {
|
||||
return ColorReferences.isMutedAccentedColor(view.getTextColors()) || view.getTextColors().getDefaultColor() == ThemesUtils.getMutedAccentColor();
|
||||
}
|
||||
|
||||
public static boolean eligibleForTinting(int id) {
|
||||
return !ThemesUtils.isDarkTheme() && (id == R.id.attach_title || id == R.id.post_retweet_name);
|
||||
}
|
||||
|
||||
public static boolean isPositiveButton(View view) {
|
||||
return !ThemesUtils.isDarkTheme() && (view.getId() == R.id.positive || view.getId() == R.id.positive_button);
|
||||
}
|
||||
|
||||
public static boolean isVkUiButton(View view) {
|
||||
return !ThemesUtils.isDarkTheme() && (view.getId() == R.id.empty_button || view.getId() == R.id.button);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.view.View;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ToolbarHook implements BaseHook {
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof Toolbar) {
|
||||
var color = (ThemesUtils.isMilkshake() && !ThemesUtils.isDarkTheme()) ? ThemesUtils.getAccentColor() : ThemesUtils.getHeaderText();
|
||||
var menu = ((Toolbar) view).getMenu();
|
||||
for (int j = 0; j < menu.size(); ++j) {
|
||||
var item = menu.getItem(j);
|
||||
var icon = item.getIcon();
|
||||
if (icon != null) {
|
||||
if (icon instanceof RecoloredDrawable)
|
||||
((RecoloredDrawable) icon).a(color);
|
||||
else
|
||||
icon = new RecoloredDrawable(icon, color);
|
||||
item.setIcon(icon);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.view.View;
|
||||
|
||||
import com.vk.imageloader.view.VKImageView;
|
||||
|
||||
import ru.vtosters.lite.themes.utils.RecolorUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class VKImageViewHook implements BaseHook {
|
||||
private static Paint paint = new Paint();
|
||||
static {
|
||||
paint.setColorFilter(new PorterDuffColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof VKImageView) {
|
||||
var imageView = (VKImageView) view;
|
||||
if (imageView.getImageTintList() != null) {
|
||||
imageView.setImageTintList(RecolorUtils.recolorCSL(imageView.getImageTintList()));
|
||||
imageView.setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package ru.vtosters.lite.themes.items;
|
||||
|
||||
public class VTLColor {
|
||||
|
||||
public String resName;
|
||||
public int id;
|
||||
public int color;
|
||||
|
||||
public VTLColor(int id, int color) {
|
||||
this.id = id;
|
||||
this.color = color;
|
||||
}
|
||||
public VTLColor(String resName, int id, int color) {
|
||||
this.resName = resName;
|
||||
this.id = id;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public static VTLColor create(int id, int color) {
|
||||
return new VTLColor(id, color);
|
||||
}
|
||||
|
||||
public static VTLColor create(String resName, int id, int color) {
|
||||
return new VTLColor(resName, id, color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package ru.vtosters.lite.themes.items;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VTLPalette {
|
||||
public String id;
|
||||
public String name;
|
||||
public String author;
|
||||
public List<VTLColor> colors = new ArrayList<>();
|
||||
|
||||
public VTLPalette() {
|
||||
|
||||
}
|
||||
|
||||
public VTLPalette(String id, String name, String author, List<VTLColor> colors) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.author = author;
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
public VTLPalette setId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setAuthor(String author) {
|
||||
this.author = author;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setColors(List<VTLColor> colors) {
|
||||
this.colors = colors;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VTLPalette setColor(String name, int color) {
|
||||
this.colors.add(new VTLColor(name, 0, color));
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getColor(String name) {
|
||||
for (var item : colors)
|
||||
if (name.equals(item.resName))
|
||||
return item.color;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static VTLPalette fromJson(JSONObject json) throws JSONException {
|
||||
var palette = new VTLPalette()
|
||||
.setId(json.optString("palette_id"))
|
||||
.setName(json.optString("name"))
|
||||
.setAuthor(json.optString("author"));
|
||||
var paletteNode = json.getJSONArray("palette");
|
||||
for (int i = 0; i < paletteNode.length(); i++) {
|
||||
var colorNode = paletteNode.getJSONObject(i);
|
||||
var name = colorNode.getString("name");
|
||||
if (colorNode.has("colors")) {
|
||||
var colorsNode = colorNode.getJSONArray("colors");
|
||||
for (int j = 0; j < colorsNode.length(); j++) {
|
||||
var subColorNode = colorsNode.getJSONObject(j);
|
||||
var index = subColorNode.getString("index");
|
||||
var subColor = subColorNode.getString("color");
|
||||
if (!subColor.startsWith("#")) subColor = "#" + subColor;
|
||||
palette.setColor(name + " " + index, Color.parseColor(subColor));
|
||||
}
|
||||
} else {
|
||||
var color = colorNode.getString("color");
|
||||
if (!color.startsWith("#")) color = "#" + color;
|
||||
palette.setColor(name, Color.parseColor(color));
|
||||
}
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
|
||||
public static VTLPalette valuesOf(String id, String name, String author, List<VTLColor> colors) {
|
||||
return new VTLPalette()
|
||||
.setId(id)
|
||||
.setName(name)
|
||||
.setAuthor(author)
|
||||
.setColors(colors);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package ru.vtosters.lite.themes.palettes;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.themes.items.VTLPalette;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
public class PalettesManager {
|
||||
|
||||
private final static File PALETTES_DIR = new File(Environment.getExternalStorageDirectory(), "VTL/palettes");
|
||||
private final static String ASSETS_DIR = "vtl_themes/palettes/";
|
||||
|
||||
private static PalettesManager sInstance;
|
||||
|
||||
private final List<VTLPalette> mPalettes = new ArrayList<>();
|
||||
|
||||
public static PalettesManager getInstance() {
|
||||
if (sInstance == null)
|
||||
sInstance = new PalettesManager();
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public PalettesManager() {
|
||||
load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
mPalettes.clear();
|
||||
if (!PALETTES_DIR.exists())
|
||||
PALETTES_DIR.mkdirs();
|
||||
final var palettes = PALETTES_DIR.listFiles((dir, name) -> name.endsWith(".json"));
|
||||
if (palettes == null || palettes.length == 0)
|
||||
copyPaletteFromAssets();
|
||||
parsePalettes();
|
||||
}
|
||||
|
||||
private boolean copyPaletteFromAssets() {
|
||||
try {
|
||||
final var manager = AndroidUtils.getGlobalContext().getAssets();
|
||||
final var assets = manager.list(ASSETS_DIR);
|
||||
if (assets == null || assets.length == 0) return false;
|
||||
for (var asset : assets) {
|
||||
try {
|
||||
IOUtils.copyFile(manager.open(ASSETS_DIR + asset), new File(PALETTES_DIR, asset));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void parsePalettes() {
|
||||
var arr = PALETTES_DIR.listFiles((dir, name) -> name.endsWith(".json"));
|
||||
if (arr == null || arr.length == 0)
|
||||
throw new RuntimeException("Can't load palettes");
|
||||
for (var file : arr) {
|
||||
try {
|
||||
var json = new JSONObject(IOUtils.readAllLines(file));
|
||||
mPalettes.add(VTLPalette.fromJson(json));
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public VTLPalette getPalette(String id) {
|
||||
for (var palette : mPalettes)
|
||||
if (id.equals(palette.id))
|
||||
return palette;
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public VTLPalette getPalette(int i) {
|
||||
return mPalettes.get(i);
|
||||
}
|
||||
|
||||
public int getPalettesCount() {
|
||||
return mPalettes.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package ru.vtosters.lite.themes.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class RecolorUtils {
|
||||
public static Drawable recolorDrawableToolbar(Drawable drawable) {
|
||||
if (drawable == null) return null;
|
||||
|
||||
return new RecoloredDrawable(drawable, ThemesUtils.getHeaderText());
|
||||
} // Recolor toolbar drawable to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public static Drawable recolorDrawableInt(int drawable) {
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables") Drawable res = AndroidUtils.getResources().getDrawable(drawable);
|
||||
return new RecoloredDrawable(res, ThemesUtils.getAccentColor());
|
||||
} // Get res drawable via id and coloring to accent
|
||||
|
||||
public static int recolorHexColor(int i){
|
||||
var accented = ColorReferences.isAccentedColor(i);
|
||||
var mutedaccented = ColorReferences.isMutedAccentedColor(i);
|
||||
return (accented || mutedaccented) ? (accented ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : i;
|
||||
}
|
||||
|
||||
public static ColorStateList recolorCSL(ColorStateList colorStateList) {
|
||||
if (colorStateList == null) return null;
|
||||
|
||||
return ColorStateList.valueOf(ThemesUtils.getAccentColor());
|
||||
} // Recolor ColorStateList to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForColorStateLists")
|
||||
public static ColorStateList themeCSL(Context context, int color) {
|
||||
if (ColorReferences.isColorRefAccented(color)) {
|
||||
return ColorStateList.valueOf(ThemesUtils.getAccentColor());
|
||||
} else if (ColorReferences.isColorRefMutedAccented(color)) {
|
||||
return ColorStateList.valueOf(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
|
||||
ColorStateList csl;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
csl = context.getColorStateList(color);
|
||||
} else {
|
||||
csl = context.getResources().getColorStateList(color);
|
||||
}
|
||||
|
||||
return themeCSL(csl);
|
||||
} // Recolor ColorStateList
|
||||
|
||||
public static ColorStateList themeCSL(ColorStateList csl){
|
||||
try {
|
||||
int unsel = csl.getColorForState(new int[]{-android.R.attr.state_selected}, Color.BLACK);
|
||||
int sel = csl.getColorForState(new int[]{android.R.attr.state_selected}, Color.BLACK);
|
||||
int enabled = csl.getColorForState(new int[]{android.R.attr.state_enabled}, Color.BLACK);
|
||||
int disabled = csl.getColorForState(new int[]{-android.R.attr.state_enabled}, Color.BLACK);
|
||||
|
||||
boolean isUnselAccent = ColorReferences.isAccentedColor(unsel);
|
||||
boolean isSelAccent = ColorReferences.isAccentedColor(sel);
|
||||
boolean isEnabledAccent = ColorReferences.isAccentedColor(enabled);
|
||||
boolean isDisabledAccent = ColorReferences.isAccentedColor(disabled);
|
||||
|
||||
boolean isUnselMutedAccent = ColorReferences.isMutedAccentedColor(unsel);
|
||||
boolean isSelMutedAccent = ColorReferences.isMutedAccentedColor(sel);
|
||||
boolean isEnabledMutedAccent = ColorReferences.isMutedAccentedColor(enabled);
|
||||
boolean isDisabledMutedAccent = ColorReferences.isMutedAccentedColor(disabled);
|
||||
|
||||
if (isUnselAccent || isSelAccent || isUnselMutedAccent || isSelMutedAccent) {
|
||||
return new ColorStateList(new int[][]{
|
||||
new int[]{android.R.attr.state_selected}, new int[]{-android.R.attr.state_selected}
|
||||
}, new int[]{(isSelAccent || isSelMutedAccent) ? (isSelAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : sel, (isUnselAccent || isUnselMutedAccent) ? (isUnselAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : unsel});
|
||||
}
|
||||
|
||||
if (isDisabledAccent || isEnabledAccent || isEnabledMutedAccent || isDisabledMutedAccent) {
|
||||
return new ColorStateList(new int[][]{
|
||||
new int[]{android.R.attr.state_enabled}, new int[]{-android.R.attr.state_enabled}
|
||||
}, new int[]{(isEnabledAccent || isEnabledMutedAccent) ? (isEnabledAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : enabled, (isDisabledAccent || isDisabledMutedAccent) ? (isDisabledAccent ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : disabled});
|
||||
}
|
||||
|
||||
return csl;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package ru.vtosters.lite.themes.utils;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.DrawableContainer;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.RippleDrawable;
|
||||
import android.graphics.drawable.StateListDrawable;
|
||||
import android.os.Build;
|
||||
import android.widget.TextView;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class VkUiThemer {
|
||||
public static void autoThemeVkuiButtons(TextView view) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
|
||||
if (ThemesUtils.isDarkTheme())
|
||||
return; // no need to theme b/w buttons, well it should skip, but I do it for extra performance
|
||||
|
||||
try {
|
||||
if (!(view.getBackground() instanceof StateListDrawable)) return;
|
||||
|
||||
StateListDrawable states = ((StateListDrawable) view.getBackground());
|
||||
if (states.getConstantState() == null) return;
|
||||
DrawableContainer.DrawableContainerState dStates = (DrawableContainer.DrawableContainerState) states.getConstantState();
|
||||
|
||||
if (dStates.getChildCount() == 2) {
|
||||
Drawable target = dStates.getChildren()[0];
|
||||
if (!(target instanceof RippleDrawable)) return;
|
||||
|
||||
RippleDrawable ripple = (RippleDrawable) target;
|
||||
for (int i = 0; i < ripple.getNumberOfLayers(); i++) {
|
||||
if (ripple.getId(i) == android.R.id.mask) continue;
|
||||
|
||||
Drawable currentTarget = ripple.getDrawable(i);
|
||||
|
||||
if (!(currentTarget instanceof GradientDrawable)) continue;
|
||||
|
||||
//if (TSColorRefs.TS_DEBUG_MODE) Log.d("TSCore", "[tsh] finally, obamium = ["+currentTarget.toString()+"]");
|
||||
|
||||
GradientDrawable spd = (GradientDrawable) currentTarget;
|
||||
if (spd.getShape() != GradientDrawable.RECTANGLE) continue;
|
||||
|
||||
// Log.d("TSCore", "[tsh] got a color!");
|
||||
|
||||
ColorStateList csl = spd.getColor();
|
||||
// if (csl != null) {
|
||||
// Log.d("TSCore", "[tsh] csl2 <def: " + csl.getDefaultColor() + " = " + ThemesUtils.hex(csl.getDefaultColor()) + "> | " + csl);
|
||||
// }
|
||||
|
||||
if (ColorReferences.isAccentedColor(spd.getColor())) {
|
||||
// Log.d("TSCore", "[tsh] theming CSL");
|
||||
spd.setTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
}
|
||||
|
||||
Drawable draw2 = dStates.getChildren()[0];
|
||||
if (!(draw2 instanceof GradientDrawable)) return;
|
||||
GradientDrawable spd = (GradientDrawable) draw2;
|
||||
if (spd.getShape() != GradientDrawable.RECTANGLE) return;
|
||||
|
||||
// Log.d("TSCore", "[tsh:disabled] got a color!");
|
||||
|
||||
ColorStateList csl = spd.getColor();
|
||||
// if (csl != null) {
|
||||
// Log.d("TSCore", "[tsh:disabled] csl2 <def: " + csl.getDefaultColor() + " = " + ThemesUtils.hex(csl.getDefaultColor()) + "> | " + csl);
|
||||
// }
|
||||
|
||||
if (ColorReferences.isAccentedColor(spd.getColor())) {
|
||||
// Log.d("TSCore", "[tsh:disabled] theming CSL");
|
||||
spd.setTint(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
if (ColorReferences.isMutedAccentedColor(spd.getColor())) {
|
||||
// Log.d("TSCore", "[tsh:disabled] theming CSL");
|
||||
spd.setTint(ThemesUtils.getMutedAccentColor());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// This must go wrong, so we ignore any exceptions that may occur
|
||||
e.printStackTrace(); // REMOVE THIS!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,23 @@
|
||||
package ru.vtosters.lite.ui;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.ImageUtils.setTint;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getSTextAttr;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
import com.vtosters.lite.ui.MaterialSwitchPreference;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ImageUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class PreferencesUtil {
|
||||
|
||||
@@ -36,7 +29,7 @@ public class PreferencesUtil {
|
||||
CharSequence[] entries,
|
||||
CharSequence[] entriesValue
|
||||
) {
|
||||
ListPreference preference = new ListPreference(getGlobalContext());
|
||||
ListPreference preference = new ListPreference(fragment.requireContext());
|
||||
preference.setEntries(entries);
|
||||
preference.setEntryValues(entriesValue);
|
||||
preference.setTitle(title); // setTitle
|
||||
@@ -57,7 +50,7 @@ public class PreferencesUtil {
|
||||
CharSequence[] entriesValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
ListPreference preference = new ListPreference(getGlobalContext());
|
||||
ListPreference preference = new ListPreference(fragment.requireContext());
|
||||
preference.setEntries(entries);
|
||||
preference.setEntryValues(entriesValue);
|
||||
preference.setSummary(summary); // setSummary
|
||||
@@ -69,7 +62,7 @@ public class PreferencesUtil {
|
||||
preference.setOnPreferenceChangeListener(listener);
|
||||
|
||||
if (iconRes != 0)
|
||||
preference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
preference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
@@ -80,7 +73,7 @@ public class PreferencesUtil {
|
||||
CharSequence summary,
|
||||
boolean defValue
|
||||
) {
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(materialPreferenceToolbarFragment.requireContext());
|
||||
materialSwitchPreference.setTitle(title); // setTitle
|
||||
materialSwitchPreference.setSummary(summary); // setSummary
|
||||
materialSwitchPreference.setKey(key); // setKey
|
||||
@@ -98,7 +91,7 @@ public class PreferencesUtil {
|
||||
// boolean defValue,
|
||||
// Preference.OnPreferenceChangeListener listener
|
||||
// ) {
|
||||
// MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
// MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(fragment.requireContext());
|
||||
// materialSwitchPreference.setTitle(title); // setTitle
|
||||
// materialSwitchPreference.setSummary(summary); // setSummary
|
||||
// materialSwitchPreference.setKey(key); // setKey
|
||||
@@ -106,7 +99,7 @@ public class PreferencesUtil {
|
||||
// materialSwitchPreference.setOnPreferenceChangeListener(listener); // setOnPreferenceClickListener
|
||||
//
|
||||
// if (iconRes != 0)
|
||||
// materialSwitchPreference.setIcon(setTint(getGlobalContext(), Objects.requireNonNull(ContextCompat.getDrawable(getGlobalContext(), iconRes)))); // preference.setIcon
|
||||
// materialSwitchPreference.setIcon(setTint(fragment.requireContext(), Objects.requireNonNull(ContextCompat.getDrawable(fragment.requireContext(), iconRes)))); // preference.setIcon
|
||||
//
|
||||
// fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
// }
|
||||
@@ -120,7 +113,7 @@ public class PreferencesUtil {
|
||||
boolean defValue,
|
||||
Preference.OnPreferenceChangeListener listener
|
||||
) {
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getGlobalContext());
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(fragment.requireContext());
|
||||
materialSwitchPreference.setTitle(title); // setTitle
|
||||
materialSwitchPreference.setSummary(summary); // setSummary
|
||||
materialSwitchPreference.setKey(key); // setKey
|
||||
@@ -128,7 +121,7 @@ public class PreferencesUtil {
|
||||
fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // materialPreferenceToolbarFragment.getPreferenceScreen().addPreference(preference)
|
||||
|
||||
if (iconRes != 0)
|
||||
materialSwitchPreference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
materialSwitchPreference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
materialSwitchPreference.setOnPreferenceChangeListener(listener); // setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
@@ -140,7 +133,7 @@ public class PreferencesUtil {
|
||||
CharSequence title,
|
||||
CharSequence summary
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
@@ -155,12 +148,12 @@ public class PreferencesUtil {
|
||||
int iconRes,
|
||||
Preference.OnPreferenceClickListener listener
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
|
||||
if (iconRes != 0)
|
||||
preference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
preference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
preference.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
@@ -173,13 +166,13 @@ public class PreferencesUtil {
|
||||
CharSequence summary,
|
||||
int iconRes,
|
||||
Preference.OnPreferenceClickListener listener) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
|
||||
if (iconRes != 0)
|
||||
preference.setIcon(setTint(getGlobalContext(), getDrawable(getGlobalContext(), iconRes))); // preference.setIcon
|
||||
preference.setIcon(ImageUtils.setTint(fragment.requireContext(), getDrawable(fragment.requireContext(), iconRes))); // preference.setIcon
|
||||
preference.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
@@ -193,7 +186,7 @@ public class PreferencesUtil {
|
||||
@Nullable Drawable icon,
|
||||
Preference.OnPreferenceClickListener listener
|
||||
) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
@@ -206,37 +199,37 @@ public class PreferencesUtil {
|
||||
}
|
||||
|
||||
public static void addPreferenceCategory(MaterialPreferenceToolbarFragment fragment, CharSequence title) {
|
||||
PreferenceCategory preference = new PreferenceCategory(getGlobalContext(), null);
|
||||
PreferenceCategory preference = new PreferenceCategory(fragment.requireContext(), null);
|
||||
preference.setTitle(title); // setTitle
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreferenceCategory(MaterialPreferenceToolbarFragment fragment, CharSequence title, int collapsedSize) {
|
||||
PreferenceCategory preference = new PreferenceCategory(getGlobalContext(), null);
|
||||
PreferenceCategory preference = new PreferenceCategory(fragment.requireContext(), null);
|
||||
preference.setTitle(title); // setTitle
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addEditTextPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, EditTextPrefChangeListener editTextPrefChangeListener) {
|
||||
Preference preference = new Preference(getGlobalContext());
|
||||
Preference preference = new Preference(fragment.requireContext());
|
||||
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
preference.setOnPreferenceClickListener(preference1 -> {
|
||||
LinearLayout linearLayout = new LinearLayout(getGlobalContext());
|
||||
LinearLayout linearLayout = new LinearLayout(fragment.requireContext());
|
||||
|
||||
final EditText editText = new EditText(getGlobalContext());
|
||||
editText.setText(PreferenceManager.getDefaultSharedPreferences(getGlobalContext()).getString(key, ""));
|
||||
final EditText editText = new EditText(fragment.requireContext());
|
||||
editText.setText(PreferenceManager.getDefaultSharedPreferences(fragment.requireContext()).getString(key, ""));
|
||||
editText.setHint(title);
|
||||
editText.setTextColor(getTextAttr());
|
||||
editText.setHintTextColor(getSTextAttr());
|
||||
editText.setTextColor(ThemesUtils.getTextAttr());
|
||||
editText.setHintTextColor(ThemesUtils.getSTextAttr());
|
||||
|
||||
editText.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
editText.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
|
||||
linearLayout.addView(editText);
|
||||
editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) editText.getLayoutParams());
|
||||
margin.setMargins(dp2px(20f), 0, dp2px(20f), 0);
|
||||
margin.setMargins(AndroidUtils.dp2px(20f), 0, AndroidUtils.dp2px(20f), 0);
|
||||
editText.setLayoutParams(margin);
|
||||
|
||||
new VkAlertDialog.Builder(fragment.getContext())
|
||||
@@ -247,7 +240,7 @@ public class PreferencesUtil {
|
||||
if (!change)
|
||||
return;
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(getGlobalContext())
|
||||
PreferenceManager.getDefaultSharedPreferences(fragment.requireContext())
|
||||
.edit()
|
||||
.putString(key, editText.getText().toString())
|
||||
.apply();
|
||||
@@ -261,13 +254,13 @@ public class PreferencesUtil {
|
||||
|
||||
public static int getTextColor(Context ctx) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(getTextAttr(), typedValue, true);
|
||||
ctx.getTheme().resolveAttribute(ThemesUtils.getTextAttr(), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
public static int getSTextColor(Context ctx) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(getSTextAttr(), typedValue, true);
|
||||
ctx.getTheme().resolveAttribute(ThemesUtils.getSTextAttr(), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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,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("Изменения: \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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -10,6 +10,7 @@ import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplicationWithTimer;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.isEnableExternalOpening;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getSTextAttr;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
@@ -49,6 +50,7 @@ import ru.vtosters.lite.music.LastFMScrobbler;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.ui.adapters.ImagineArrayAdapter;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
private static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
@@ -56,7 +58,7 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
public static void download(Context ctx) {
|
||||
final EditText input = new EditText(ctx);
|
||||
input.setTextColor(getTextAttr());
|
||||
input.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
input.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
|
||||
var lp = new FrameLayout.LayoutParams(-1, -2);
|
||||
lp.leftMargin = AndroidUtils.dp2px(16);
|
||||
@@ -91,6 +93,12 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
prefs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
findPreference("maxquality").setEnabled(isEnableExternalOpening());
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
private void prefs() {
|
||||
findPreference("download_video").setOnPreferenceClickListener(new MediaFragment.download());
|
||||
findPreference("clearvideohistory").setOnPreferenceClickListener(preference -> {
|
||||
@@ -156,6 +164,8 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
.show();
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("maxquality").setEnabled(isEnableExternalOpening());
|
||||
}
|
||||
|
||||
private void lastfmAuth(Context ctx) {
|
||||
@@ -166,7 +176,7 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
fn.setHint(R.string.lastfm_login);
|
||||
fn.setTextColor(getTextAttr());
|
||||
fn.setHintTextColor(getSTextAttr());
|
||||
fn.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
fn.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
linearLayout.addView(fn);
|
||||
fn.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) fn.getLayoutParams());
|
||||
@@ -177,7 +187,7 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
ln.setHint(R.string.lastfm_password);
|
||||
ln.setTextColor(getTextAttr());
|
||||
ln.setHintTextColor(getSTextAttr());
|
||||
ln.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
ln.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
linearLayout.addView(ln);
|
||||
ln.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ln.setLayoutParams(margin);
|
||||
|
||||
@@ -60,6 +60,7 @@ 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;
|
||||
|
||||
@@ -96,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();
|
||||
|
||||
@@ -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,20 +1,22 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.isTablet;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplicationWithTimer;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.core.fragments.FragmentImpl;
|
||||
import com.vk.navigation.Navigator;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
import ru.vtosters.lite.themes.ThemesCore;
|
||||
import ru.vtosters.lite.themes.palettes.PalettesManager;
|
||||
import ru.vtosters.lite.ui.dialogs.PalettesBottomSheetDialog;
|
||||
import ru.vtosters.lite.ui.views.rarepebble.ColorPickerView;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ThemesFragment extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
@@ -22,23 +24,79 @@ public class ThemesFragment extends MaterialPreferenceToolbarFragment {
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(R.xml.preferences_themes);
|
||||
prefs();
|
||||
initPreferences();
|
||||
}
|
||||
|
||||
private void prefs() {
|
||||
findPreference("navbar").setOnPreferenceClickListener(new restart());
|
||||
findPreference("milkshake").setOnPreferenceClickListener(new restart());
|
||||
findPreference("darktheme").setOnPreferenceChangeListener(new restartdark());
|
||||
findPreference("lighttheme").setOnPreferenceChangeListener(new restartlight());
|
||||
findPreference("iconmanager").setOnPreferenceClickListener(new openicons());
|
||||
findPreference("dockbar_tab_titles").setOnPreferenceClickListener(new restart());
|
||||
findPreference("dockbar_accent").setOnPreferenceClickListener(new restart());
|
||||
findPreference("dockcounter").setOnPreferenceClickListener(new restart());
|
||||
findPreference("newsfeed_notif").setOnPreferenceClickListener(new restart());
|
||||
findPreference("newsfeed_notif").setVisible(milkshake());
|
||||
private void initPreferences() {
|
||||
var accentColorPreference = findPreference("accent_color");
|
||||
accentColorPreference.setIcon(ThemesUtils.recolorDrawable(requireContext().getDrawable(R.drawable.bg_accent_circle)));
|
||||
accentColorPreference.setOnPreferenceClickListener(preference -> {
|
||||
changeAccent();
|
||||
return true;
|
||||
});
|
||||
|
||||
if (isTablet()) {
|
||||
findPreference("dockbarsett").setVisible(false);
|
||||
var navBarPreference = findPreference("navbar");
|
||||
navBarPreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return true;
|
||||
});
|
||||
|
||||
var milkshakePreference = findPreference("milkshake");
|
||||
milkshakePreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return true;
|
||||
});
|
||||
|
||||
var amoledThemePreference = findPreference("amoledtheme");
|
||||
amoledThemePreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return true;
|
||||
});
|
||||
|
||||
var monetThemePreference = findPreference("monettheme");
|
||||
monetThemePreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return true;
|
||||
});
|
||||
monetThemePreference.setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S);
|
||||
|
||||
var iconManagerPreference = findPreference("iconmanager");
|
||||
iconManagerPreference.setOnPreferenceClickListener(preference -> {
|
||||
switchFragment(IconsFragment.class);
|
||||
return true;
|
||||
});
|
||||
|
||||
var dockbarTabTitlesPreference = findPreference("dockbar_tab_titles");
|
||||
dockbarTabTitlesPreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return true;
|
||||
});
|
||||
|
||||
var dockbarAccentPreference = findPreference("dockbar_accent");
|
||||
dockbarAccentPreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return true;
|
||||
});
|
||||
|
||||
var dockCounterPreference = findPreference("dockcounter");
|
||||
dockCounterPreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return true;
|
||||
});
|
||||
|
||||
var newsfeedNotificationsPreference = findPreference("newsfeed_notif");
|
||||
newsfeedNotificationsPreference.setOnPreferenceClickListener(preference -> {
|
||||
restart();
|
||||
return true;
|
||||
});
|
||||
|
||||
newsfeedNotificationsPreference.setVisible(Preferences.milkshake());
|
||||
|
||||
findPreference("accentprefs").setVisible(!ThemesUtils.isMonetTheme() && ThemesUtils.isMilkshake());
|
||||
|
||||
if (AndroidUtils.isTablet()) {
|
||||
PreferenceCategory dockbarSettingsPreferenceCategory = (PreferenceCategory) findPreference("dockbarsett");
|
||||
dockbarSettingsPreferenceCategory.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,40 +105,68 @@ public class ThemesFragment extends MaterialPreferenceToolbarFragment {
|
||||
return R.string.vtlthemes;
|
||||
}
|
||||
|
||||
public static class restart implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
restartApplicationWithTimer();
|
||||
return true;
|
||||
}
|
||||
void changeAccent() {
|
||||
final var titles = AndroidUtils.getArray("accent_select_type");
|
||||
new VkAlertDialog.Builder(requireContext())
|
||||
.setTitle(AndroidUtils.getString("change_accent_color"))
|
||||
.setItems(titles, (dialog, which) -> {
|
||||
switch (which) {
|
||||
case 0:
|
||||
showColorPicker();
|
||||
break;
|
||||
case 1:
|
||||
showPalettesDialog();
|
||||
break;
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.reset, (dialog, which) -> {
|
||||
ThemesUtils.setCustomAccentColor(0, false);
|
||||
LifecycleUtils.restartApplicationWithTimer();
|
||||
})
|
||||
.setPositiveButton(R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
public static class restartlight implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
edit().putString("lighttheme", o.toString()).commit();
|
||||
restartApplicationWithTimer();
|
||||
return false;
|
||||
}
|
||||
void showColorPicker() {
|
||||
final var colorPickerView = new ColorPickerView(requireContext());
|
||||
colorPickerView.setColor(ThemesUtils.getAccentColor());
|
||||
new VkAlertDialog.Builder(requireContext())
|
||||
.setTitle(AndroidUtils.getString("select_color"))
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.select, (dialog, which) -> setAccentColor(colorPickerView.getColor()))
|
||||
.setView(colorPickerView)
|
||||
.show();
|
||||
}
|
||||
|
||||
public static class restartdark implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
edit().putString("darktheme", o.toString()).commit();
|
||||
restartApplicationWithTimer();
|
||||
return false;
|
||||
}
|
||||
void showPalettesDialog() {
|
||||
final var manager = PalettesManager.getInstance();
|
||||
final var titles = new String[manager.getPalettesCount()];
|
||||
for (int i = 0; i < titles.length; ++i)
|
||||
titles[i] = manager.getPalette(i).name;
|
||||
new VkAlertDialog.Builder(requireContext())
|
||||
.setTitle(AndroidUtils.getString("select_palette"))
|
||||
.setItems(titles, (dialog, which) ->
|
||||
PalettesBottomSheetDialog.create(requireActivity(), manager.getPalette(which),
|
||||
(adapter, vtlcolor) -> setAccentColor(vtlcolor.color))
|
||||
)
|
||||
.setPositiveButton(R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
public class openicons implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(IconsFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
return true;
|
||||
}
|
||||
void setAccentColor(int color) {
|
||||
ThemesUtils.setCustomAccentColor(color, false);
|
||||
ThemesCore.setThemedColors(color);
|
||||
restart();
|
||||
}
|
||||
|
||||
void restart() {
|
||||
LifecycleUtils.restartApplicationWithTimer();
|
||||
}
|
||||
|
||||
private void switchFragment(Class<? extends FragmentImpl> fragmentClz) {
|
||||
var intent = new Navigator(fragmentClz)
|
||||
.b(requireContext())
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
requireContext().startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +1,11 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static ru.vtosters.lite.ui.PreferencesUtil.addListPreferenceIcon;
|
||||
import static ru.vtosters.lite.ui.PreferencesUtil.addMaterialSwitchPreference;
|
||||
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.utils.About.getBuildNumber;
|
||||
import static ru.vtosters.lite.utils.About.getCommitLink;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserPhoto;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUsername;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.isVKTester;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.isTablet;
|
||||
import static ru.vtosters.lite.utils.GmsUtils.isGmsInstalled;
|
||||
import static ru.vtosters.lite.utils.ImageUtils.getDrawableFromUrl;
|
||||
import static ru.vtosters.lite.utils.Preferences.ads;
|
||||
import static ru.vtosters.lite.utils.Preferences.autotranslate;
|
||||
import static ru.vtosters.lite.utils.Preferences.dev;
|
||||
import static ru.vtosters.lite.utils.Preferences.devmenu;
|
||||
import static ru.vtosters.lite.utils.Preferences.disableSettingsSumms;
|
||||
import static ru.vtosters.lite.utils.Preferences.hasSpecialVerif;
|
||||
import static ru.vtosters.lite.utils.Preferences.isValidSignature;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
import static ru.vtosters.lite.utils.Preferences.navbar;
|
||||
import static ru.vtosters.lite.utils.Preferences.offline;
|
||||
import static ru.vtosters.lite.utils.Preferences.shortinfo;
|
||||
import static ru.vtosters.lite.utils.Preferences.stories;
|
||||
import static ru.vtosters.lite.utils.Preferences.superapp;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getDarkTheme;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getLightTheme;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.isDarkTheme;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.setTheme;
|
||||
import static ru.vtosters.lite.utils.VTVerifications.vtverif;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.aefyr.tsg.g2.TelegramStickersService;
|
||||
import com.vk.about.AboutAppFragment;
|
||||
import com.vk.balance.BalanceFragment;
|
||||
@@ -60,7 +23,7 @@ import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
import com.vtosters.lite.general.fragments.SettingsAccountFragment;
|
||||
import com.vtosters.lite.general.fragments.SettingsGeneralFragment;
|
||||
import com.vtosters.lite.ui.MaterialSwitchPreference;
|
||||
|
||||
import ru.vtosters.lite.concurrent.VTExecutors;
|
||||
import ru.vtosters.lite.hooks.ui.SystemThemeChangerHook;
|
||||
import ru.vtosters.lite.ui.components.DockBarEditorManager;
|
||||
import ru.vtosters.lite.ui.components.SuperAppEditorManager;
|
||||
@@ -70,6 +33,17 @@ import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.SSFSUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
import static ru.vtosters.lite.ui.PreferencesUtil.*;
|
||||
import static ru.vtosters.lite.utils.About.getBuildNumber;
|
||||
import static ru.vtosters.lite.utils.About.getCommitLink;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.*;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.*;
|
||||
import static ru.vtosters.lite.utils.GmsUtils.isGmsInstalled;
|
||||
import static ru.vtosters.lite.utils.ImageUtils.getDrawableFromUrl;
|
||||
import static ru.vtosters.lite.utils.Preferences.*;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.*;
|
||||
import static ru.vtosters.lite.utils.VTVerifications.vtverif;
|
||||
|
||||
public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
public static String getValAsString(@StringRes int strRes, Boolean value) {
|
||||
if (disableSettingsSumms()) return null;
|
||||
@@ -165,19 +139,33 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
this.addPreferencesFromResource(R.xml.empty);
|
||||
|
||||
addPreferenceDrawable(this, "", getUsername(), requireContext().getString(R.string.vtllogout), getDrawableFromUrl(getUserPhoto(), R.drawable.ic_user_circle_outline_28, true, true), preference -> {
|
||||
try {
|
||||
VKAuth.a("logout", false);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
addPreferenceDrawable(
|
||||
this,
|
||||
"account_switcher",
|
||||
getUsername(),
|
||||
requireContext().getString(R.string.vtllogout),
|
||||
requireContext().getDrawable(R.drawable.ic_user_circle_outline_28),
|
||||
preference -> {
|
||||
try {
|
||||
VKAuth.a("logout", false);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
var intent = new Intent(requireContext(), MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
requireContext().startActivity(intent);
|
||||
var intent = new Intent(requireContext(), MainActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
requireContext().startActivity(intent);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
});
|
||||
|
||||
VTExecutors.getIoScheduler().a(() -> {
|
||||
var icon = getDrawableFromUrl(getUserPhoto(), 0, true, true);
|
||||
if (icon == null) return;
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
findPreference("account_switcher").setIcon(icon);
|
||||
});
|
||||
});
|
||||
|
||||
addPreference(this, "", requireContext().getString(R.string.vtssfs), ssfs, R.drawable.ic_link_circle_outline_28, preference -> {
|
||||
|
||||
@@ -1,51 +1,36 @@
|
||||
package ru.vtosters.lite.ui.fragments.tgstickers;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static android.widget.Toast.makeText;
|
||||
import static ru.vtosters.lite.tgs.TGPref.setTGBotKey;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getSTextAttr;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.*;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
|
||||
import com.aefyr.tsg.g2.TelegramStickersService;
|
||||
import com.aefyr.tsg.g2.stickersgrabber.TelegramStickersGrabber;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.navigation.Navigator;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import ru.vtosters.lite.tgs.TGPref;
|
||||
import ru.vtosters.lite.ui.adapters.StickerPackAdapter;
|
||||
import ru.vtosters.lite.ui.components.StickerTouchHelperCallback;
|
||||
import ru.vtosters.lite.ui.fragments.BaseToolbarFragment;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class StickersFragment extends BaseToolbarFragment {
|
||||
public final static String ACTION_RELOAD = "com.vtosters.lite.action.RELOAD_TGS_LIST";
|
||||
@@ -83,8 +68,8 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
@Override
|
||||
protected void onCreateMenu(Menu menu) {
|
||||
var item = menu.add(0, 0, 0, "");
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
item.setIcon(R.drawable.ic_settings_24);
|
||||
item.setIcon(ThemesUtils.recolorDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_settings_24)))
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
|
||||
super.onCreateMenu(menu);
|
||||
}
|
||||
@@ -97,7 +82,7 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
|
||||
private void openMenu(String toast) {
|
||||
if (toast != null) {
|
||||
makeText(getContext(), toast, LENGTH_SHORT).show();
|
||||
Toast.makeText(getContext(), toast, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
var intent = new Navigator(StickersPreferencesFragment.class, new Bundle()).b(getContext());
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
@@ -132,12 +117,12 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
|
||||
FloatingActionButton mAddStickerPack = new FloatingActionButton(getContext());
|
||||
mAddStickerPack.setImageResource(R.drawable.ic_add_24);
|
||||
mAddStickerPack.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
mAddStickerPack.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
mAddStickerPack.setOnClickListener(v2 -> fabClick());
|
||||
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(-2, -2);
|
||||
params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
||||
params.setMargins(0, 0, 0, dp2px(12f));
|
||||
params.setMargins(0, 0, 0, AndroidUtils.dp2px(12f));
|
||||
layout.addView(mAddStickerPack, params);
|
||||
|
||||
return layout;
|
||||
@@ -172,13 +157,13 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
LinearLayout linearLayout = new LinearLayout(getContext());
|
||||
|
||||
final EditText editText = new EditText(getContext());
|
||||
editText.setHintTextColor(getSTextAttr());
|
||||
editText.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
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(dp2px(24f), 0, dp2px(24f), 0);
|
||||
margin.setMargins(AndroidUtils.dp2px(24f), 0, AndroidUtils.dp2px(24f), 0);
|
||||
editText.setLayoutParams(margin);
|
||||
|
||||
new VkAlertDialog.Builder(getContext())
|
||||
@@ -190,7 +175,7 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
if (!pack.startsWith("https://")) {
|
||||
pack = "https://" + pack;
|
||||
} else if (!pack.contains("addstickers")) {
|
||||
sendToast(AndroidUtils.getString("invalid_pack_link"));
|
||||
AndroidUtils.sendToast(AndroidUtils.getString("invalid_pack_link"));
|
||||
}
|
||||
pack = parsePack(pack);
|
||||
mService.requestPackDownload(pack, new File(getContext().getFilesDir(), new File("VT-Stickers", pack).getAbsolutePath()));
|
||||
@@ -230,13 +215,13 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
LinearLayout linearLayout = new LinearLayout(getContext());
|
||||
|
||||
final EditText editText = new EditText(getContext());
|
||||
editText.setHintTextColor(getSTextAttr());
|
||||
editText.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
|
||||
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(dp2px(24f), 0, dp2px(24f), 0);
|
||||
margin.setMargins(AndroidUtils.dp2px(24f), 0, AndroidUtils.dp2px(24f), 0);
|
||||
editText.setLayoutParams(margin);
|
||||
|
||||
new VkAlertDialog.Builder(getContext())
|
||||
@@ -244,7 +229,7 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
.setMessage(requireContext().getString(R.string.stickersapi6))
|
||||
.setView(linearLayout)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
setTGBotKey(editText.getText().toString());
|
||||
TGPref.setTGBotKey(editText.getText().toString());
|
||||
if (r != null) r.run();
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel,
|
||||
@@ -276,8 +261,8 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
public void onKeyChecked(boolean ok) {
|
||||
progressDialog.dismiss();
|
||||
if (!ok) {
|
||||
makeText(context, requireContext().getString(R.string.stickersapi2), LENGTH_SHORT).show();
|
||||
setTGBotKey(null);
|
||||
Toast.makeText(context, requireContext().getString(R.string.stickersapi2), Toast.LENGTH_SHORT).show();
|
||||
TGPref.setTGBotKey(null);
|
||||
return;
|
||||
}
|
||||
mService.setBotKey(TGPref.getTGBotKey());
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
public class AlphaView extends SliderViewBase implements ColorObserver {
|
||||
|
||||
private ObservableColor observableColor = new ObservableColor(0);
|
||||
|
||||
public AlphaView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public void observeColor(ObservableColor observableColor) {
|
||||
this.observableColor = observableColor;
|
||||
observableColor.addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateColor(ObservableColor observableColor) {
|
||||
setPos((float)observableColor.getAlpha()/0xff);
|
||||
updateBitmap();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyListener(float currentPos) {
|
||||
observableColor.updateAlpha((int)(currentPos * 0xff), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPointerColor(float currentPos) {
|
||||
float solidColorLightness = observableColor.getLightness();
|
||||
float posLightness = 1 + currentPos * (solidColorLightness - 1);
|
||||
return posLightness > 0.5f ? 0xff000000 : 0xffffffff;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap makeBitmap(int w, int h) {
|
||||
final boolean isWide = w > h;
|
||||
final int n = Math.max(w, h);
|
||||
int color = observableColor.getColor();
|
||||
int[] colors = new int[n];
|
||||
for (int i = 0; i < n; ++i) {
|
||||
float alpha = isWide ? (float)i / n : 1 - (float)i / n;
|
||||
colors[i] = color & 0xffffff | (int)(alpha * 0xff) << 24;
|
||||
}
|
||||
final int bmpWidth = isWide ? w : 1;
|
||||
final int bmpHeight = isWide ? 1 : h;
|
||||
return Bitmap.createBitmap(colors, bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
public interface ColorObserver {
|
||||
|
||||
void updateColor(ObservableColor observableColor);
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.text.method.DigitsKeyListener;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import ru.vtosters.lite.utils.LayoutUtils;
|
||||
|
||||
public class ColorPickerView extends FrameLayout {
|
||||
|
||||
private final AlphaView alphaView;
|
||||
private final EditText hexEdit;
|
||||
private final ObservableColor observableColor = new ObservableColor(0);
|
||||
private final SwatchView swatchView;
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
public ColorPickerView(Context context) {
|
||||
super(context);
|
||||
|
||||
var container = new LinearLayout(context);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
container.setPadding(dp2px(16), dp2px(16), dp2px(16), dp2px(16));
|
||||
container.setGravity(Gravity.CENTER);
|
||||
this.addView(container, LayoutUtils.createFrame(-2, -2));
|
||||
|
||||
var colorPickerFrame = new FrameLayout(context);
|
||||
var colorPickerFrameParams = LayoutUtils.createLinear(-2, -2);
|
||||
colorPickerFrameParams.weight = 1.0f;
|
||||
container.addView(colorPickerFrame, colorPickerFrameParams);
|
||||
|
||||
swatchView = new SwatchView(context);
|
||||
colorPickerFrame.addView(swatchView, LayoutUtils.createFrame(-2, -2));
|
||||
|
||||
HueSatView hueSatView = new HueSatView(context);
|
||||
colorPickerFrame.addView(hueSatView, LayoutUtils.createFrame(-2, -2));
|
||||
|
||||
ValueView valueView = new ValueView(context);
|
||||
var valueViewParams = LayoutUtils.createLinear(-1, dp2px(36));
|
||||
valueViewParams.topMargin = dp2px(16);
|
||||
container.addView(valueView, valueViewParams);
|
||||
|
||||
alphaView = new AlphaView(context);
|
||||
var alphaViewParams = LayoutUtils.createLinear(-1, dp2px(36));
|
||||
valueViewParams.topMargin = dp2px(16);
|
||||
container.addView(alphaView, alphaViewParams);
|
||||
|
||||
hexEdit = new EditText(context);
|
||||
hexEdit.setText("000000");
|
||||
hexEdit.setKeyListener(DigitsKeyListener.getInstance("0123456789ABCDEFabcdef"));
|
||||
hexEdit.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
hexEdit.setFilters(new InputFilter[]{ new InputFilter.LengthFilter(4) });
|
||||
hexEdit.setBackground(null);
|
||||
hexEdit.setTypeface(Typeface.MONOSPACE);
|
||||
hexEdit.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
||||
hexEdit.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
container.addView(hexEdit, LayoutUtils.createLinear(-1, -2));
|
||||
|
||||
swatchView.observeColor(observableColor);
|
||||
hueSatView.observeColor(observableColor);
|
||||
valueView.observeColor(observableColor);
|
||||
alphaView.observeColor(observableColor);
|
||||
HexEdit.setUpListeners(hexEdit, observableColor);
|
||||
|
||||
showAlpha(false);
|
||||
showHex(true);
|
||||
showPreview(true);
|
||||
|
||||
// We get all our state saved and restored for free,
|
||||
// thanks to the EditText and its listeners!
|
||||
}
|
||||
|
||||
/** Returns the color selected by the user */
|
||||
public int getColor() {
|
||||
return observableColor.getColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the original color swatch and the current color to the specified value.<br>
|
||||
* Using dark colors may lead to a loss of color information caused by the ARGB color space.
|
||||
* Use {@link #setColor(int, float, float, float)} instead to avoid this.
|
||||
*/
|
||||
public void setColor(int color) {
|
||||
setOriginalColor(color);
|
||||
setCurrentColor(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the original color swatch and the current color to the specified value.
|
||||
*
|
||||
* <ul>
|
||||
* <li>Alpha [0...255]</li>
|
||||
* <li>Hue [0...360)</li>
|
||||
* <li>Saturation [0...1]</li>
|
||||
* <li>Brightness [0...1]</li>
|
||||
* </ul>
|
||||
*/ public void setColor(int alpha, float hue, float sat, float bri) {
|
||||
setOriginalColor(alpha, hue, sat, bri);
|
||||
setCurrentColor(alpha, hue, sat, bri);
|
||||
}
|
||||
|
||||
/** Sets the original color swatch without changing the current color. */
|
||||
public void setOriginalColor(int color) {
|
||||
swatchView.setOriginalColor(color);
|
||||
}
|
||||
|
||||
/** Sets the original color swatch without changing the current color. */
|
||||
public void setOriginalColor(int alpha, float hue, float sat, float bri) {
|
||||
int color = Color.HSVToColor(alpha, new float[]{hue, sat, bri});
|
||||
swatchView.setOriginalColor(color);
|
||||
}
|
||||
|
||||
/** Updates the current color without changing the original color swatch. */
|
||||
public void setCurrentColor(int color) {
|
||||
observableColor.updateColor(color, null);
|
||||
}
|
||||
|
||||
/** Updates the current color without changing the original color swatch. */
|
||||
public void setCurrentColor(int alpha, float hue, float sat, float bri) {
|
||||
observableColor.updateColor(alpha, hue, sat, bri, null);
|
||||
}
|
||||
|
||||
public void showAlpha(boolean showAlpha) {
|
||||
alphaView.setVisibility(showAlpha ? View.VISIBLE : View.GONE);
|
||||
HexEdit.setShowAlphaDigits(hexEdit, showAlpha);
|
||||
}
|
||||
|
||||
public void addColorObserver(ColorObserver observer) {
|
||||
observableColor.addObserver(observer);
|
||||
}
|
||||
|
||||
public void showHex(boolean showHex) {
|
||||
hexEdit.setVisibility(showHex ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
public void showPreview(boolean showPreview) {
|
||||
swatchView.setVisibility(showPreview ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextWatcher;
|
||||
import android.widget.EditText;
|
||||
|
||||
class HexEdit {
|
||||
|
||||
private static InputFilter[] withoutAlphaDigits = {new ColorPasteLengthFilter()};
|
||||
private static InputFilter[] withAlphaDigits = {new InputFilter.LengthFilter(8)};
|
||||
|
||||
public static void setUpListeners(final EditText hexEdit, final ObservableColor observableColor) {
|
||||
|
||||
class MultiObserver implements ColorObserver, TextWatcher {
|
||||
|
||||
@Override
|
||||
public void updateColor(ObservableColor observableColor) {
|
||||
final String colorString = formatColor(observableColor.getColor());
|
||||
// Prevent onTextChanged getting called when we update text programmatically
|
||||
hexEdit.removeTextChangedListener(this);
|
||||
hexEdit.setText(colorString);
|
||||
hexEdit.addTextChangedListener(this);
|
||||
}
|
||||
|
||||
private String formatColor(int color) {
|
||||
return shouldTrimAlphaDigits()
|
||||
? String.format("%06x", color & 0x00ffffff)
|
||||
: String.format("%08x", color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
int color = parseHexColor(s);
|
||||
if (shouldTrimAlphaDigits()) color = color | 0xff000000;
|
||||
observableColor.updateColor(color, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
private boolean shouldTrimAlphaDigits() {
|
||||
return hexEdit.getFilters() == withoutAlphaDigits;
|
||||
}
|
||||
}
|
||||
|
||||
final MultiObserver multiObserver = new MultiObserver();
|
||||
hexEdit.addTextChangedListener(multiObserver);
|
||||
observableColor.addObserver(multiObserver);
|
||||
setShowAlphaDigits(hexEdit, true);
|
||||
}
|
||||
|
||||
private static int parseHexColor(CharSequence s) {
|
||||
try {
|
||||
return (int)(Long.parseLong(s.toString(), 16) & 0xffffffffL);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return Color.GRAY;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setShowAlphaDigits(final EditText hexEdit, boolean showAlphaDigits) {
|
||||
hexEdit.setFilters(showAlphaDigits ? withAlphaDigits : withoutAlphaDigits);
|
||||
hexEdit.setText(hexEdit.getText()); // trigger a reformat of text
|
||||
}
|
||||
|
||||
|
||||
private static class ColorPasteLengthFilter implements InputFilter {
|
||||
|
||||
private static final int MAX_LENGTH = 6;
|
||||
private static final int PASTED_LEN = 8;
|
||||
private final InputFilter sixDigitFilter = new InputFilter.LengthFilter(MAX_LENGTH);
|
||||
|
||||
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
||||
// If 8 digits have been pasted, replacing all source, trim alpha digits.
|
||||
// Otherwise standard LengthFilter behavior.
|
||||
final int srcLength = end - start;
|
||||
final int dstSelLength = dend - dstart;
|
||||
if (srcLength == PASTED_LEN && dstSelLength == dest.length()) {
|
||||
// Discard alpha digits:
|
||||
return source.subSequence(PASTED_LEN - MAX_LENGTH, PASTED_LEN);
|
||||
}
|
||||
else {
|
||||
return sixDigitFilter.filter(source, start, end, dest, dstart, dend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Build;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class HueSatView extends SquareView implements ColorObserver {
|
||||
|
||||
private Paint borderPaint;
|
||||
private Paint pointerPaint;
|
||||
private Path pointerPath;
|
||||
private Path borderPath;
|
||||
private Rect viewRect = new Rect();
|
||||
private int w;
|
||||
private int h;
|
||||
|
||||
// Bitmap is generated once and shared across instances.
|
||||
private static Bitmap bitmap;
|
||||
|
||||
private final PointF pointer = new PointF();
|
||||
private ObservableColor observableColor = new ObservableColor(0);
|
||||
|
||||
public HueSatView(Context context) {
|
||||
super(context);
|
||||
|
||||
borderPaint = Resources.makeLinePaint();
|
||||
pointerPaint = Resources.makeLinePaint();
|
||||
pointerPaint.setColor(0xff000000);
|
||||
pointerPath = Resources.makePointerPath();
|
||||
borderPath = new Path();
|
||||
if (bitmap == null) {
|
||||
bitmap = makeBitmap(optimalBitmapSize());
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
||||
// Need clipPath() and setLayerType()...
|
||||
throw new UnsupportedOperationException("Android API 10 and below is not supported.");
|
||||
}
|
||||
else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
// clipPath() is only supported on a software layer.
|
||||
setLayerType(LAYER_TYPE_SOFTWARE, null);
|
||||
}
|
||||
}
|
||||
|
||||
private int optimalBitmapSize() {
|
||||
final int scale = 2;
|
||||
final int maxBitmapSize = 128;
|
||||
final DisplayMetrics dm = getResources().getDisplayMetrics();
|
||||
return Math.min(maxBitmapSize, Math.min(dm.widthPixels, dm.heightPixels) / scale);
|
||||
}
|
||||
|
||||
public void observeColor(ObservableColor observableColor) {
|
||||
this.observableColor = observableColor;
|
||||
observableColor.addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateColor(ObservableColor observableColor) {
|
||||
setPointer(pointer, observableColor.getHue(), observableColor.getSat(), w);
|
||||
optimisePointerColor();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
viewRect.set(0, 0, w, h);
|
||||
|
||||
float inset = borderPaint.getStrokeWidth() / 2;
|
||||
makeBorderPath(borderPath, w, h, inset);
|
||||
|
||||
// Sets pointer position
|
||||
updateColor(observableColor);
|
||||
}
|
||||
|
||||
private static void makeBorderPath(Path borderPath, int w, int h, float inset) {
|
||||
w -= inset;
|
||||
h -= inset;
|
||||
borderPath.reset();
|
||||
borderPath.moveTo(w, inset);
|
||||
borderPath.lineTo(w, h);
|
||||
borderPath.lineTo(inset, h);
|
||||
borderPath.addArc(new RectF(inset, inset, 2 * w, 2 * h), 180, 270);
|
||||
borderPath.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
int action = event.getActionMasked();
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
boolean withinPicker = clamp(pointer, event.getX(), event.getY(), true);
|
||||
if (withinPicker) update();
|
||||
return withinPicker;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
clamp(pointer, event.getX(), event.getY(), false);
|
||||
update();
|
||||
getParent().requestDisallowInterceptTouchEvent(true);
|
||||
return true;
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
observableColor.updateHueSat(
|
||||
hueForPos(pointer.x, pointer.y, w),
|
||||
satForPos(pointer.x, pointer.y, w),
|
||||
this);
|
||||
optimisePointerColor();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private boolean clamp(PointF pointer, float x, float y, boolean rejectOutside) {
|
||||
x = Math.min(x, w);
|
||||
y = Math.min(y, h);
|
||||
final float dx = w - x;
|
||||
final float dy = h - y;
|
||||
final float r = (float)Math.sqrt(dx * dx + dy * dy);
|
||||
boolean outside = r > w;
|
||||
if (!outside || !rejectOutside) {
|
||||
if (outside) {
|
||||
x = w - dx * w / r;
|
||||
y = w - dy * w / r;
|
||||
}
|
||||
pointer.set(x, y);
|
||||
}
|
||||
return !outside;
|
||||
}
|
||||
|
||||
private void optimisePointerColor() {
|
||||
pointerPaint.setColor(
|
||||
observableColor.getLightnessWithValue(1) > 0.5
|
||||
? 0xff000000 : 0xffffffff);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
canvas.save();
|
||||
|
||||
canvas.clipPath(borderPath);
|
||||
canvas.drawBitmap(bitmap, null, viewRect, null);
|
||||
canvas.translate(pointer.x, pointer.y);
|
||||
canvas.drawPath(pointerPath, pointerPaint);
|
||||
|
||||
canvas.restore();
|
||||
|
||||
canvas.drawPath(borderPath, borderPaint);
|
||||
}
|
||||
|
||||
private static Bitmap makeBitmap(int radiusPx) {
|
||||
int[] colors = new int[radiusPx * radiusPx];
|
||||
float[] hsv = new float[]{0f, 0f, 1f};
|
||||
for (int y = 0; y < radiusPx; ++y) {
|
||||
for (int x = 0; x < radiusPx; ++x) {
|
||||
final int i = x + y * radiusPx;
|
||||
final float sat = satForPos(x, y, radiusPx);
|
||||
final float arcBleed = 2f / radiusPx; // extend curved edge pixels just outside clip area.
|
||||
if (sat <= 1 + arcBleed) {
|
||||
hsv[0] = hueForPos(x, y, radiusPx);
|
||||
hsv[1] = sat;
|
||||
colors[i] = Color.HSVToColor(0xff, hsv);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Bitmap.createBitmap(colors, radiusPx, radiusPx, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
private static float hueForPos(float x, float y, float radiusPx) {
|
||||
final double r = radiusPx - 1; // gives values 0...1 inclusive
|
||||
final double dx = (r - x) / r;
|
||||
final double dy = (r - y) / r;
|
||||
final double angle = Math.atan2(dy, dx);
|
||||
final double hue = 360 * angle / (Math.PI / 2);
|
||||
return (float)hue;
|
||||
}
|
||||
|
||||
private static float satForPos(float x, float y, float radiusPx) {
|
||||
final double r = radiusPx - 1; // gives values 0...1 inclusive
|
||||
final double dx = (r - x) / r;
|
||||
final double dy = (r - y) / r;
|
||||
final double sat = dx * dx + dy * dy; // leave it squared -- exaggerates pale colors
|
||||
return (float)sat;
|
||||
}
|
||||
|
||||
private static void setPointer(PointF pointer, float hue, float sat, float radiusPx) {
|
||||
final float r = radiusPx - 1; // for values 0...1 inclusive
|
||||
final double distance = r * Math.sqrt(sat);
|
||||
final double angle = hue / 360 * Math.PI / 2;
|
||||
final double dx = distance * Math.cos(angle);
|
||||
final double dy = distance * Math.sin(angle);
|
||||
pointer.set(r - (float)dx, r - (float)dy);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ObservableColor {
|
||||
|
||||
// Store as HSV & A, otherwise round-trip to int causes color drift.
|
||||
private final float[] hsv = {0, 0, 0};
|
||||
private int alpha;
|
||||
private final List<ColorObserver> observers = new ArrayList<ColorObserver>();
|
||||
|
||||
public ObservableColor(int color) {
|
||||
Color.colorToHSV(color, hsv);
|
||||
alpha = Color.alpha(color);
|
||||
}
|
||||
|
||||
public void getHsv(float hsvOut[]) {
|
||||
hsvOut[0] = hsv[0];
|
||||
hsvOut[1] = hsv[1];
|
||||
hsvOut[2] = hsv[2];
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return Color.HSVToColor(alpha, hsv);
|
||||
}
|
||||
|
||||
public float getHue() {
|
||||
return hsv[0];
|
||||
}
|
||||
|
||||
public float getSat() {
|
||||
return hsv[1];
|
||||
}
|
||||
|
||||
public float getValue() {
|
||||
return hsv[2];
|
||||
}
|
||||
|
||||
public int getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public float getLightness() {
|
||||
return getLightnessWithValue(hsv[2]);
|
||||
}
|
||||
|
||||
public float getLightnessWithValue(float value) {
|
||||
float[] hsV = {hsv[0], hsv[1], value};
|
||||
final int color = Color.HSVToColor(hsV);
|
||||
return (Color.red(color) * 0.2126f + Color.green(color) * 0.7152f + Color.blue(color) * 0.0722f)/0xff;
|
||||
}
|
||||
|
||||
public void addObserver(ColorObserver observer) {
|
||||
observers.add(observer);
|
||||
}
|
||||
|
||||
public void updateHueSat(float hue, float sat, ColorObserver sender) {
|
||||
hsv[0] = hue;
|
||||
hsv[1] = sat;
|
||||
notifyOtherObservers(sender);
|
||||
}
|
||||
|
||||
public void updateValue(float value, ColorObserver sender) {
|
||||
hsv[2] = value;
|
||||
notifyOtherObservers(sender);
|
||||
}
|
||||
|
||||
public void updateAlpha(int alpha, ColorObserver sender) {
|
||||
this.alpha = alpha;
|
||||
notifyOtherObservers(sender);
|
||||
}
|
||||
|
||||
public void updateColor(int color, ColorObserver sender) {
|
||||
Color.colorToHSV(color, hsv);
|
||||
alpha = Color.alpha(color);
|
||||
notifyOtherObservers(sender);
|
||||
}
|
||||
|
||||
public void updateColor(int alpha, float hue, float sat, float bri, ColorObserver sender) {
|
||||
this.alpha = alpha;
|
||||
hsv[0] = hue;
|
||||
hsv[1] = sat;
|
||||
hsv[2] = bri;
|
||||
notifyOtherObservers(sender);
|
||||
}
|
||||
|
||||
private void notifyOtherObservers(ColorObserver sender) {
|
||||
for (ColorObserver observer : observers) {
|
||||
if (observer != sender) {
|
||||
observer.updateColor(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Shader;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
class Resources {
|
||||
|
||||
private static final float LINE_WIDTH_DIP = 1.5f;
|
||||
private static final float POINTER_RADIUS_DIP = 7;
|
||||
private static final int VIEW_OUTLINE_COLOR = 0xff808080;
|
||||
|
||||
public static Paint makeLinePaint() {
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(VIEW_OUTLINE_COLOR);
|
||||
paint.setStrokeWidth(dp2px(LINE_WIDTH_DIP));
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setAntiAlias(true);
|
||||
return paint;
|
||||
}
|
||||
|
||||
public static Paint makeCheckerPaint(Context context) {
|
||||
Paint paint = new Paint();
|
||||
final Bitmap checkerBmp = BitmapFactory.decodeResource(context.getResources(), AndroidUtils.getIdentifier("checker_background", "drawable"));
|
||||
paint.setShader(new BitmapShader(checkerBmp, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
|
||||
paint.setStrokeWidth(dp2px(LINE_WIDTH_DIP));
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setAntiAlias(true);
|
||||
return paint;
|
||||
}
|
||||
|
||||
public static Path makePointerPath() {
|
||||
Path pointerPath = new Path();
|
||||
final float radiusPx = dp2px(POINTER_RADIUS_DIP);
|
||||
pointerPath.addCircle(0, 0, radiusPx, Path.Direction.CW);
|
||||
return pointerPath;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public abstract class SliderViewBase extends View {
|
||||
|
||||
private final Paint borderPaint;
|
||||
private final Paint checkerPaint;
|
||||
private final Rect viewRect = new Rect();
|
||||
private int w;
|
||||
private int h;
|
||||
private final Path borderPath;
|
||||
private Bitmap bitmap;
|
||||
private final Path pointerPath;
|
||||
private final Paint pointerPaint;
|
||||
|
||||
private float currentPos;
|
||||
|
||||
public SliderViewBase(Context context) {
|
||||
super(context);
|
||||
checkerPaint = Resources.makeCheckerPaint(context);
|
||||
borderPaint = Resources.makeLinePaint();
|
||||
pointerPaint = Resources.makeLinePaint();
|
||||
pointerPath = Resources.makePointerPath();
|
||||
borderPath = new Path();
|
||||
}
|
||||
|
||||
protected abstract void notifyListener(float currentPos);
|
||||
|
||||
protected abstract Bitmap makeBitmap(int w, int h);
|
||||
|
||||
protected abstract int getPointerColor(float currentPos);
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
viewRect.set(0, 0, w, h);
|
||||
float inset = borderPaint.getStrokeWidth() / 2;
|
||||
borderPath.reset();
|
||||
borderPath.addRect(new RectF(inset, inset, w - inset, h - inset), Path.Direction.CW);
|
||||
updateBitmap();
|
||||
}
|
||||
|
||||
protected void setPos(float pos) {
|
||||
currentPos = pos;
|
||||
optimisePointerColor();
|
||||
}
|
||||
|
||||
protected void updateBitmap() {
|
||||
if (w > 0 && h > 0) {
|
||||
bitmap = makeBitmap(w, h);
|
||||
optimisePointerColor();
|
||||
}
|
||||
// else not ready yet
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
int action = event.getActionMasked();
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
currentPos = valueForTouchPos(event.getX(), event.getY());
|
||||
optimisePointerColor();
|
||||
notifyListener(currentPos);
|
||||
invalidate();
|
||||
getParent().requestDisallowInterceptTouchEvent(true);
|
||||
return true;
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
canvas.drawPath(borderPath, checkerPaint);
|
||||
canvas.drawBitmap(bitmap, null, viewRect, null);
|
||||
canvas.drawPath(borderPath, borderPaint);
|
||||
|
||||
canvas.save();
|
||||
if (isWide()) {
|
||||
canvas.translate(w * currentPos, h / 2);
|
||||
}
|
||||
else {
|
||||
canvas.translate(w / 2, h * (1 - currentPos));
|
||||
}
|
||||
canvas.drawPath(pointerPath, pointerPaint);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
private boolean isWide() {
|
||||
return w > h;
|
||||
}
|
||||
|
||||
private float valueForTouchPos(float x, float y) {
|
||||
final float val = isWide() ? x / w : 1 - y / h;
|
||||
return Math.max(0, Math.min(1, val));
|
||||
}
|
||||
|
||||
private void optimisePointerColor() {
|
||||
pointerPaint.setColor(getPointerColor(currentPos));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
class SquareView extends View {
|
||||
private static final int MIN_SIZE_DIP = 200;
|
||||
|
||||
private final int minSizePx;
|
||||
|
||||
public SquareView(Context context) {
|
||||
super(context);
|
||||
minSizePx = dp2px(MIN_SIZE_DIP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
// Constrain to square
|
||||
final int w = MeasureSpec.getSize(widthMeasureSpec);
|
||||
final int h = MeasureSpec.getSize(heightMeasureSpec);
|
||||
final int modeW = MeasureSpec.getMode(widthMeasureSpec);
|
||||
final int modeH = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int size = minSizePx;
|
||||
if (modeW == MeasureSpec.UNSPECIFIED) {
|
||||
size = h;
|
||||
}
|
||||
else if (modeH == MeasureSpec.UNSPECIFIED) {
|
||||
size = w;
|
||||
}
|
||||
else {
|
||||
size = Math.min(w, h);
|
||||
}
|
||||
size = Math.max(size, minSizePx);
|
||||
setMeasuredDimension(size, size);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.RectF;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class SwatchView extends SquareView implements ColorObserver {
|
||||
|
||||
private final Paint borderPaint;
|
||||
private final Path borderPath;
|
||||
private final Paint checkerPaint;
|
||||
private final Path oldFillPath;
|
||||
private final Path newFillPath;
|
||||
private final Paint oldFillPaint;
|
||||
private final Paint newFillPaint;
|
||||
private final float radialMarginPx;
|
||||
|
||||
public SwatchView(Context context) {
|
||||
super(context);
|
||||
|
||||
radialMarginPx = AndroidUtils.dp2px(16);
|
||||
|
||||
borderPaint = Resources.makeLinePaint();
|
||||
checkerPaint = Resources.makeCheckerPaint(context);
|
||||
oldFillPaint = new Paint();
|
||||
newFillPaint = new Paint();
|
||||
|
||||
borderPath = new Path();
|
||||
oldFillPath = new Path();
|
||||
newFillPath = new Path();
|
||||
}
|
||||
|
||||
void setOriginalColor(int color) {
|
||||
oldFillPaint.setColor(color);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void observeColor(ObservableColor observableColor) {
|
||||
observableColor.addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateColor(ObservableColor observableColor) {
|
||||
newFillPaint.setColor(observableColor.getColor());
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
// We expect to be stacked behind a square HueSatView and fill the top left corner.
|
||||
|
||||
final float inset = borderPaint.getStrokeWidth() / 2;
|
||||
final float r = Math.min(w, h);
|
||||
|
||||
// Trim the corners of the swatch is where it is radialMarginPx thick.
|
||||
// find how long the outeredges are:
|
||||
final float margin = radialMarginPx;
|
||||
final float diagonal = r + 2 * margin;
|
||||
final float opp = (float)Math.sqrt(diagonal * diagonal - r * r);
|
||||
final float edgeLen = r - opp;
|
||||
|
||||
// Arc angles for drawing CCW
|
||||
final float outerAngle = (float)Math.toDegrees(Math.atan2(opp, r));
|
||||
final float startAngle = 270 - outerAngle;
|
||||
// Sweep angle for each half of the swatch:
|
||||
final float sweepAngle = outerAngle - 45;
|
||||
// Sweep angle for the smooth corners:
|
||||
final float cornerSweepAngle = 90 - outerAngle;
|
||||
|
||||
// Outer border:
|
||||
beginBorder(borderPath, inset, edgeLen, margin, cornerSweepAngle);
|
||||
mainArc(borderPath, r, margin, startAngle, 2 * sweepAngle);
|
||||
endBorder(borderPath, inset, edgeLen, margin, cornerSweepAngle);
|
||||
|
||||
// Old fill shape:
|
||||
oldFillPath.reset();
|
||||
oldFillPath.moveTo(inset, inset);
|
||||
mainArc(oldFillPath, r, margin, 225, sweepAngle);
|
||||
endBorder(oldFillPath, inset, edgeLen, margin, cornerSweepAngle);
|
||||
|
||||
// New fill shape:
|
||||
beginBorder(newFillPath, inset, edgeLen, margin, cornerSweepAngle);
|
||||
mainArc(newFillPath, r, margin, startAngle, sweepAngle);
|
||||
newFillPath.lineTo(inset, inset);
|
||||
newFillPath.close();
|
||||
}
|
||||
|
||||
private static void beginBorder(Path path, float inset, float edgeLen, float cornerRadius, float cornerSweepAngle) {
|
||||
path.reset();
|
||||
path.moveTo(inset, inset);
|
||||
cornerArc(path, edgeLen, inset, cornerRadius-inset, 0, cornerSweepAngle);
|
||||
}
|
||||
|
||||
private static void endBorder(Path path, float inset, float edgeLen, float cornerRadius, float cornerSweepAngle) {
|
||||
cornerArc(path, inset, edgeLen, cornerRadius - inset, 90 - cornerSweepAngle, cornerSweepAngle);
|
||||
path.lineTo(inset, inset);
|
||||
path.close();
|
||||
}
|
||||
|
||||
private static void cornerArc(Path path, float cx, float cy, float r, float startAngle, float sweepAngle) {
|
||||
final RectF ovalRect = new RectF(-r, -r, r, r);
|
||||
ovalRect.offset(cx, cy);
|
||||
path.arcTo(ovalRect, startAngle, sweepAngle);
|
||||
}
|
||||
|
||||
private static void mainArc(Path path, float viewSize, float margin, float startAngle, float sweepAngle) {
|
||||
float r = viewSize + margin;
|
||||
final RectF ovalRect = new RectF(-r, -r, r, r);
|
||||
ovalRect.offset(viewSize, viewSize);
|
||||
path.arcTo(ovalRect, startAngle, sweepAngle);
|
||||
}
|
||||
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
canvas.drawPath(borderPath, checkerPaint);
|
||||
canvas.drawPath(oldFillPath, oldFillPaint);
|
||||
canvas.drawPath(newFillPath, newFillPaint);
|
||||
canvas.drawPath(borderPath, borderPaint);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package ru.vtosters.lite.ui.views.rarepebble;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
||||
public class ValueView extends SliderViewBase implements ColorObserver {
|
||||
|
||||
private ObservableColor observableColor = new ObservableColor(0);
|
||||
|
||||
public ValueView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public void observeColor(ObservableColor observableColor) {
|
||||
this.observableColor = observableColor;
|
||||
observableColor.addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateColor(ObservableColor observableColor) {
|
||||
setPos(this.observableColor.getValue());
|
||||
updateBitmap();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyListener(float currentPos) {
|
||||
observableColor.updateValue(currentPos, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPointerColor(float currentPos) {
|
||||
float brightColorLightness = observableColor.getLightness();
|
||||
float posLightness = currentPos * brightColorLightness;
|
||||
return posLightness > 0.5f ? 0xff000000 : 0xffffffff;
|
||||
}
|
||||
|
||||
protected Bitmap makeBitmap(int w, int h) {
|
||||
final boolean isWide = w > h;
|
||||
final int n = Math.max(w, h);
|
||||
int[] colors = new int[n];
|
||||
|
||||
float[] hsv = new float[]{0, 0, 0};
|
||||
observableColor.getHsv(hsv);
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
hsv[2] = isWide ? (float)i / n : 1 - (float)i / n;
|
||||
colors[i] = Color.HSVToColor(hsv);
|
||||
}
|
||||
final int bmpWidth = isWide ? w : 1;
|
||||
final int bmpHeight = isWide ? 1 : h;
|
||||
return Bitmap.createBitmap(colors, bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +1,55 @@
|
||||
package ru.vtosters.lite.ui.vkui;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.vk.core.dialogs.bottomsheet.ModalBottomSheet;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
public class ModalBottomSheetWrapper {
|
||||
public final ModalBottomSheet.a builder;
|
||||
public class ModalBottomSheetWrapper<T> {
|
||||
public final ModalBottomSheet.a mBuilder;
|
||||
public ModalBottomSheet mBottomSheet;
|
||||
|
||||
public ModalBottomSheetWrapper(Activity activity) {
|
||||
builder = new ModalBottomSheet.a(activity);
|
||||
mBuilder = new ModalBottomSheet.a(activity);
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setTitle(String title) {
|
||||
builder.d(title);
|
||||
return this;
|
||||
public T setTitle(String title) {
|
||||
mBuilder.d(title);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
public ModalBottomSheetWrapper setUpdateInfoView(String changelog) {
|
||||
var context = getGlobalContext();
|
||||
var container = new LinearLayout(context);
|
||||
var changelogView = new TextView(context);
|
||||
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
changelogView.setPadding(0, dp2px(8), 0, 0);
|
||||
changelogView.setText(context.getString(R.string.changelog) + ": \n" + changelog);
|
||||
changelogView.setTextColor(getTextAttr());
|
||||
container.addView(changelogView, new LinearLayout.LayoutParams(-1, -2));
|
||||
|
||||
builder.a(container);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setClickableMessage(
|
||||
public T setClickableMessage(
|
||||
String text,
|
||||
Runnable callback
|
||||
) {
|
||||
builder.a(text, listener -> callback.run());
|
||||
return this;
|
||||
mBuilder.a(text, listener -> callback.run());
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setPositiveButton(
|
||||
public T setPositiveButton(
|
||||
String text,
|
||||
Runnable callback
|
||||
) {
|
||||
builder.a(text, kostil -> callback.run());
|
||||
return this;
|
||||
mBuilder.a(text, listener -> callback.run());
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setView(View view) {
|
||||
builder.a(view);
|
||||
return this;
|
||||
public T setView(View view) {
|
||||
mBuilder.a(view);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public ModalBottomSheet show() {
|
||||
return builder.a("");
|
||||
public ModalBottomSheet show(String tag) {
|
||||
return mBuilder.a(tag);
|
||||
}
|
||||
|
||||
public ModalBottomSheet show(boolean isCancellable) {
|
||||
var sheet = builder.a("");
|
||||
sheet.setCancelable(isCancellable);
|
||||
return sheet;
|
||||
public ModalBottomSheet show(String tag, boolean isCancellable) {
|
||||
mBottomSheet = mBuilder.a(tag);
|
||||
mBottomSheet.setCancelable(isCancellable);
|
||||
return mBottomSheet;
|
||||
}
|
||||
|
||||
public void dismiss() {
|
||||
mBottomSheet.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class VBottomSheetBuilder {
|
||||
public static void show(Activity activity, VBSContent content) {
|
||||
public static void show(Activity activity, VBSContent content, String tag) {
|
||||
ModalBottomSheetWrapper builder = new ModalBottomSheetWrapper(activity);
|
||||
|
||||
builder.setView(content.view);
|
||||
@@ -20,9 +20,10 @@ public class VBottomSheetBuilder {
|
||||
new Handler(Looper.getMainLooper()).post(content.button.action);
|
||||
}); // Positive
|
||||
|
||||
builder.show(); // Build+Show
|
||||
builder.show(tag); // Build+Show
|
||||
}
|
||||
|
||||
|
||||
public static class VBSContent {
|
||||
public String title;
|
||||
@Nullable
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.ui.adapters.MessagesPreviewAdapter;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class WallpaperPreferences extends Preference {
|
||||
|
||||
@@ -49,7 +50,7 @@ public class WallpaperPreferences extends Preference {
|
||||
mRecyclerView = (RecyclerView) preferenceViewHolder.findViewById(R.id.install_btn_container);
|
||||
mRecyclerView.setPadding(0, dp2px(8), 0, 0);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
mRecyclerView.setAdapter((mAdapter = new MessagesPreviewAdapter()));
|
||||
mRecyclerView.setAdapter((mAdapter = new MessagesPreviewAdapter(AndroidUtils.getArray(R.array.wallpaper_change_dialog))));
|
||||
mRecyclerView.setClickable(false);
|
||||
mRecyclerView.setFocusable(false);
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class WallpapersHooks {
|
||||
}
|
||||
|
||||
public static void setBg(View view) {
|
||||
if (getWallpaper() != null) {
|
||||
if (hasWallpapers()) {
|
||||
((ImageView) view).setImageDrawable(getFilteredFile()); // set picture to background
|
||||
} else {
|
||||
view.setBackgroundColor(ThemesUtils.getColorFromAttr(im_bg_chat)); // set default bg color
|
||||
@@ -103,6 +103,10 @@ public class WallpapersHooks {
|
||||
return "default";
|
||||
}
|
||||
|
||||
public static boolean hasWallpapers() {
|
||||
return getWallpaper() != null;
|
||||
}
|
||||
|
||||
public static Drawable getWallpaper() {
|
||||
if (mWallpaper == null || mUpdateWallpaperRequested) {
|
||||
String url = getWallpaperUrl();
|
||||
|
||||
@@ -2,6 +2,10 @@ package ru.vtosters.lite.utils;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/*
|
||||
*Extension of Base64 class for decoding/encoding with flag NO_PADDING
|
||||
*/
|
||||
@@ -14,4 +18,12 @@ public class Base64Utils {
|
||||
public static String encode(String base) {
|
||||
return Base64.encodeToString(base.getBytes(), Base64.NO_PADDING);
|
||||
}
|
||||
|
||||
public static String encodeValue(String value) {
|
||||
try {
|
||||
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
import static android.text.TextUtils.isEmpty;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.isEnableExternalOpening;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.dto.common.VideoFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.isEnableExternalOpening;
|
||||
|
||||
public class ExternalLinkParser {
|
||||
private static final String TAG = "ExternalLinkHandler";
|
||||
|
||||
private static final List<String> filters = Arrays.asList(
|
||||
"youtube.com",
|
||||
@@ -30,7 +26,6 @@ public class ExternalLinkParser {
|
||||
"youtu.be",
|
||||
"m.youtube.com"
|
||||
);
|
||||
private static final Map<String, String> qualities = new HashMap<>();
|
||||
|
||||
public static boolean parseVideoFile(VideoFile file) {
|
||||
return parseVideoFile(file, getGlobalContext(), isEnableExternalOpening());
|
||||
@@ -44,12 +39,12 @@ public class ExternalLinkParser {
|
||||
return parseVideoFile(file, activity, isEnableExternalOpening());
|
||||
}
|
||||
|
||||
public static boolean parseVideoFile(VideoFile file, Context context, Boolean isEnabled) {
|
||||
if (checkYoutubeLink(file)) {
|
||||
public static boolean parseVideoFile(VideoFile videoFile, Context context, Boolean isEnabled) {
|
||||
if (checkYoutubeLink(videoFile)) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.setData(Uri.parse(file.G));
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.setData(Uri.parse(videoFile.G));
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
@@ -57,23 +52,28 @@ public class ExternalLinkParser {
|
||||
}
|
||||
}
|
||||
|
||||
if (!isEnabled || file.isEmpty()) return false;
|
||||
if (!isEnabled || videoFile.isEmpty()) return false;
|
||||
|
||||
if (checkVkVideo(file)) {
|
||||
if (qualities.size() == 1 || getBoolValue("maxquality", false)) {
|
||||
startExternalVideo((String) qualities.values().toArray()[0], context);
|
||||
} else {
|
||||
String[] titles = qualities.keySet().toArray(new String[0]);
|
||||
List<String> urls = new ArrayList<>();
|
||||
List<String> qualities = new ArrayList<>();
|
||||
|
||||
parseVKVideo(videoFile, qualities, urls);
|
||||
|
||||
if (urls.size() > 0)
|
||||
if (getBoolValue("maxquality", false) || qualities.size() == 1)
|
||||
startExternalVideo(context, urls.get(0));
|
||||
else
|
||||
new VkAlertDialog.Builder(context)
|
||||
.setItems(titles, ((dialog, which) -> startExternalVideo(qualities.get(titles[which]), context)))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
.setItems(
|
||||
qualities.toArray(new String[0]),
|
||||
(dialog, which) -> startExternalVideo(context, urls.get(which))
|
||||
)
|
||||
.show();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean checkYoutubeLink(VideoFile file) {
|
||||
if (!isEmpty(file.G)) {
|
||||
if (!TextUtils.isEmpty(file.G)) {
|
||||
for (String filter : filters) {
|
||||
if (file.G.contains(filter))
|
||||
return true;
|
||||
@@ -91,52 +91,64 @@ public class ExternalLinkParser {
|
||||
* this.C = var66.optString("mp4_1440");
|
||||
* this.D = var66.optString("mp4_2160");
|
||||
*/
|
||||
public static boolean checkVkVideo(VideoFile videoFile) {
|
||||
if (!isEmpty(videoFile.e)) {
|
||||
qualities.put("240", videoFile.e);
|
||||
public static boolean parseVKVideo(VideoFile videoFile, List<String> qualities, List<String> urls) {
|
||||
if (!TextUtils.isEmpty(videoFile.D)) {
|
||||
qualities.add("2160p");
|
||||
urls.add(videoFile.D);
|
||||
}
|
||||
if (!isEmpty(videoFile.f)) {
|
||||
qualities.put("360", videoFile.f);
|
||||
|
||||
if (!TextUtils.isEmpty(videoFile.C)) {
|
||||
qualities.add("1440p");
|
||||
urls.add(videoFile.C);
|
||||
}
|
||||
if (!isEmpty(videoFile.g)) {
|
||||
qualities.put("480", videoFile.g);
|
||||
|
||||
if (!TextUtils.isEmpty(videoFile.B)) {
|
||||
qualities.add("1080p");
|
||||
urls.add(videoFile.B);
|
||||
}
|
||||
if (!isEmpty(videoFile.h)) {
|
||||
qualities.put("720", videoFile.h);
|
||||
|
||||
if (!TextUtils.isEmpty(videoFile.h)) {
|
||||
qualities.add("720p");
|
||||
urls.add(videoFile.h);
|
||||
}
|
||||
if (!isEmpty(videoFile.B)) {
|
||||
qualities.put("1080", videoFile.B);
|
||||
|
||||
if (!TextUtils.isEmpty(videoFile.g)) {
|
||||
qualities.add("480p");
|
||||
urls.add(videoFile.g);
|
||||
}
|
||||
if (!isEmpty(videoFile.C)) {
|
||||
qualities.put("1440", videoFile.C);
|
||||
|
||||
if (!TextUtils.isEmpty(videoFile.f)) {
|
||||
qualities.add("360p");
|
||||
urls.add(videoFile.f);
|
||||
}
|
||||
if (!isEmpty(videoFile.D)) {
|
||||
qualities.put("2160", videoFile.D);
|
||||
|
||||
if (!TextUtils.isEmpty(videoFile.e)) {
|
||||
qualities.add("240p");
|
||||
urls.add(videoFile.e);
|
||||
}
|
||||
|
||||
return qualities.size() > 0;
|
||||
}
|
||||
|
||||
public static boolean startExternalVideo(String url, Context ctx) {
|
||||
public static boolean startExternalVideo(Context context, String url) {
|
||||
try {
|
||||
qualities.clear();
|
||||
|
||||
Uri uri = Uri.parse(url);
|
||||
Intent intent = new Intent();
|
||||
|
||||
String packageName = getMXPlayerPackageName();
|
||||
if (!isEmpty(packageName)) {
|
||||
intent.setPackage(packageName);
|
||||
intent.setDataAndType(uri, "application/mp4");
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
String packageName = getMXPlayerPackageName(context);
|
||||
if (!TextUtils.isEmpty(packageName)) {
|
||||
intent.setPackage(packageName)
|
||||
.setDataAndType(uri, "application/mp4")
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
} else {
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, "video/mp4");
|
||||
intent.setAction(Intent.ACTION_VIEW)
|
||||
.setDataAndType(uri, "video/mp4");
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
}
|
||||
ctx.startActivity(intent);
|
||||
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -145,12 +157,11 @@ public class ExternalLinkParser {
|
||||
}
|
||||
|
||||
@SuppressLint("QueryPermissionsNeeded")
|
||||
private static String getMXPlayerPackageName() {
|
||||
for (ApplicationInfo info : getGlobalContext().getPackageManager().getInstalledApplications(0)) {
|
||||
String packName = info.packageName;
|
||||
if (packName.equals("com.mxtech.videoplayer.ad") || packName.equals("com.mxtech.videoplayer.pro"))
|
||||
return packName;
|
||||
}
|
||||
private static String getMXPlayerPackageName(Context context) {
|
||||
for (var info : context.getPackageManager().getInstalledApplications(0))
|
||||
if ("com.mxtech.videoplayer.ad".equals(info.packageName)
|
||||
|| "com.mxtech.videoplayer.pro".equals(info.packageName))
|
||||
return info.packageName;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,7 @@ public class IOUtils {
|
||||
|
||||
public static byte[] decodeStream(InputStream encIs, String keyURL) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IOException {
|
||||
CipherInputStream cip = new CipherInputStream(encIs, getCipher(keyURL));
|
||||
var bytes = readAllBytes(cip);
|
||||
cip.close();
|
||||
|
||||
return bytes;
|
||||
return readAllBytes(cip);
|
||||
}
|
||||
|
||||
public static Cipher getCipher(String key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException {
|
||||
@@ -49,23 +46,15 @@ public class IOUtils {
|
||||
}
|
||||
|
||||
public static String readAllLines(File file) throws IOException {
|
||||
var is = new FileInputStream(file);
|
||||
var bytes = readAllBytes(is);
|
||||
is.close();
|
||||
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
return readAllLines(new FileInputStream(file));
|
||||
}
|
||||
|
||||
public static String readAllLines(InputStream is) throws IOException {
|
||||
return new String(readAllBytes(is), StandardCharsets.UTF_8);
|
||||
return new String(readAllBytes(is), "utf-8");
|
||||
}
|
||||
|
||||
public static byte[] readAllBytes(File file) throws IOException {
|
||||
var is = new FileInputStream(file);
|
||||
var bytes = readAllBytes(is);
|
||||
is.close();
|
||||
|
||||
return bytes;
|
||||
return readAllBytes(new FileInputStream(file));
|
||||
}
|
||||
|
||||
public static byte[] readAllBytes(InputStream is) throws IOException {
|
||||
@@ -74,11 +63,9 @@ public class IOUtils {
|
||||
int len;
|
||||
while ((len = is.read(buffer)) > 0)
|
||||
bos.write(buffer, 0, len);
|
||||
|
||||
var bytes = bos.toByteArray();
|
||||
is.close();
|
||||
bos.close();
|
||||
|
||||
return bytes;
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
public static void writeToFile(File file, String content) throws IOException {
|
||||
@@ -86,11 +73,35 @@ public class IOUtils {
|
||||
}
|
||||
|
||||
public static void writeToFile(File file, byte[] content) throws IOException {
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
var fos = new FileOutputStream(file);
|
||||
fos.write(content);
|
||||
fos.close();
|
||||
}
|
||||
|
||||
public static void copyFileToDirectory(File dest, File targetDir) throws IOException {
|
||||
if (!targetDir.exists())
|
||||
targetDir.mkdirs();
|
||||
var path = dest.getAbsolutePath();
|
||||
var target = new File(targetDir, path.substring(path.lastIndexOf("/")));
|
||||
copyFile(dest, target);
|
||||
}
|
||||
|
||||
public static void copyFile(File dest, File target) throws IOException {
|
||||
var parent = target.getParentFile();
|
||||
if (!parent.exists())
|
||||
parent.getParentFile().mkdirs();
|
||||
writeToFile(target, readAllBytes(dest));
|
||||
}
|
||||
|
||||
public static void copyFile(InputStream is, File target) throws IOException {
|
||||
var parent = target.getParentFile();
|
||||
if (!parent.exists())
|
||||
parent.getParentFile().mkdirs();
|
||||
writeToFile(target, readAllBytes(is));
|
||||
}
|
||||
|
||||
public static void deleteRecursive(File f) {
|
||||
deleteRecursive(f, true);
|
||||
}
|
||||
@@ -98,8 +109,8 @@ public class IOUtils {
|
||||
public static void deleteRecursive(File f, boolean selfDeletion) {
|
||||
if (f.isDirectory()) {
|
||||
var fs = f.listFiles();
|
||||
if (fs != null)
|
||||
for (File child : fs)
|
||||
if (fs != null && fs.length > 0)
|
||||
for (var child : fs)
|
||||
deleteRecursive(child, true);
|
||||
}
|
||||
if (selfDeletion)
|
||||
@@ -107,7 +118,7 @@ public class IOUtils {
|
||||
}
|
||||
|
||||
public static long getDirSize(File dir) {
|
||||
var arr = dir.listFiles();
|
||||
final var arr = dir.listFiles();
|
||||
if (arr == null || arr.length == 0)
|
||||
return 0;
|
||||
|
||||
@@ -121,4 +132,4 @@ public class IOUtils {
|
||||
public static String getValidFileName(String fileName) {
|
||||
return fileName.replaceAll("[\\\\/:*?\"<>|]", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,83 +1,33 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
import static android.graphics.Bitmap.createBitmap;
|
||||
import static android.graphics.Bitmap.createScaledBitmap;
|
||||
import static androidx.core.content.ContextCompat.getDrawable;
|
||||
import static ru.vtosters.lite.utils.Preferences.preferences;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.*;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.StrictMode;
|
||||
import android.util.Log;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
import java.net.URL;
|
||||
|
||||
public class ImageUtils {
|
||||
|
||||
private static final OkHttpClient client = VtOkHttpClient.getInstance();
|
||||
// must be called asynchronously
|
||||
public static Drawable getDrawableFromUrl(String url, int placeholderRes, boolean rounded, boolean scaled) {
|
||||
|
||||
public static Bitmap bmp = null;
|
||||
if (NetworkUtils.isNetworkConnected() && !NetworkUtils.isNetworkIsSlow()) {
|
||||
try {
|
||||
var bmp = BitmapFactory.decodeStream(new URL(url).openStream());
|
||||
|
||||
public static Drawable getDrawableFromUrl(String url, int defDrawableRes, Boolean rounded, Boolean scaled) {
|
||||
if (!NetworkUtils.isNetworkConnected()) {
|
||||
if (defDrawableRes == 0) return null;
|
||||
return getDrawable(AndroidUtils.getGlobalContext(), defDrawableRes);
|
||||
}
|
||||
if (bmp != null) {
|
||||
if (rounded) bmp = getBitmapClippedCircle(bmp);
|
||||
if (scaled) bmp = Bitmap.createScaledBitmap(bmp, AndroidUtils.dp2px(256), AndroidUtils.dp2px(256), true);
|
||||
|
||||
if (NetworkUtils.isNetworkIsSlow()) {
|
||||
if (defDrawableRes == 0) return null;
|
||||
return getDrawable(AndroidUtils.getGlobalContext(), defDrawableRes);
|
||||
}
|
||||
|
||||
try {
|
||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||
StrictMode.setThreadPolicy(policy); // fix get pic
|
||||
|
||||
var request = new Request.a()
|
||||
.b(url)
|
||||
.a();
|
||||
client.a(request).a(new Callback() {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
Log.e("Error", e.getMessage());
|
||||
return new BitmapDrawable(AndroidUtils.getResources(), bmp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(Call call, Response response) {
|
||||
bmp = BitmapFactory.decodeStream(response.a().a());
|
||||
}
|
||||
});
|
||||
|
||||
if (bmp == null) {
|
||||
if (defDrawableRes == 0) return null;
|
||||
return getDrawable(AndroidUtils.getGlobalContext(), defDrawableRes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
bmp = rounded ? getBitmapClippedCircle(bmp) : bmp; // rounding
|
||||
|
||||
bmp = scaled ? createScaledBitmap(bmp, AndroidUtils.dp2px(256), AndroidUtils.dp2px(256), true) : bmp; // scaling
|
||||
|
||||
return new BitmapDrawable(AndroidUtils.getResources(), bmp); // return our drawable
|
||||
} catch (Exception e) {
|
||||
if (defDrawableRes == 0) return null; // default pic can be null
|
||||
|
||||
return getDrawable(AndroidUtils.getGlobalContext(), defDrawableRes); // get default drawable via res
|
||||
}
|
||||
return placeholderRes > 0 ? ContextCompat.getDrawable(AndroidUtils.getGlobalContext(), placeholderRes) : null;
|
||||
}
|
||||
|
||||
public static Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) {
|
||||
@@ -106,8 +56,8 @@ public class ImageUtils {
|
||||
public static Bitmap getBitmapClippedCircle(Bitmap bitmap) {
|
||||
final int width = bitmap.getWidth();
|
||||
final int height = bitmap.getHeight();
|
||||
final Bitmap outputBitmap = createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
int pref = preferences.getInt("pic_rounding", 0);
|
||||
final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
int pref = Preferences.preferences.getInt("pic_rounding", 0);
|
||||
final Canvas canvas = new Canvas(outputBitmap);
|
||||
|
||||
final Path path = new Path();
|
||||
@@ -128,7 +78,7 @@ public class ImageUtils {
|
||||
}
|
||||
|
||||
public static Drawable setTint(Context ctx, Drawable d) {
|
||||
d.setColorFilter(getAccentColor(), PorterDuff.Mode.SRC_ATOP);
|
||||
d.setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_ATOP);
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,10 +280,6 @@ public class Preferences {
|
||||
return getBoolValue("systememoji", false);
|
||||
}
|
||||
|
||||
public static boolean vksans() {
|
||||
return getBoolValue("vksans", false);
|
||||
}
|
||||
|
||||
public static boolean voice() {
|
||||
return getBoolValue("voice", true);
|
||||
}
|
||||
@@ -293,10 +289,6 @@ public class Preferences {
|
||||
return customvalue.isEmpty() ? orig : Integer.parseInt(customvalue);
|
||||
}
|
||||
|
||||
public static boolean color_grishka() {
|
||||
return getBoolValue("color_grishka", true);
|
||||
}
|
||||
|
||||
public static boolean vkme_notifs() {
|
||||
return getBoolValue("vkme_notifs", false);
|
||||
}
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.vk.profile.presenter.UserPresenter;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.api.ExtendedUserProfile;
|
||||
import com.vtosters.lite.fragments.messages.chat.vc.MsgSendVc;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserID;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserId;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.profile.presenter.UserPresenter;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.api.ExtendedUserProfile;
|
||||
import com.vtosters.lite.fragments.messages.chat.vc.MsgSendVc;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
|
||||
// Jesus cries
|
||||
public class ProfileHider {
|
||||
private static final OkHttpClient client = VtOkHttpClient.getInstance();
|
||||
|
||||
@@ -48,13 +44,9 @@ public class ProfileHider {
|
||||
.a()
|
||||
.g());
|
||||
String response = payload.optJSONObject(MsgSendVc.d0).optString("response");
|
||||
if (!response.isEmpty()) {
|
||||
Field z2 = ExtendedUserProfile.class.getDeclaredField("z2");
|
||||
z2.setAccessible(true);
|
||||
z2.set(extendedUserProfile, response);
|
||||
}
|
||||
} catch (IOException | JSONException | NoSuchFieldException |
|
||||
IllegalAccessException e) {
|
||||
if (!TextUtils.isEmpty(response))
|
||||
extendedUserProfile.z2 = response;
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NullPointerException e) {
|
||||
Log.e("ProfileHide", "null \"profiles\" node\n" + e);
|
||||
@@ -64,17 +56,8 @@ public class ProfileHider {
|
||||
|
||||
public static String getInfo(ExtendedUserProfile extendedUserProfile) {
|
||||
int userID = getUserID(extendedUserProfile);
|
||||
if (VTVerifications.isServiceAccount(userID)) {
|
||||
try {
|
||||
Field z2 = ExtendedUserProfile.class.getDeclaredField("z2");
|
||||
z2.setAccessible(true);
|
||||
String val = (String) z2.get(extendedUserProfile);
|
||||
if (val != null && !val.isEmpty())
|
||||
return val;
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (VTVerifications.isServiceAccount(userID) && !TextUtils.isEmpty(extendedUserProfile.z2))
|
||||
return extendedUserProfile.z2;
|
||||
return getGlobalContext().getString(UserPresenter.q0.a(userID));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class RenameTool {
|
||||
fn.setHint(R.string.vk_auth_sign_up_first_name);
|
||||
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());
|
||||
@@ -164,7 +164,7 @@ public class RenameTool {
|
||||
ln.setHint(R.string.vk_auth_sign_up_last_name);
|
||||
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);
|
||||
@@ -235,7 +235,7 @@ public class RenameTool {
|
||||
fn.setHint(R.string.vk_auth_sign_up_first_name);
|
||||
fn.setHintTextColor(getSTextAttr());
|
||||
fn.setTextColor(getTextAttr());
|
||||
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());
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
import com.vk.core.network.Network;
|
||||
|
||||
import static ru.vtosters.lite.hooks.DateHook.getLocale;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isAnyProxyEnabled;
|
||||
import static ru.vtosters.lite.utils.About.getBuildNumber;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.dev;
|
||||
import static ru.vtosters.lite.utils.Preferences.vksans;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.isDarkTheme;
|
||||
|
||||
public class SSFSUtils {
|
||||
@@ -17,8 +17,8 @@ public class SSFSUtils {
|
||||
"&secret=" + AccountManagerUtils.getUserSecret() +
|
||||
"&proxy=" + getUserProxy() +
|
||||
"&lang=" + getLocale() +
|
||||
"&vt=1&vksans=" + isVKSansEnabled() +
|
||||
"&vt_version=" + getBuildNumber() +
|
||||
"&vt=1" +
|
||||
"&useragent=" + Base64Utils.encodeValue(Base64Utils.encode(Network.l.c().a())) +
|
||||
"&vt_debug=" + isDEVModEnabled();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SSFSUtils {
|
||||
|
||||
if (!string.isEmpty()) return string;
|
||||
|
||||
return "https://vtsf.vknext.net";
|
||||
return "https://ssfs.vtosters.app";
|
||||
}
|
||||
|
||||
public static String getDarkVKUI() {
|
||||
@@ -35,17 +35,13 @@ public class SSFSUtils {
|
||||
}
|
||||
|
||||
public static String getAmoledVKUI() {
|
||||
return getPrefsValue("darktheme").equals("amoled") && isDarkTheme() ? "1" : "0";
|
||||
return ThemesUtils.isAmoledTheme() && isDarkTheme() ? "1" : "0";
|
||||
}
|
||||
|
||||
public static String getUserProxy() {
|
||||
return isAnyProxyEnabled() ? "1" : "0";
|
||||
}
|
||||
|
||||
public static String isVKSansEnabled() {
|
||||
return vksans() ? "1" : "0";
|
||||
}
|
||||
|
||||
public static String isDEVModEnabled() {
|
||||
return dev() ? "1" : "0";
|
||||
}
|
||||
|
||||
@@ -1,36 +1,23 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
import static android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
|
||||
import static ru.vtosters.lite.hooks.VKUIHook.isLoaded;
|
||||
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getWallpaper;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getCenterScreenCoords;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getResources;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.getCurrentActivity;
|
||||
import static ru.vtosters.lite.utils.Preferences.color_grishka;
|
||||
import static ru.vtosters.lite.utils.Preferences.dockbar_accent;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
import static ru.vtosters.lite.utils.Preferences.navbar;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
|
||||
import com.vk.articles.preload.WebCachePreloader;
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
import com.vk.core.preference.Preference;
|
||||
@@ -39,15 +26,17 @@ import com.vk.core.ui.themes.VKTheme;
|
||||
import com.vk.core.ui.themes.VKThemeHelper;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.data.ThemeTracker;
|
||||
import ru.vtosters.lite.deviceinfo.OEMDetector;
|
||||
import ru.vtosters.lite.hooks.VKUIHook;
|
||||
import ru.vtosters.lite.themes.ThemesHacks;
|
||||
import ru.vtosters.lite.ui.wallpapers.WallpapersHooks;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.*;
|
||||
import static ru.vtosters.lite.utils.Preferences.*;
|
||||
|
||||
public class ThemesUtils {
|
||||
public static List<String> accentColors = Arrays.asList(
|
||||
"5692d7", "528bcc", "7aa0cc", "518bcc", "6296d0", "2f68aa", "638ebf", "5181b8", "71aaeb", "4774a8", "5baaf4", "4186c8", "add3ff", "4774a8", "718198", "5a9eff", "99a2ad", "74a2d6", "e9eef3", "dfe3e7", "eff1f3", "5c9ce6", "4986cc", "4680c2"
|
||||
);
|
||||
|
||||
public static void applyTheme(VKTheme theme) {
|
||||
var currentActivity = LifecycleUtils.getCurrentActivity();
|
||||
if (currentActivity != null) {
|
||||
@@ -61,6 +50,10 @@ public class ThemesUtils {
|
||||
}
|
||||
} // Apply VKTheme and ImTheme (hard applying without dynamic theme changing)
|
||||
|
||||
public static ColorStateList getAccenedColorStateList() {
|
||||
return ColorStateList.valueOf(getAccentColor());
|
||||
}
|
||||
|
||||
public static int getSystemModeTheme() {
|
||||
return AppCompatDelegate.getDefaultNightMode();
|
||||
}
|
||||
@@ -71,26 +64,26 @@ public class ThemesUtils {
|
||||
|
||||
public static void setTheme(VKTheme theme, Activity activity) {
|
||||
if (activity == null) {
|
||||
activity = getCurrentActivity();
|
||||
activity = LifecycleUtils.getCurrentActivity();
|
||||
|
||||
if (activity == null) return;
|
||||
}
|
||||
VKThemeHelper.theme(theme, activity, getCenterScreenCoords());
|
||||
ThemeTracker.a();
|
||||
isLoaded = false;
|
||||
VKUIHook.isLoaded = false;
|
||||
new WebView(activity).clearCache(true);
|
||||
WebCachePreloader.e();
|
||||
} // apply changed theme
|
||||
|
||||
public static void setThemeFL(VKTheme theme, Activity activity, float[] fl) {
|
||||
if (activity == null) {
|
||||
activity = getCurrentActivity();
|
||||
activity = LifecycleUtils.getCurrentActivity();
|
||||
|
||||
if (activity == null) return;
|
||||
}
|
||||
VKThemeHelper.theme(theme, activity, fl);
|
||||
ThemeTracker.a();
|
||||
isLoaded = false;
|
||||
VKUIHook.isLoaded = false;
|
||||
new WebView(activity).clearCache(true);
|
||||
WebCachePreloader.e();
|
||||
}
|
||||
@@ -98,11 +91,118 @@ public class ThemesUtils {
|
||||
public static boolean isDarkTheme() {
|
||||
return VKThemeHelper.r();
|
||||
}
|
||||
|
||||
public static boolean isMonetTheme() {
|
||||
return getBoolValue("monettheme", false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S;
|
||||
}
|
||||
|
||||
public static boolean isAmoledTheme() {
|
||||
return getBoolValue("amoledtheme", false);
|
||||
}
|
||||
|
||||
public static int getAccentColor() {
|
||||
return getColorFromAttr(R.attr.accent);
|
||||
var accent = AndroidUtils.getPreferences().getInt("accent_color", getColorFromAttr(R.attr.accent));
|
||||
return (accent == 0 || isMonetTheme() || !isMilkshake()) ? getColorFromAttr(R.attr.accent) : accent;
|
||||
} // Color accent
|
||||
|
||||
public static int getMutedAccentColor() {
|
||||
return getMutedColor(getAccentColor());
|
||||
}
|
||||
|
||||
@SuppressLint("DiscouragedPrivateApi")
|
||||
public static void setCursorColor(EditText view) {
|
||||
try {
|
||||
view.setHighlightColor(ThemesUtils.getMutedAccentColor());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
view.getTextCursorDrawable().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
} else if (!OEMDetector.isMIUI()) {
|
||||
Field field = TextView.class.getDeclaredField("mCursorDrawableRes");
|
||||
field.setAccessible(true);
|
||||
int drawableResId = field.getInt(view);
|
||||
|
||||
field = TextView.class.getDeclaredField("mEditor");
|
||||
field.setAccessible(true);
|
||||
Object editor = field.get(view);
|
||||
|
||||
if (editor != null) {
|
||||
Drawable drawable = ContextCompat.getDrawable(view.getContext(), drawableResId);
|
||||
drawable.setColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
Drawable[] drawables = {drawable, drawable};
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
field = editor.getClass().getDeclaredField("mCursorDrawable");
|
||||
} else {
|
||||
field = editor.getClass().getDeclaredField("mDrawableForCursor");
|
||||
}
|
||||
field.setAccessible(true);
|
||||
field.set(editor, drawables);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
@SuppressLint("DiscouragedPrivateApi")
|
||||
public static void colorHandles(TextView view) {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
view.getTextSelectHandle().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
view.getTextSelectHandleRight().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
view.getTextSelectHandleLeft().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
} else if (!OEMDetector.isMIUI()) {
|
||||
Field editorField = TextView.class.getDeclaredField("mEditor");
|
||||
|
||||
if (!editorField.isAccessible()) editorField.setAccessible(true);
|
||||
|
||||
Object editor = editorField.get(view);
|
||||
|
||||
if (editor != null) {
|
||||
Class<?> editorClass;
|
||||
|
||||
editorClass = editor.getClass();
|
||||
|
||||
String[] handleNames = {"mSelectHandleLeft", "mSelectHandleRight", "mSelectHandleCenter"};
|
||||
String[] resNames = {"mTextSelectHandleLeftRes", "mTextSelectHandleRightRes", "mTextSelectHandleRes"};
|
||||
|
||||
for (int i = 0; i < handleNames.length; i++) {
|
||||
Field handleField = editorClass.getDeclaredField(handleNames[i]);
|
||||
if (!handleField.isAccessible()) {
|
||||
handleField.setAccessible(true);
|
||||
}
|
||||
|
||||
Drawable handleDrawable = (Drawable) handleField.get(editor);
|
||||
|
||||
if (handleDrawable == null) {
|
||||
Field resField = TextView.class.getDeclaredField(resNames[i]);
|
||||
if (!resField.isAccessible()) {
|
||||
resField.setAccessible(true);
|
||||
}
|
||||
int resId = resField.getInt(view);
|
||||
handleDrawable = view.getResources().getDrawable(resId);
|
||||
}
|
||||
|
||||
if (handleDrawable != null) {
|
||||
Drawable drawable = handleDrawable.mutate();
|
||||
drawable.setColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
handleField.set(editor, drawable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getMutedColor(int color) {
|
||||
return ColorUtils.blendARGB(color, (isDarkTheme() ? Color.BLACK : Color.WHITE), (isMilkshake() ? 0.5f : 0.3f));
|
||||
}
|
||||
|
||||
public static void setCustomAccentColor(int newColor, boolean async) {
|
||||
var editor = AndroidUtils.edit().putInt("accent_color", newColor);
|
||||
if (async) editor.apply();
|
||||
else editor.commit();
|
||||
}
|
||||
|
||||
public static int getTextAttr() {
|
||||
return getColorFromAttr(R.attr.text_primary);
|
||||
} // Text Primary color
|
||||
@@ -131,45 +231,36 @@ public class ThemesUtils {
|
||||
return getColorFromAttr(R.attr.header_text);
|
||||
} // Header/Toolbar color text
|
||||
|
||||
public static int getAmoledTheme() {
|
||||
return getIdentifier("BaseAmoledStyle", "style");
|
||||
} // Get Amoled theme id
|
||||
|
||||
public static int picFix() {
|
||||
return getIdentifier("ActionBarThemeFix", "style");
|
||||
} // Fix tabbar color in photo viewer
|
||||
|
||||
public static int getAmoledImTheme() {
|
||||
return getIdentifier("VkIm.Theme.VkApp.Amoled", "style");
|
||||
} // Get Amoled theme id for messages
|
||||
|
||||
public static int getAmoledMeTheme() {
|
||||
return getIdentifier("VkIm.Theme.VkMe.Amoled", "style");
|
||||
} // Get Amoled theme id for messages with rounded msg
|
||||
|
||||
public static int getAttrId(String attr) {
|
||||
return getIdentifier(attr, "attr");
|
||||
}
|
||||
|
||||
public static void setBarTheme(View getview) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
getview.setSystemUiVisibility(getNeededColorNavbar() | getNeededColorStatusbar());
|
||||
}
|
||||
} // Set white/dark statusbar/navbar icons
|
||||
|
||||
public static int getNeededColorStatusbar() {
|
||||
return !isDarkTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? 8192 : 0;
|
||||
}
|
||||
|
||||
public static int getNeededColorNavbar() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? isDarkTheme() ? SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR : 0 : 0;
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? isDarkTheme() ? View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR : 0 : 0;
|
||||
}
|
||||
|
||||
public static int getDarkThemeRes() {
|
||||
if (getPrefsValue("darktheme").equals("amoled")) {
|
||||
return isMilkshake() ? R.style.VkMilkAmoledStyle : R.style.VkAmoledStyle;
|
||||
if (isMonetTheme()) {
|
||||
if (isAmoledTheme()) {
|
||||
return getIdentifier(isMilkshake() ? "VkMilkAmoledMonetStyle" : "VkAmoledMonetStyle", "style");
|
||||
} else {
|
||||
return getIdentifier(isMilkshake() ? "VkMilkDarkMonetStyle" : "VkDarkMonetStyle", "style");
|
||||
}
|
||||
} else {
|
||||
if (isAmoledTheme()) {
|
||||
return isMilkshake() ? R.style.VkMilkAmoledStyle : R.style.VkAmoledStyle;
|
||||
} else {
|
||||
return isMilkshake() ? R.style.VkMilkDarkStyle : R.style.VkDarkStyle;
|
||||
}
|
||||
}
|
||||
} // Return needed res theme
|
||||
|
||||
public static int getLightThemeRes() {
|
||||
if (isMonetTheme()) {
|
||||
return getIdentifier(isMilkshake() ? "VkMilkLightMonetStyle" : "VkLightMonetStyle", "style");
|
||||
} else {
|
||||
return isMilkshake() ? R.style.VkMilkLightStyle : R.style.VkLightStyle;
|
||||
}
|
||||
return isMilkshake() ? R.style.VkMilkDarkStyle : R.style.VkDarkStyle;
|
||||
} // Return needed res theme
|
||||
|
||||
public static VKTheme getDarkTheme() {
|
||||
@@ -184,12 +275,7 @@ public class ThemesUtils {
|
||||
return VKThemeHelper.d(attr);
|
||||
} // Get needed attr color
|
||||
|
||||
public static boolean isAndroidMonet() {
|
||||
return color_grishka() && Build.VERSION.SDK_INT >= 31;
|
||||
}
|
||||
|
||||
public static void colorWriteBar(View view) {
|
||||
if (!navbar()) return;
|
||||
view.setBackgroundColor(getTabbarBackground());
|
||||
}
|
||||
|
||||
@@ -197,16 +283,8 @@ public class ThemesUtils {
|
||||
return MilkshakeHelper.e();
|
||||
}
|
||||
|
||||
public static boolean isColorRefAccented(int color) {
|
||||
for (int accent : new int[]{R.color.accent_blue, R.color.azure_A400, R.color.blue, R.color.blue_200, R.color.blue_200_muted, R.color.blue_300, R.color.blue_400, R.color.cool_blue, R.color.cornflower_blue, R.color.cornflower_blue_two, R.color.dot_unread, R.color.fave_promo_btn_pressed, R.color.header_blue, R.color.vkim_ripple_dark, R.color.colorAccent, R.color.light_blue, R.color.light_blue_gray, R.color.live_emoji_butt_hide, R.color.music_action_button_blue, R.color.name, R.color.picker_blue, R.color.picker_blue_pressed, R.color.picker_tab_bg_selected, R.color.picker_tab_text_selected, R.color.sharing_blue_btn_normal, R.color.sharing_blue_btn_pressed, R.color.sky_300, R.color.text_blue, R.color.tip_background, R.color.tw__blue_default, R.color.tw__blue_pressed, R.color.vkim_msg_sending_ic, R.color.vkim_playing_drawable_rect, R.color.white_blue32}) {
|
||||
if (color == accent) return true;
|
||||
}
|
||||
return false;
|
||||
} // Accent colors
|
||||
|
||||
public static void themeMonetToolbar(ImageButton imageButton, Toolbar toolbar) {
|
||||
imageButton.setImageTintList(ColorStateList.valueOf(getHeaderText()));
|
||||
toolbar.setElevation(0.0f);
|
||||
public static void setImageViewColored(ImageView view){
|
||||
view.setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
|
||||
public static Drawable recolorDrawable(Drawable drawable) {
|
||||
@@ -214,76 +292,18 @@ public class ThemesUtils {
|
||||
return new RecoloredDrawable(drawable, getAccentColor());
|
||||
} // Recolor drawable to accent color
|
||||
|
||||
public static Drawable recolorVKIconMenu(Drawable drawable) {
|
||||
int accent = getHeaderText();
|
||||
|
||||
public static Drawable recolorToolbarDrawable(Drawable drawable) {
|
||||
if (drawable == null) return null;
|
||||
return new RecoloredDrawable(drawable, (ThemesUtils.isMilkshake() && !ThemesUtils.isDarkTheme()) ? ThemesUtils.getAccentColor() : ThemesUtils.getHeaderText());
|
||||
}
|
||||
|
||||
if (isAndroidMonet() || isDarkTheme()) accent = getAccentColor();
|
||||
public static void recolorTextView(TextView tw) {
|
||||
tw.getBackground().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_OVER);
|
||||
}
|
||||
|
||||
return new RecoloredDrawable(drawable, accent);
|
||||
} // Recolor vk icon to accent color
|
||||
|
||||
|
||||
public static Drawable recolorDrawableToolbar(Drawable drawable) {
|
||||
if (drawable == null) return null;
|
||||
|
||||
if (!isAndroidMonet()) return drawable;
|
||||
|
||||
return new RecoloredDrawable(drawable, getHeaderText());
|
||||
} // Recolor toolbar drawable to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public static Drawable recolorDrawableInt(int drawable) {
|
||||
if (!isAndroidMonet()) return getResources().getDrawable(drawable);
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables") Drawable res = getResources().getDrawable(drawable);
|
||||
return new RecoloredDrawable(res, getAccentColor());
|
||||
} // Get res drawable via id and coloring to accent
|
||||
|
||||
public static ColorStateList recolorCSL(ColorStateList colorStateList) {
|
||||
if (colorStateList == null) return null;
|
||||
|
||||
if (!isAndroidMonet()) return colorStateList;
|
||||
|
||||
return ColorStateList.valueOf(getAccentColor());
|
||||
} // Recolor ColorStateList to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForColorStateLists")
|
||||
public static ColorStateList themeCSL(Context context, int color) {
|
||||
if (isColorRefAccented(color) && isAndroidMonet()) {
|
||||
return ColorStateList.valueOf(getAccentColor());
|
||||
}
|
||||
|
||||
ColorStateList csl;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
csl = context.getColorStateList(color);
|
||||
} else {
|
||||
csl = context.getResources().getColorStateList(color);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
boolean isUnselAccent = isAccentedColor(unsel);
|
||||
boolean isSelAccent = isAccentedColor(sel);
|
||||
|
||||
if (isUnselAccent || isSelAccent) {
|
||||
|
||||
return new ColorStateList(new int[][]{
|
||||
new int[]{android.R.attr.state_selected}, new int[]{-android.R.attr.state_selected}
|
||||
}, new int[]{isSelAccent ? getAccentColor() : sel, isUnselAccent ? getAccentColor() : unsel});
|
||||
}
|
||||
|
||||
return csl;
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} // Recolor ColorStateList
|
||||
public static void recolorBGView(View view) {
|
||||
view.getBackground().setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_OVER);
|
||||
}
|
||||
|
||||
public static int darken(int color, float by) {
|
||||
float[] hsl = new float[3];
|
||||
@@ -293,6 +313,14 @@ public class ThemesUtils {
|
||||
return ColorUtils.HSLToColor(hsl);
|
||||
}
|
||||
|
||||
public static int fixSeparator(float f) {
|
||||
if (isMonetTheme()) {
|
||||
return 0;
|
||||
} else {
|
||||
return (int) Math.floor(f * Resources.getSystem().getDisplayMetrics().density);
|
||||
}
|
||||
}
|
||||
|
||||
public static int lighten(int color, float factor) {
|
||||
int red = (int) ((Color.red(color) * (1 - factor) / 255 + factor) * 255);
|
||||
int green = (int) ((Color.green(color) * (1 - factor) / 255 + factor) * 255);
|
||||
@@ -300,41 +328,12 @@ public class ThemesUtils {
|
||||
return Color.argb(Color.alpha(color), red, green, blue);
|
||||
}
|
||||
|
||||
public static int fixTextColor(int resid) {
|
||||
if (resid == R.color.music_action_button_gray || resid == R.color.cool_grey || resid == R.color.accent_blue) {
|
||||
return isDarkTheme() ? R.color.white : R.color.cool_grey;
|
||||
}
|
||||
return resid;
|
||||
}
|
||||
|
||||
public static int halfAlpha(int src) {
|
||||
return ColorUtils.setAlphaComponent(src, 169);
|
||||
}
|
||||
|
||||
public static boolean isAccentedColor(ColorStateList target) {
|
||||
return target != null && isAccentedColor(target.getDefaultColor());
|
||||
}
|
||||
|
||||
public static boolean isAccentedColor(int target) {
|
||||
return accentColors.contains(hex(target).toLowerCase());
|
||||
}
|
||||
|
||||
public static int getColor(Context context, int i) {
|
||||
if (isColorRefAccented(i) && isAndroidMonet()) {
|
||||
return getAccentColor();
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
return context.getColor(i);
|
||||
} else {
|
||||
return context.getResources().getColor(i);
|
||||
}
|
||||
} // Android Support color injector + accent color checker
|
||||
|
||||
public static int getColor2(int i) {
|
||||
if (isColorRefAccented(i) && isAndroidMonet()) {
|
||||
return getAccentColor();
|
||||
}
|
||||
return getResources().getColor(i);
|
||||
public static int getColor(int i) {
|
||||
return ThemesHacks.getHackedColor(getGlobalContext(), i);
|
||||
} // Android Support color injector + accent color checker
|
||||
|
||||
public static int getAlertStyle() {
|
||||
@@ -342,10 +341,7 @@ public class ThemesUtils {
|
||||
}
|
||||
|
||||
public static String getBackgroundStickers() {
|
||||
if (getWallpaper() != null) {
|
||||
return "images_with_background";
|
||||
}
|
||||
return "images";
|
||||
return WallpapersHooks.hasWallpapers() ? "images_with_background" : "images";
|
||||
}
|
||||
|
||||
public static VKTheme getCurrentTheme() {
|
||||
@@ -380,10 +376,25 @@ public class ThemesUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setStatusBarColor(Window window) {
|
||||
if (isDarkTheme()) {
|
||||
View view = window.getDecorView();
|
||||
view.setSystemUiVisibility(view.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
} else {
|
||||
View view = window.getDecorView();
|
||||
view.setSystemUiVisibility(view.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
}
|
||||
}
|
||||
|
||||
public static String hex(int i) {
|
||||
return String.format("#%06X", i & 16777215);
|
||||
} // Get color as hex string
|
||||
|
||||
// hex, but without # at the beginning
|
||||
public static String hexx(int i) {
|
||||
return String.format("%06X", i & 16777215);
|
||||
}
|
||||
|
||||
public static int getNavigationHeight(int Default) {
|
||||
int VKME = R.dimen.design_bottom_sheet_peek_height_min;
|
||||
|
||||
|
||||
+2
-129
@@ -11,64 +11,6 @@ setlocal
|
||||
call :setESC
|
||||
|
||||
cls
|
||||
echo.
|
||||
echo %ESC%[1;4mBuild dex...%ESC%[0m
|
||||
echo.
|
||||
call gradlew clean
|
||||
del app\src\main\assets\version.properties
|
||||
del smali\assets\version.properties
|
||||
call gradlew versionFile
|
||||
call gradlew assembleRelease
|
||||
if "%ERRORLEVEL%" == "0" (
|
||||
echo %ESC%[92mSuccessful%ESC%[0m
|
||||
) else (
|
||||
echo %ESC%[31mFailed%ESC%[0m
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo %ESC%[1;4mExport dex...%ESC%[0m
|
||||
echo.
|
||||
call gradlew exportDex
|
||||
if "%ERRORLEVEL%" == "0" (
|
||||
echo %ESC%[92mSuccessful%ESC%[0m
|
||||
) else (
|
||||
echo %ESC%[31mFailed%ESC%[0m
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo %ESC%[1;4mMove dex6 to source dir...%ESC%[0m
|
||||
echo.
|
||||
move app\classes6.dex smali\
|
||||
if "%ERRORLEVEL%" == "0" (
|
||||
echo %ESC%[92mSuccessful%ESC%[0m
|
||||
) else (
|
||||
echo %ESC%[31mFailed%ESC%[0m
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo %ESC%[1;4mMove dex7 to source dir...%ESC%[0m
|
||||
echo.
|
||||
move app\classes7.dex smali\
|
||||
if "%ERRORLEVEL%" == "0" (
|
||||
echo %ESC%[92mSuccessful%ESC%[0m
|
||||
) else (
|
||||
echo %ESC%[31mFailed%ESC%[0m
|
||||
)
|
||||
|
||||
|
||||
echo.
|
||||
echo %ESC%[1;4mMove version.properties to source dir...%ESC%[0m
|
||||
echo.
|
||||
move app\version.properties smali\assets\
|
||||
if "%ERRORLEVEL%" == "0" (
|
||||
echo %ESC%[92mSuccessful%ESC%[0m
|
||||
) else (
|
||||
echo %ESC%[31mFailed%ESC%[0m
|
||||
)
|
||||
|
||||
echo.
|
||||
echo %ESC%[1;4mBuild apk...%ESC%[0m
|
||||
echo.
|
||||
@@ -81,7 +23,7 @@ if "%ERRORLEVEL%" == "0" (
|
||||
exit /B 1
|
||||
)
|
||||
del classes6.dex
|
||||
del classes8.dex
|
||||
del classes7.dex
|
||||
del assets\version.properties
|
||||
|
||||
echo.
|
||||
@@ -95,78 +37,9 @@ if "%ERRORLEVEL%" == "0" (
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
|
||||
:startinstall
|
||||
SET choice=
|
||||
SET /p choice=Do you want to install APK?:
|
||||
|
||||
IF /i '%choice%'=='Y' GOTO yesinst
|
||||
IF /i '%choice%'=='yes' GOTO yesinst
|
||||
IF /i '%choice%'=='Yes' GOTO yesinst
|
||||
IF /i '%choice%'=='y' GOTO yesinst
|
||||
|
||||
IF /i '%choice%'=='N' GOTO noinst
|
||||
IF /i '%choice%'=='No' GOTO noinst
|
||||
IF /i '%choice%'=='n' GOTO noinst
|
||||
IF /i '%choice%'=='no' GOTO noinst
|
||||
|
||||
ECHO "%choice%" doesn't exist
|
||||
|
||||
ECHO.
|
||||
GOTO startinstall
|
||||
|
||||
:yesinst
|
||||
echo.
|
||||
echo %ESC%[1;4mInstall apk...%ESC%[0m
|
||||
echo.
|
||||
call adb install ../scripts/VTLite.apk
|
||||
if "%ERRORLEVEL%" == "0" (
|
||||
echo %ESC%[92mSuccessful%ESC%[0m
|
||||
) else (
|
||||
echo %ESC%[31mFailed%ESC%[0m
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
:noinst
|
||||
|
||||
|
||||
:startapp
|
||||
SET choice=
|
||||
SET /p choice=Do you want to start app?:
|
||||
|
||||
IF /i '%choice%'=='Y' GOTO start
|
||||
IF /i '%choice%'=='yes' GOTO start
|
||||
IF /i '%choice%'=='Yes' GOTO start
|
||||
IF /i '%choice%'=='y' GOTO start
|
||||
|
||||
IF /i '%choice%'=='N' GOTO skip
|
||||
IF /i '%choice%'=='No' GOTO skip
|
||||
IF /i '%choice%'=='n' GOTO skip
|
||||
IF /i '%choice%'=='no' GOTO skip
|
||||
|
||||
ECHO "%choice%" doesn't exist
|
||||
|
||||
ECHO.
|
||||
GOTO startapp
|
||||
|
||||
:start
|
||||
echo.
|
||||
echo %ESC%[1;4mOpen VTL...%ESC%[0m
|
||||
echo.
|
||||
call adb shell monkey -p com.vtosters.lite -c android.intent.category.LAUNCHER 1
|
||||
if "%ERRORLEVEL%" == "0" (
|
||||
echo %ESC%[92mSuccessful%ESC%[0m
|
||||
) else (
|
||||
echo %ESC%[31mFailed%ESC%[0m
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
:skip
|
||||
|
||||
:setESC
|
||||
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
|
||||
set ESC=%%b
|
||||
exit /B 0
|
||||
)
|
||||
exit /B 0
|
||||
|
||||
exit
|
||||
|
||||
+21
-70
@@ -5,85 +5,36 @@ NC='\033[0m'
|
||||
BOLD='\033[1m'
|
||||
UNDERLINE='\033[4m'
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Сборка dex..${NC}\n"
|
||||
cd ../
|
||||
rm ../smali/assets/version.properties
|
||||
rm ../lite/app/src/main/assets/version.properties
|
||||
./gradlew versionFile
|
||||
./gradlew assembleRelease
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Экспорт dex..${NC}"
|
||||
./gradlew exportDex
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Перенос dex6 в папку с исходным кодом..${NC}"
|
||||
mv app/classes6.dex smali/
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Перенос dex7 в папку с исходным кодом..${NC}"
|
||||
mv app/classes7.dex smali/
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Перенос version.properties в папку с исходным кодом..${NC}"
|
||||
mv app/version.properties smali/assets/
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
fi
|
||||
check_result() {
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Сборка apk..${NC}"
|
||||
cd smali/
|
||||
java -jar ../scripts/apktool.jar b . -o VTLite.apk --use-aapt2 -p ../scripts/framework/
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
java -jar ../scripts/apktool.jar b . -o ../scripts/VTLite.apk --use-aapt2 -p ../scripts/framework/
|
||||
check_result
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Zipaligning..${NC}"
|
||||
if command -v zipalign &> /dev/null; then
|
||||
zipalign -p -f 4 ../scripts/VTLite.apk ../scripts/VTLite.apk_aligned
|
||||
check_result
|
||||
mv ../scripts/VTLite.apk_aligned ../scripts/VTLite.apk
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
exit 1
|
||||
echo -e "${RED}Zipalign не найден, выравнивание пропущено${NC}"
|
||||
fi
|
||||
|
||||
echo -e "\nПодписывание апк..."
|
||||
echo -e "${BOLD}${UNDERLINE}Подписывание апк...${NC}"
|
||||
cd ../scripts
|
||||
./apksigner sign --ks debug.keystore --ks-key-alias androiddebugkey --ks-pass pass:android ../smali/VTLite.apk
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}"
|
||||
fi
|
||||
./apksigner sign --ks debug.keystore --ks-key-alias androiddebugkey --ks-pass pass:android ../scripts/VTLite.apk
|
||||
check_result
|
||||
|
||||
echo -e "${BOLD}VTosters Lite успешно собран! APK находится в папке smali${NC}"
|
||||
echo -e "${BOLD}VTosters Lite успешно собран! APK находится в папке scripts${NC}"
|
||||
|
||||
cd ../smali
|
||||
rm classes6.dex
|
||||
rm classes7.dex
|
||||
|
||||
echo -n "Желаете установить VTosters через adb? (y/n) "
|
||||
read -n 1 prompt
|
||||
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
|
||||
then
|
||||
echo -e "\n"
|
||||
adb install VTLite.apk
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#!/bin/bash
|
||||
echo -e "${BOLD}${UNDERLINE}Сборка dex..${NC}\n"
|
||||
|
||||
gradle versionFile
|
||||
gradle assembleRelease
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Экспорт dex..${NC}"
|
||||
gradle exportDex
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Перенос dex6 в папку с исходным кодом..${NC}"
|
||||
mv app/classes6.dex smali/
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Перенос dex7 в папку с исходным кодом..${NC}"
|
||||
mv app/classes7.dex smali/
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Перенос version.properties в папку с исходным кодом..${NC}"
|
||||
mv app/version.properties smali/assets/
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
fi
|
||||
|
||||
echo -e "${BOLD}${UNDERLINE}Сборка apk..${NC}"
|
||||
java -jar scripts/apktool.jar b smali -o smali/VTLite.apk --use-aapt2 -p scripts/framework/
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Успех!${NC}\n"
|
||||
else
|
||||
echo -e "${RED}Провал.${NC}\n"
|
||||
exit 1
|
||||
fi
|
||||
@@ -94,4 +94,6 @@ cкорее подписывайся
|
||||
Подписывайтесь👇
|
||||
Подписывайся👇
|
||||
ссылка в комментариях
|
||||
в комментариях👇
|
||||
в комментариях👇
|
||||
👉https://
|
||||
👉http://
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="@color/darker_blue" android:state_pressed="true" />
|
||||
<item android:color="@color/blue" android:state_pressed="false" android:state_selected="true" />
|
||||
<item android:color="?accent" android:state_pressed="true" />
|
||||
<item android:color="?accent" android:state_pressed="false" android:state_selected="true" />
|
||||
<item android:color="@color/date_picker_text_normal" android:state_pressed="false" android:state_selected="false" />
|
||||
</selector>
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="#ff5181b8" android:state_selected="true" />
|
||||
<item android:color="@color/header_blue" android:state_selected="true" />
|
||||
<item android:color="#ffabafb3" />
|
||||
</selector>
|
||||
@@ -22,7 +22,7 @@
|
||||
<path
|
||||
android:name="_R_G_L_1_G_D_0_P_0"
|
||||
android:fillAlpha="1.0"
|
||||
android:fillColor="#ff3f8ae0"
|
||||
android:fillColor="@color/azure_300"
|
||||
android:fillType="nonZero"
|
||||
android:pathData=" M2.53 6.5 C2.67,5.96 3.22,5.64 3.75,5.78 C4.29,5.92 4.61,6.47 4.47,7 C3.84,9.42 2.29,10.75 0,10.75 C-2.29,10.75 -3.84,9.42 -4.47,7 C-4.61,6.47 -4.29,5.92 -3.75,5.78 C-3.22,5.64 -2.67,5.96 -2.53,6.5 C-2.12,8.08 -1.34,8.75 0,8.75 C1.34,8.75 2.12,8.08 2.53,6.5c " />
|
||||
</group>
|
||||
@@ -36,7 +36,7 @@
|
||||
<path
|
||||
android:name="_R_G_L_0_G_D_0_P_0"
|
||||
android:fillAlpha="1.0"
|
||||
android:fillColor="#ff3f8ae0"
|
||||
android:fillColor="@color/azure_300"
|
||||
android:fillType="nonZero"
|
||||
android:pathData=" M8.73 0.95 C8.8,1.03 8.86,1.11 9,1.27 C10.07,2.51 10.5,3.22 10.5,4.34 C10.5,4.84 10.44,5.23 10.21,5.7 C9.7,6.69 8.62,7.25 7,7.25 C7,7.25 -7,7.25 -7,7.25 C-8.67,7.25 -9.76,6.68 -10.24,5.65 C-10.45,5.2 -10.5,4.84 -10.5,4.34 C-10.5,3.22 -10.08,2.51 -9.01,1.27 C-8.87,1.11 -8.8,1.04 -8.74,0.96 C-8.2,0.32 -8,-0.03 -8,-0.34 C-8,-0.34 -8,-2.17 -8,-2.17 C-8,-6.95 -4.53,-10.75 0,-10.75 C4.54,-10.75 8,-6.96 8,-2.17 C8,-2.17 8,-0.34 8,-0.34 C8,-0.34 8.19,0.32 8.73,0.95c M6 -0.34 C6,-0.34 6,-2.17 6,-2.17 C6,-5.89 3.39,-8.75 0,-8.75 C-3.38,-8.75 -6,-5.89 -6,-2.17 C-6,-2.17 -6,-0.34 -6,-0.34 C-6,0.58 -6.38,1.27 -7.21,2.25 C-7.28,2.34 -7.35,2.42 -7.49,2.58 C-8.25,3.46 -8.5,3.87 -8.5,4.34 C-8.5,4.56 -8.48,4.68 -8.43,4.8 C-8.31,5.06 -7.94,5.25 -7,5.25 C-7,5.25 7,5.25 7,5.25 C7.91,5.25 8.29,5.06 8.42,4.79 C8.48,4.67 8.5,4.55 8.5,4.34 C8.5,3.88 8.25,3.46 7.49,2.58 C7.35,2.42 7.28,2.34 7.21,2.25 C6.38,1.27 6,0.59 6,-0.34c " />
|
||||
</group>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="6.0dip" />
|
||||
<solid android:color="#44528bcc" />
|
||||
<solid android:color="@color/accent_blue" />
|
||||
<stroke android:width="1.0dip" android:color="@color/accent_blue" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
android:shape="rectangle">
|
||||
<gradient
|
||||
android:angle="90.0"
|
||||
android:endColor="#ff5c9ce6"
|
||||
android:endColor="@color/blue_200"
|
||||
android:startColor="#ff397ecc" />
|
||||
</shape>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/accent_blue" />
|
||||
<solid android:color="?accent" />
|
||||
<corners android:radius="11.0dip" />
|
||||
<stroke
|
||||
android:width="2.0dip"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<ripple android:color="#32001833">
|
||||
<item>
|
||||
<shape>
|
||||
<solid android:color="#ff5181b8" />
|
||||
<solid android:color="@color/header_blue" />
|
||||
<corners android:radius="4.0dip" />
|
||||
</shape>
|
||||
</item>
|
||||
@@ -12,7 +12,7 @@
|
||||
</item>
|
||||
<item>
|
||||
<shape>
|
||||
<solid android:color="#665181b8" />
|
||||
<solid android:color="@color/header_blue" />
|
||||
<corners android:radius="4.0dip" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 397 B |
@@ -5,7 +5,7 @@
|
||||
android:viewportWidth="56.0"
|
||||
android:viewportHeight="56.0">
|
||||
<path
|
||||
android:fillColor="#ff528bcc"
|
||||
android:fillColor="@color/accent_blue"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M33.91,34.26L32.4,35.77a2.96,2.96 0,0 1,-3.12 0.69c-1.75,-0.64 -3.78,-2.16 -6.18,-4.55 -2.39,-2.39 -3.91,-4.43 -4.55,-6.18a2.96,2.96 0,0 1,0.69 -3.12l1.51,-1.51c2.24,-2.24 2.44,-5.74 0.5,-8.05l-1.77,-2.11c-1.48,-1.76 -4.17,-1.94 -6.01,-0.37a5.32,5.32 0,0 0,-1.56 2.31,5.41 5.41,0 0,0 -0.26,1.26c-0.83,6.19 2.21,12.83 9.3,19.92 7.09,7.09 13.72,10.14 19.97,9.3a5.32,5.32 0,0 0,3.51 -1.81c1.57,-1.85 1.39,-4.54 -0.37,-6.02l-2.1,-1.77c-2.31,-1.94 -5.81,-1.74 -8.05,0.5zM31.79,32.14c3.33,-3.33 8.59,-3.63 12.11,-0.68l2.11,1.77c3.05,2.57 3.36,7.16 0.71,10.27 -1.4,1.62 -3.37,2.64 -5.45,2.84 -7.26,0.98 -14.75,-2.46 -22.44,-10.15C11.13,28.49 7.69,21 8.66,13.81c0.06,-0.64 0.19,-1.28 0.4,-1.9a8.33,8.33 0,0 1,2.45 -3.63c3.1,-2.64 7.7,-2.33 10.26,0.72l1.77,2.11c2.96,3.51 2.66,8.78 -0.67,12.11l-1.49,1.49c0.46,1.25 1.75,2.97 3.85,5.07 2.1,2.1 3.82,3.38 5.07,3.85l1.49,-1.49z" />
|
||||
</vector>
|
||||
@@ -2,7 +2,7 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape>
|
||||
<solid android:color="#ff5c9ce6" />
|
||||
<solid android:color="?accent" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:gravity="center|clip_horizontal|clip_vertical">
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user