Compare commits
186
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d4be416d8 | ||
|
|
11d12fc397 | ||
|
|
caf70b72b5 | ||
|
|
f6d860c439 | ||
|
|
7d99f06053 | ||
|
|
b4e260d7cb | ||
|
|
46281102cb | ||
|
|
b237ec034a | ||
|
|
bfae3b5a7d | ||
|
|
5311aa0fb9 | ||
|
|
2dd61e4cce | ||
|
|
63b97d280b | ||
|
|
529d4afb3b | ||
|
|
d2de67bcc3 | ||
|
|
d02d6ceac1 | ||
|
|
4ac4ae03f1 | ||
|
|
4534ed1156 | ||
|
|
c18bdb3abb | ||
|
|
fb524186d1 | ||
|
|
827f10392f | ||
|
|
105f2c76c0 | ||
|
|
2e6617ec83 | ||
|
|
8806f36182 | ||
|
|
07ca91d8a2 | ||
|
|
4443f69056 | ||
|
|
4cc0b04b68 | ||
|
|
89f2e7cf51 | ||
|
|
8b36fea7a5 | ||
|
|
e5848f2f91 | ||
|
|
5448b2f27e | ||
|
|
253b3bdcb9 | ||
|
|
c3a17ca4ca | ||
|
|
4cf7422997 | ||
|
|
270fca127b | ||
|
|
8b614f786d | ||
|
|
415d3fb3a7 | ||
|
|
593086d3b1 | ||
|
|
f3fda343d2 | ||
|
|
6633eb8f60 | ||
|
|
65d66007e0 | ||
|
|
9763f54bf5 | ||
|
|
6be6b5c714 | ||
|
|
f7c4663329 | ||
|
|
03c19bc9cf | ||
|
|
c27410d359 | ||
|
|
00dda2141b | ||
|
|
68c3a1d137 | ||
|
|
e60ab4a54e | ||
|
|
d9d57428ce | ||
|
|
78d30f9546 | ||
|
|
db1b95b15a | ||
|
|
d27c191800 | ||
|
|
682d9bdef1 | ||
|
|
6f3565a4e3 | ||
|
|
a7e70dabe5 | ||
|
|
d602766fc4 | ||
|
|
5c95ae3dd0 | ||
|
|
0e354123fc | ||
|
|
db51fb01c0 | ||
|
|
cfdf283457 | ||
|
|
724e8b9308 | ||
|
|
46a05c916c | ||
|
|
c814a1b384 | ||
|
|
d1eed0fbd5 | ||
|
|
6faa7dbb74 | ||
|
|
57e8c32629 | ||
|
|
9b6425442a | ||
|
|
025f582f6a | ||
|
|
2dec7b28f4 | ||
|
|
30886adc62 | ||
|
|
761d32dab6 | ||
|
|
7dbebc1cd1 | ||
|
|
dd6c793979 | ||
|
|
c441823d94 | ||
|
|
090c82dd40 | ||
|
|
a7a5a3cd4c | ||
|
|
0e36807bd6 | ||
|
|
24c41e5a6d | ||
|
|
22e12b6422 | ||
|
|
0efdefb207 | ||
|
|
80d2045fbb | ||
|
|
7bb0d69a96 | ||
|
|
96d71394fd | ||
|
|
371f9ae4a6 | ||
|
|
b439165246 | ||
|
|
07eefdcea9 | ||
|
|
9d8533e066 | ||
|
|
37f39f29ab | ||
|
|
84d2d583a3 | ||
|
|
f2c73c6ede | ||
|
|
59e92e30f2 | ||
|
|
be1bc8efbb | ||
|
|
ac0206f5ab | ||
|
|
e576fa0be5 | ||
|
|
1e0e432d57 | ||
|
|
3a1c93d4d0 | ||
|
|
378e6192c7 | ||
|
|
67d0a4c88d | ||
|
|
d59297d348 | ||
|
|
1da12a02b6 | ||
|
|
9ceee0b3d9 | ||
|
|
281b4d9773 | ||
|
|
18714288d7 | ||
|
|
8ac098e4f8 | ||
|
|
eda5ab139e | ||
|
|
ab3221cc01 | ||
|
|
92d4ff2027 | ||
|
|
cedf5d263a | ||
|
|
08909baf2f | ||
|
|
383bafae92 | ||
|
|
c2661e11ec | ||
|
|
9c4ccce409 | ||
|
|
c1b2409baa | ||
|
|
54ee9f6c5b | ||
|
|
d83033e983 | ||
|
|
92c0369332 | ||
|
|
d796455bbe | ||
|
|
dc4743f2a3 | ||
|
|
94c8736bc1 | ||
|
|
e05255263b | ||
|
|
e916b5fcc8 | ||
|
|
09e0dbd01d | ||
|
|
84e5ce6dc2 | ||
|
|
2520b709bd | ||
|
|
0ed16b0836 | ||
|
|
6e55514edf | ||
|
|
93d515b423 | ||
|
|
b88ecd97fc | ||
|
|
5c1b39c79f | ||
|
|
bae7263554 | ||
|
|
63f4ed3885 | ||
|
|
ad90c522ac | ||
|
|
374b221f0d | ||
|
|
99adb95816 | ||
|
|
e96a3b304f | ||
|
|
cf4855bdd1 | ||
|
|
8c8c574a4e | ||
|
|
653afd69b6 | ||
|
|
0660c9664d | ||
|
|
a72ef8570a | ||
|
|
4ce55a22f9 | ||
|
|
910c991adb | ||
|
|
b746594b1d | ||
|
|
0698985623 | ||
|
|
859d9dd2b8 | ||
|
|
341d1b6e70 | ||
|
|
cbdf33f253 | ||
|
|
536dd9ea51 | ||
|
|
624b4d4724 | ||
|
|
0e604c81c7 | ||
|
|
3175fe3af2 | ||
|
|
9f37390d59 | ||
|
|
2dfcc9096f | ||
|
|
00d8e60d1e | ||
|
|
010a71ecca | ||
|
|
e82547ddbb | ||
|
|
484b0f5850 | ||
|
|
fd9837aee4 | ||
|
|
255e5e62db | ||
|
|
4da1ec3b76 | ||
|
|
296b717891 | ||
|
|
e709f6ac68 | ||
|
|
e231e4a2b4 | ||
|
|
2e8f168d9f | ||
|
|
e75eb4caa5 | ||
|
|
58905bbc59 | ||
|
|
ae9d89c6c6 | ||
|
|
41ac03a7e1 | ||
|
|
4bded5c565 | ||
|
|
652f5e665f | ||
|
|
05e118ff31 | ||
|
|
c63457674d | ||
|
|
c9b8dbc8dd | ||
|
|
34c6a7f8b1 | ||
|
|
74d4a5368a | ||
|
|
b2256d20e0 | ||
|
|
f887648f48 | ||
|
|
8ee29b4b83 | ||
|
|
a4c6af8ace | ||
|
|
9ec4e52eba | ||
|
|
b756bfa622 | ||
|
|
f96baa58ac | ||
|
|
d9f03a5d0e | ||
|
|
15d2daa887 | ||
|
|
9fc5aa4fc3 | ||
|
|
f6555f49d8 |
@@ -10,7 +10,7 @@
|
||||
<a href="https://t.me/s/vtosters">
|
||||
<img src="https://img.shields.io/badge/-Telegram-blue?style=for-the-badge&logo=telegram&color=2AABEE"/>
|
||||
</a>
|
||||
<a href="https://vk.ru/vtosters_official">
|
||||
<a href="https://vk.com/vtosters_official">
|
||||
<img src="https://img.shields.io/badge/-VK-blue?style=for-the-badge&logo=vk&color=0077FF"/>
|
||||
</a>
|
||||
<a href="https://discord.gg/j9CAt3uYXj">
|
||||
@@ -55,10 +55,11 @@
|
||||
* Лента
|
||||
* Блокировка рекламы в ленте
|
||||
* Блокировка постов через фильтры
|
||||
* Возможность добавлять в вайтлист фильтров группы, чтобы в них не удалялись посты
|
||||
* Возможность отключить рекомендации от ВК
|
||||
* Редактор докбара
|
||||
* Редактор элементов Superapp
|
||||
* Медиа контент
|
||||
* Медиаконтент
|
||||
* Округление дат
|
||||
* 1 января в 4:20
|
||||
* 1 января в 4:20:00
|
||||
@@ -68,8 +69,7 @@
|
||||
* Результаты опросов без участия
|
||||
* Возможность указывать папку для загрузки фото/видео/музыки/всего
|
||||
* Интеграция с <a href="https://www.last.fm/">LAST.FM</a> (а также возможность скробблинга)
|
||||
* Новый раздел музыки
|
||||
* Возможность скачивать видео
|
||||
* Возможность скачивать видео, очищать историю просмотра видео
|
||||
* Возможность найти фотографию через поисковые системы
|
||||
* Интеграция с <a href="https://vkx.app/">VK X</a>
|
||||
* Сообщения
|
||||
@@ -77,18 +77,20 @@
|
||||
* Возможность выключения кнопки записи голосовых сообщений
|
||||
* Возможность скрыть блок рекомендаций в сообщениях
|
||||
* Режим **VK Me**
|
||||
* Возможность вернуть вкладку уведомлений
|
||||
* Возможность вернуть вкладку уведомлений для режима VK Me
|
||||
* Встроенный переводчик текста для сообщений
|
||||
* Возможность выбрать язык перевода
|
||||
* Автоматический перевод ваших сообщений на выбранный язык
|
||||
* Автоматический перевод ваших сообщений на выбранный язык
|
||||
* Альтернативный дизайн эмодзи меню
|
||||
* Возможность использовать системные эмодзи
|
||||
* Возможнсть использовать Enter с аппаратной клавиатуры
|
||||
* Активность
|
||||
* Возможность видеть удаленные сообщения
|
||||
* Функционал, позволяющий оставаться в «оффлайне» (принудительный оффлайн/не отправлять статус онлайна и т.п.)
|
||||
* Нечиталка/неписалка для ЛС/бесед/ботов/групп
|
||||
* Возможность отключить информацию о том, что вы просмотрели историю/прослушали голосовое сообщение
|
||||
* Возможность видеть онлайн пользователей, если у вас скрыт онлайн через VK Messenger
|
||||
* Возможность сохранять настройки бесшумных сообщений/сообщений-бомбочек
|
||||
* Отключить уведомление о том, что вы сделали скриншот в беседе
|
||||
* Отключение редиректа через away.php
|
||||
* Отключение отправки метрики
|
||||
@@ -115,6 +117,7 @@
|
||||
* Возможность скрыть блок рекомендаций друзей в разделе «Друзья»
|
||||
* Возможность скрыть подписи в настройках
|
||||
* Прокси
|
||||
* Поддержка сторонних прокси, таких как: Zaborona, VikaMobile, рандомные прокси и прочие
|
||||
* Возможность использовать **HTTP/HTTPS/SOCKS** прокси, менять домены **API/OAuth/Static**
|
||||
* Другое
|
||||
* Очистка кеша приложения (**всё/стикеры/изображения/видео/сообщения/WebView**)
|
||||
@@ -133,7 +136,7 @@
|
||||
|
||||
`android:debuggable="false"` ➝ `android:debuggable="true"`
|
||||
|
||||
Настройки, необходимые для **отладки** вне Android Studio, находятся по этой ссылке: [vk.ru/vt/debug](https://vk.ru/vt/debug)
|
||||
Настройки, необходимые для **отладки** вне Android Studio, находятся по этой ссылке: [vk.com/vt/debug](https://vk.com/vt/debug)
|
||||
|
||||
* Для дополнительной отладки ответов и логов необходимо включить **[Режим разработчика]**
|
||||
|
||||
@@ -145,7 +148,7 @@
|
||||
|
||||
Сразу после нажатия на запись приложение начнет записывать **все ваши действия** по пути `/Download/VK/logs/com.vtosters.lite/`
|
||||
|
||||
При следующем открытии приложения оно автоматически сохранит логи и отправит вам в [**Документы** ВК](https://vk.ru/docs), откуда вы можете скачать архив логов и работать с ними.
|
||||
При следующем открытии приложения оно автоматически сохранит логи и отправит вам в [**Документы** ВК](https://vk.com/docs), откуда вы можете скачать архив логов и работать с ними.
|
||||
|
||||
## Разработка
|
||||
|
||||
|
||||
+4
-2
@@ -77,10 +77,11 @@ android {
|
||||
targetSdkVersion 32
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
multiDexEnabled false
|
||||
multiDexEnabled true
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
coreLibraryDesugaringEnabled true
|
||||
sourceCompatibility JavaVersion.VERSION_11
|
||||
targetCompatibility JavaVersion.VERSION_11
|
||||
}
|
||||
@@ -88,8 +89,9 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
|
||||
implementation 'net.sourceforge.streamsupport:streamsupport-minifuture:1.7.4'
|
||||
implementation 'com.google.android.material:material:1.6.1'
|
||||
implementation 'androidx.exifinterface:exifinterface:1.3.3'
|
||||
implementation 'androidx.preference:preference:1.2.0'
|
||||
implementation fileTree(dir: 'libs', include: ['*.aar'])
|
||||
compileOnly fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// IVKExternalMusic.aidl
|
||||
package bruhcollective.itaysonlab.libvkx;
|
||||
|
||||
interface ILibVkxService {
|
||||
// Starts playback. playbackContext can be "other" if you don't sure what it is
|
||||
void play(in List<String> audio_ids, in int index, in String playbackContext) = 1;
|
||||
|
||||
// A UserID. CHECK FOR THIS TO BE EQUAL BEFORE SENDING ANYTHING TO SERVICE!
|
||||
int getUserId() = 2;
|
||||
|
||||
// Cache add/remove
|
||||
void addTrackToCache(in int track_id, in int owner_id, in String access_key) = 3;
|
||||
void deleteTrackFromCache(in int track_id, in int owner_id) = 4;
|
||||
boolean isTrackCached(in int track_id, in int owner_id) = 5;
|
||||
|
||||
// Get a list of cached tracks. The response is close to VK's original response (an audio list)
|
||||
// Also, the items in the list are JSON ones.
|
||||
List<String> getCache() = 6;
|
||||
|
||||
// [ver 1.1]
|
||||
void downloadTrack(in int track_id, in int owner_id, in String access_key) = 7;
|
||||
void downloadPlaylist(in int playlist_id, in int owner_id, in String access_key) = 8;
|
||||
void addPlaylistToCache(in int playlist_id, in int owner_id, in String access_key) = 9;
|
||||
void deletePlaylistFromCache(in int playlist_id, in int owner_id) = 10;
|
||||
|
||||
// [ver 1.2]
|
||||
String getCacheCatalog() = 11;
|
||||
List<String> getTracksInPlaylist(in String playlist_id, in String owner_id) = 12;
|
||||
String getPlaylistDefJson(in String playlist_id, in String owner_id) = 13;
|
||||
|
||||
// [ver 1.3]
|
||||
boolean isPlaylistCached(in int playlist_id, in int owner_id) = 14;
|
||||
}
|
||||
@@ -1,340 +0,0 @@
|
||||
/*
|
||||
* This file is auto-generated. DO NOT MODIFY.
|
||||
*/
|
||||
package bruhcollective.itaysonlab.libvkx;
|
||||
|
||||
// Works only with original signature of VT
|
||||
|
||||
public interface ILibVkxService extends android.os.IInterface {
|
||||
void play(java.util.List<String> audio_ids, int index, String playbackContext) throws android.os.RemoteException;
|
||||
|
||||
int getUserId() throws android.os.RemoteException;
|
||||
// Starts playback. playbackContext can be "other" if you don't sure what it is
|
||||
|
||||
void addTrackToCache(int track_id, int owner_id, String access_key) throws android.os.RemoteException;
|
||||
// A UserID. CHECK FOR THIS TO BE EQUAL BEFORE SENDING ANYTHING TO SERVICE!
|
||||
|
||||
void deleteTrackFromCache(int track_id, int owner_id) throws android.os.RemoteException;
|
||||
// Cache add/remove
|
||||
|
||||
boolean isTrackCached(int track_id, int owner_id) throws android.os.RemoteException;
|
||||
|
||||
java.util.List<String> getCache() throws android.os.RemoteException;
|
||||
|
||||
/**
|
||||
* Default implementation for ILibVkxService.
|
||||
*/
|
||||
class Default implements ILibVkxService {
|
||||
// Starts playback. playbackContext can be "other" if you don't sure what it is
|
||||
|
||||
@Override
|
||||
public void play(java.util.List<String> audio_ids, int index, String playbackContext) throws android.os.RemoteException {
|
||||
}
|
||||
// A UserID. CHECK FOR THIS TO BE EQUAL BEFORE SENDING ANYTHING TO SERVICE!
|
||||
|
||||
@Override
|
||||
public int getUserId() throws android.os.RemoteException {
|
||||
return 0;
|
||||
}
|
||||
// Cache add/remove
|
||||
|
||||
@Override
|
||||
public void addTrackToCache(int track_id, int owner_id, String access_key) throws android.os.RemoteException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTrackFromCache(int track_id, int owner_id) throws android.os.RemoteException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTrackCached(int track_id, int owner_id) throws android.os.RemoteException {
|
||||
return false;
|
||||
}
|
||||
// Get a list of cached tracks. The response is close to VK's original response (an audio list)
|
||||
// Also, the items in the list are JSON ones.
|
||||
|
||||
@Override
|
||||
public java.util.List<String> getCache() throws android.os.RemoteException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.os.IBinder asBinder() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// Get a list of cached tracks. The response is close to VK's original response (an audio list)
|
||||
// Also, the items in the list are JSON ones.
|
||||
|
||||
/**
|
||||
* Local-side IPC implementation stub class.
|
||||
*/
|
||||
abstract class Stub extends android.os.Binder implements ILibVkxService {
|
||||
static final int TRANSACTION_play = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
|
||||
static final int TRANSACTION_getUserId = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
|
||||
static final int TRANSACTION_addTrackToCache = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);
|
||||
static final int TRANSACTION_deleteTrackFromCache = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);
|
||||
static final int TRANSACTION_isTrackCached = (android.os.IBinder.FIRST_CALL_TRANSACTION + 5);
|
||||
static final int TRANSACTION_getCache = (android.os.IBinder.FIRST_CALL_TRANSACTION + 6);
|
||||
private static final String DESCRIPTOR = "bruhcollective.itaysonlab.libvkx.ILibVkxService";
|
||||
|
||||
/**
|
||||
* Construct the stub at attach it to the interface.
|
||||
*/
|
||||
public Stub() {
|
||||
this.attachInterface(this, DESCRIPTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast an IBinder object into an bruhcollective.itaysonlab.libvkx.ILibVkxService interface,
|
||||
* generating a proxy if needed.
|
||||
*/
|
||||
public static ILibVkxService asInterface(android.os.IBinder obj) {
|
||||
if ((obj == null)) {
|
||||
return null;
|
||||
}
|
||||
android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
|
||||
if (((iin != null) && (iin instanceof ILibVkxService))) {
|
||||
return ((ILibVkxService) iin);
|
||||
}
|
||||
return new Proxy(obj);
|
||||
}
|
||||
|
||||
public static boolean setDefaultImpl(ILibVkxService impl) {
|
||||
if (Proxy.sDefaultImpl == null && impl != null) {
|
||||
Proxy.sDefaultImpl = impl;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ILibVkxService getDefaultImpl() {
|
||||
return Proxy.sDefaultImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.os.IBinder asBinder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException {
|
||||
String descriptor = DESCRIPTOR;
|
||||
switch (code) {
|
||||
case INTERFACE_TRANSACTION: {
|
||||
reply.writeString(descriptor);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_play: {
|
||||
data.enforceInterface(descriptor);
|
||||
java.util.List<String> _arg0;
|
||||
_arg0 = data.createStringArrayList();
|
||||
int _arg1;
|
||||
_arg1 = data.readInt();
|
||||
String _arg2;
|
||||
_arg2 = data.readString();
|
||||
this.play(_arg0, _arg1, _arg2);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getUserId: {
|
||||
data.enforceInterface(descriptor);
|
||||
int _result = this.getUserId();
|
||||
reply.writeNoException();
|
||||
reply.writeInt(_result);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_addTrackToCache: {
|
||||
data.enforceInterface(descriptor);
|
||||
int _arg0;
|
||||
_arg0 = data.readInt();
|
||||
int _arg1;
|
||||
_arg1 = data.readInt();
|
||||
String _arg2;
|
||||
_arg2 = data.readString();
|
||||
this.addTrackToCache(_arg0, _arg1, _arg2);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_deleteTrackFromCache: {
|
||||
data.enforceInterface(descriptor);
|
||||
int _arg0;
|
||||
_arg0 = data.readInt();
|
||||
int _arg1;
|
||||
_arg1 = data.readInt();
|
||||
this.deleteTrackFromCache(_arg0, _arg1);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_isTrackCached: {
|
||||
data.enforceInterface(descriptor);
|
||||
int _arg0;
|
||||
_arg0 = data.readInt();
|
||||
int _arg1;
|
||||
_arg1 = data.readInt();
|
||||
boolean _result = this.isTrackCached(_arg0, _arg1);
|
||||
reply.writeNoException();
|
||||
reply.writeInt(((_result) ? (1) : (0)));
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getCache: {
|
||||
data.enforceInterface(descriptor);
|
||||
java.util.List<String> _result = this.getCache();
|
||||
reply.writeNoException();
|
||||
reply.writeStringList(_result);
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
return super.onTransact(code, data, reply, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class Proxy implements ILibVkxService {
|
||||
public static ILibVkxService sDefaultImpl;
|
||||
private final android.os.IBinder mRemote;
|
||||
|
||||
Proxy(android.os.IBinder remote) {
|
||||
mRemote = remote;
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.os.IBinder asBinder() {
|
||||
return mRemote;
|
||||
}
|
||||
// Starts playback. playbackContext can be "other" if you don't sure what it is
|
||||
|
||||
public String getInterfaceDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
// A UserID. CHECK FOR THIS TO BE EQUAL BEFORE SENDING ANYTHING TO SERVICE!
|
||||
|
||||
@Override
|
||||
public void play(java.util.List<String> audio_ids, int index, String playbackContext) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeStringList(audio_ids);
|
||||
_data.writeInt(index);
|
||||
_data.writeString(playbackContext);
|
||||
boolean _status = mRemote.transact(Stub.TRANSACTION_play, _data, _reply, 0);
|
||||
if (!_status && getDefaultImpl() != null) {
|
||||
getDefaultImpl().play(audio_ids, index, playbackContext);
|
||||
return;
|
||||
}
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
// Cache add/remove
|
||||
|
||||
@Override
|
||||
public int getUserId() throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
int _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
boolean _status = mRemote.transact(Stub.TRANSACTION_getUserId, _data, _reply, 0);
|
||||
if (!_status && getDefaultImpl() != null) {
|
||||
return getDefaultImpl().getUserId();
|
||||
}
|
||||
_reply.readException();
|
||||
_result = _reply.readInt();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTrackToCache(int track_id, int owner_id, String access_key) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(track_id);
|
||||
_data.writeInt(owner_id);
|
||||
_data.writeString(access_key);
|
||||
boolean _status = mRemote.transact(Stub.TRANSACTION_addTrackToCache, _data, _reply, 0);
|
||||
if (!_status && getDefaultImpl() != null) {
|
||||
getDefaultImpl().addTrackToCache(track_id, owner_id, access_key);
|
||||
return;
|
||||
}
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTrackFromCache(int track_id, int owner_id) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(track_id);
|
||||
_data.writeInt(owner_id);
|
||||
boolean _status = mRemote.transact(Stub.TRANSACTION_deleteTrackFromCache, _data, _reply, 0);
|
||||
if (!_status && getDefaultImpl() != null) {
|
||||
getDefaultImpl().deleteTrackFromCache(track_id, owner_id);
|
||||
return;
|
||||
}
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
// Get a list of cached tracks. The response is close to VK's original response (an audio list)
|
||||
// Also, the items in the list are JSON ones.
|
||||
|
||||
@Override
|
||||
public boolean isTrackCached(int track_id, int owner_id) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
boolean _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(track_id);
|
||||
_data.writeInt(owner_id);
|
||||
boolean _status = mRemote.transact(Stub.TRANSACTION_isTrackCached, _data, _reply, 0);
|
||||
if (!_status && getDefaultImpl() != null) {
|
||||
return getDefaultImpl().isTrackCached(track_id, owner_id);
|
||||
}
|
||||
_reply.readException();
|
||||
_result = (0 != _reply.readInt());
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<String> getCache() throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
java.util.List<String> _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
boolean _status = mRemote.transact(Stub.TRANSACTION_getCache, _data, _reply, 0);
|
||||
if (!_status && getDefaultImpl() != null) {
|
||||
return getDefaultImpl().getCache();
|
||||
}
|
||||
_reply.readException();
|
||||
_result = _reply.createStringArrayList();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,13 @@ public class LibVKXClient {
|
||||
return getInstance().runOnService(action);
|
||||
}
|
||||
|
||||
public static void lambdaplay(List<MusicTrack> list, MusicTrack musicTrack, ILibVkxService iLibVkxService) {
|
||||
public static void lambdaplay(List<MusicTrack> list, MusicTrack musicTrack, ILibVkxService iLibVkxService, MusicPlaybackLaunchContext playerRefer) {
|
||||
var playbackContext = "";
|
||||
|
||||
if (playerRefer != null) {
|
||||
playbackContext = playerRefer.v0();
|
||||
}
|
||||
|
||||
int indexOf = list.indexOf(musicTrack);
|
||||
var ids = new ArrayList<String>();
|
||||
for (var track : list) {
|
||||
@@ -65,17 +71,21 @@ public class LibVKXClient {
|
||||
}
|
||||
|
||||
try {
|
||||
iLibVkxService.play(ids, indexOf, "");
|
||||
iLibVkxService.play(ids, indexOf, playbackContext);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static String asId(MusicTrack musicTrack) {
|
||||
String str = musicTrack.e + "_" + musicTrack.d;
|
||||
if (musicTrack.O == null || musicTrack.O.equals("")) {
|
||||
return str;
|
||||
public static void lambdaplay(List<MusicTrack> list, MusicTrack musicTrack, ILibVkxService iLibVkxService){
|
||||
lambdaplay(list, musicTrack, iLibVkxService, null);
|
||||
}
|
||||
|
||||
public static String asId(MusicTrack musicTrack) {
|
||||
String id = musicTrack.e + "_" + musicTrack.d;
|
||||
if (musicTrack.O != null && !musicTrack.O.equals("")) {
|
||||
id += "_" + musicTrack.O;
|
||||
}
|
||||
return str + "_" + musicTrack.O;
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,5 @@
|
||||
package com.vk.core.util;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.Preferences.getDownloadsDir;
|
||||
import static ru.vtosters.lite.utils.Preferences.getMusicDir;
|
||||
import static ru.vtosters.lite.utils.Preferences.getPhotosDir;
|
||||
import static ru.vtosters.lite.utils.Preferences.getVideosDir;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
@@ -13,8 +7,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -24,10 +18,11 @@ import com.vk.core.concurrent.VkExecutors;
|
||||
import com.vk.imageloader.VKImageLoader;
|
||||
import com.vk.log.L;
|
||||
import com.vk.metrics.eventtracking.VkTracker;
|
||||
import com.vtosters.lite.MainActivity;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.HashSet;
|
||||
@@ -55,52 +50,61 @@ public class DownloadUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static void b(final Context context, String str, String str2, boolean z) {
|
||||
if (TextUtils.isEmpty(str2)) {
|
||||
private static void b(final Context context, String str, String uri, boolean z) {
|
||||
if (TextUtils.isEmpty(uri)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String file = a(str, str2);
|
||||
File b2;
|
||||
boolean pic = false;
|
||||
boolean c2 = MediaUtils.c(MediaUtils.b(str2));
|
||||
String fileName = a(str, uri);
|
||||
File file;
|
||||
|
||||
if (file.endsWith(".jpg") || file.endsWith(".png") || file.endsWith(".jpeg")) {
|
||||
b2 = new File(getPhotosDir(), file);
|
||||
pic = true;
|
||||
} else if (file.endsWith(".mp3") || file.endsWith(".wav") || file.endsWith(".ogg") || file.endsWith(".aac") || file.endsWith(".flac") || file.endsWith(".m4a")) {
|
||||
b2 = new File(getMusicDir(), file);
|
||||
} else if (file.endsWith(".mp4") || file.endsWith(".mkv") || file.endsWith(".avi") || file.endsWith(".flv") || file.endsWith(".wmv") || file.endsWith(".mov") || file.endsWith(".3gp")) {
|
||||
b2 = new File(getVideosDir(), file);
|
||||
Log.v("DownloadUtils", "download: filename = " + fileName + " | str = " + str + "| str2 = " + uri);
|
||||
|
||||
if (fileName.endsWith(".jpg") || fileName.endsWith(".png") || fileName.endsWith(".jpeg")) {
|
||||
file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath(), fileName);
|
||||
} else if (fileName.endsWith(".mp3") || fileName.endsWith(".wav") || fileName.endsWith(".ogg") || fileName.endsWith(".aac") || fileName.endsWith(".flac") || fileName.endsWith(".m4a")) {
|
||||
file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath(), fileName);
|
||||
} else if (fileName.endsWith(".mp4") || fileName.endsWith(".mkv") || fileName.endsWith(".avi") || fileName.endsWith(".flv") || fileName.endsWith(".wmv") || fileName.endsWith(".mov") || fileName.endsWith(".3gp")) {
|
||||
file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath(), fileName);
|
||||
} else {
|
||||
b2 = new File(getDownloadsDir(), file);
|
||||
file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(), fileName);
|
||||
}
|
||||
|
||||
if (c2) {
|
||||
EncodedImage c3 = VKImageLoader.c(Uri.parse(str2));
|
||||
final InputStream h = c3 == null ? null : c3.h();
|
||||
boolean isImage = MediaUtils.c(FileUtils.f(file));
|
||||
|
||||
if (isImage) {
|
||||
EncodedImage encodedImage = VKImageLoader.c(Uri.parse(uri));
|
||||
final InputStream h = encodedImage == null ? null : encodedImage.h();
|
||||
if (h != null) {
|
||||
try {
|
||||
if (b2.getParentFile() != null) {
|
||||
b2.createNewFile();
|
||||
if (file.getParentFile() != null) {
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
if (b2.exists()) {
|
||||
VkExecutors.x.a().execute(() -> ToastUtils.a(context.getString(R.string.file_saved, b2.getAbsoluteFile())));
|
||||
if (file.exists()) {
|
||||
VkExecutors.x.e().execute(() -> {
|
||||
try {
|
||||
FileUtils.b.a(h, new FileOutputStream(file), h.available(), null);
|
||||
ToastUtils.a(context.getString(R.string.file_saved, file.getAbsoluteFile()));
|
||||
} catch (IOException e) {
|
||||
ToastUtils.a(context.getString(R.string.error) + " [" + e.getMessage() + "]");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} catch (Exception e2) {
|
||||
L.a(e2);
|
||||
}
|
||||
|
||||
CameraUtils.a(context, b2, null);
|
||||
CameraUtils.a(context, file, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(str2));
|
||||
request.setDestinationUri(Uri.fromFile(b2));
|
||||
request.setMimeType(FileUtils.f(new File(str)));
|
||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(uri));
|
||||
var mimeType = FileUtils.f(file);
|
||||
request.setDestinationUri(Uri.fromFile(file));
|
||||
request.setMimeType(mimeType);
|
||||
request.setNotificationVisibility(1);
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setTitle(str);
|
||||
@@ -110,9 +114,6 @@ public class DownloadUtils {
|
||||
}
|
||||
try {
|
||||
long enqueue = a2.enqueue(request);
|
||||
if (pic) {
|
||||
CameraUtils.a(context, b2, null);
|
||||
}
|
||||
if (!z) {
|
||||
return;
|
||||
}
|
||||
@@ -192,10 +193,12 @@ public class DownloadUtils {
|
||||
}
|
||||
Intent intent = new Intent("android.intent.action.VIEW");
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
String f2 = FileUtils.f(file);
|
||||
if (!TextUtils.isEmpty(f2)) {
|
||||
var mimeType = FileUtils.f(file);
|
||||
var uri = FileUtils.uriFromFile(file);
|
||||
Log.d("DownloadUtils", "openFile: " + file.getAbsolutePath() + "| mimetype " + mimeType + "| uri " + uri);
|
||||
if (!TextUtils.isEmpty(mimeType)) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.setDataAndType(FileUtils.uriFromFile(file), f2);
|
||||
intent.setDataAndType(uri, mimeType);
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
@@ -216,9 +219,13 @@ public class DownloadUtils {
|
||||
|
||||
private static boolean a(Context context, File file) {
|
||||
if (file != null && file.exists()) {
|
||||
var mimeType = FileUtils.f(file);
|
||||
var uri = FileUtils.uriFromFile(file);
|
||||
|
||||
Intent intent = new Intent("android.intent.action.VIEW");
|
||||
intent.setDataAndType(Uri.parse(file.getAbsolutePath()), "application/*");
|
||||
intent.setDataAndType(uri, mimeType);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Log.d("DownloadUtils", "openFile: " + file.getAbsolutePath() + "| mimetype " + mimeType + "| uri " + uri);
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
@@ -36,8 +35,6 @@ import com.vtosters.lite.a0;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
@UiThread
|
||||
public class TargetImageView extends VKMultiImageView {
|
||||
private static final int I = Screen.a(2);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.vk.stories.view;
|
||||
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getColor2;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
@@ -29,7 +27,6 @@ import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import com.facebook.u.b.a.PipelineDraweeControllerBuilder;
|
||||
import com.facebook.x.g.CloseableImage;
|
||||
import com.vk.core.drawable.BorderDrawable;
|
||||
import com.vk.core.ui.themes.Themable;
|
||||
import com.vk.core.ui.themes.VKThemeHelper;
|
||||
import com.vk.core.util.DrawableUtils;
|
||||
@@ -50,8 +47,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class StoryCircleImageView extends BorderedCircleImageView implements Themable{
|
||||
private static final HashSet<Integer> B0 = new HashSet<>();
|
||||
private final PipelineDraweeControllerBuilder f0;
|
||||
|
||||
+1
-2
@@ -1,6 +1,6 @@
|
||||
package com.vtosters.lite.ui.bottomnavigation;
|
||||
|
||||
import static ru.vtosters.lite.utils.Preferences.*;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getCSTDock;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
@@ -31,7 +31,6 @@ import com.vk.core.ui.themes.VKThemeHelper;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import me.grishka.appkit.utils.V;
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
|
||||
public class BottomNavigationItemView extends FrameLayout implements MenuView.ItemView {
|
||||
private final TextView mSmallLabel;
|
||||
|
||||
@@ -5,8 +5,6 @@ import static com.vk.im.engine.h.im_ic_edit_msg;
|
||||
import static com.vk.im.engine.h.im_ic_more_vertical;
|
||||
import static com.vk.im.engine.h.im_ic_pinned_msg_hide;
|
||||
import static com.vk.im.engine.h.im_ic_pinned_msg_show;
|
||||
import static com.vk.im.engine.h.im_ic_write_msg;
|
||||
import static com.vk.im.ui.c.im_ic_chat_settings;
|
||||
import static com.vk.im.ui.c.im_ic_keyboard;
|
||||
import static ru.vtosters.lite.dnr.DNRModule.hookDNR;
|
||||
import static ru.vtosters.lite.dnr.DNRModule.hookDNT;
|
||||
@@ -17,8 +15,8 @@ import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.isTablet;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.Preferences.getDownloadsDir;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
@@ -29,7 +27,6 @@ import com.vk.core.network.Network;
|
||||
import com.vk.im.engine.ImEngine1;
|
||||
import com.vk.im.engine.events.OnDialogUpdateEvent;
|
||||
import com.vk.im.engine.models.EntityIntMap;
|
||||
import com.vk.im.engine.models.ProfilesSimpleInfo;
|
||||
import com.vk.im.engine.models.dialogs.Dialog;
|
||||
import com.vk.im.engine.models.messages.Msg;
|
||||
import com.vk.im.engine.models.messages.MsgFromUser;
|
||||
@@ -52,14 +49,21 @@ import ru.vtosters.lite.encryption.EncryptProvider;
|
||||
import ru.vtosters.lite.encryption.base.IMProcessor;
|
||||
import ru.vtosters.lite.hooks.CryptImHook;
|
||||
import ru.vtosters.lite.ui.dialogs.Translate;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class DNRInjector {
|
||||
public static void inject(Dialog dialog, List<DialogAction> list) {
|
||||
int peerId = 0;
|
||||
|
||||
if (dialog != null) {
|
||||
peerId = dialog.getId();
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e){
|
||||
Log.d("DialoggetId", "null");
|
||||
}
|
||||
}
|
||||
|
||||
if (peerId == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
list.add(DialogAction.DOWNLOAD);
|
||||
@@ -113,8 +117,10 @@ public class DNRInjector {
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DNT_ON, 2, im_ic_edit_msg, getIdentifier("DNT_ON", "string"))); // DialogAction, Int, Icon, String
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DNT_OFF, 2, im_ic_edit_msg, getIdentifier("DNT_OFF", "string"))); // DialogAction, Int, Icon, String
|
||||
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.ENCRYPT, 3, im_ic_keyboard, getIdentifier("encryption", "string"))); // DialogAction, Int, Icon, String
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.ENCRYPT_SETT, 3, im_ic_more_vertical, getIdentifier("encryption_sett", "string"))); // DialogAction, Int, Icon, String
|
||||
if (!isTablet()) {
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.ENCRYPT, 3, im_ic_keyboard, getIdentifier("encryption", "string"))); // DialogAction, Int, Icon, String
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.ENCRYPT_SETT, 3, im_ic_more_vertical, getIdentifier("encryption_sett", "string"))); // DialogAction, Int, Icon, String
|
||||
}
|
||||
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.MARK_AS_READ, 4, im_ic_done, getIdentifier("vkim_dialogs_list_option_mark_as_read", "string"))); // DialogAction, Int, Icon, String
|
||||
|
||||
@@ -131,7 +137,15 @@ public class DNRInjector {
|
||||
int peerId = 0;
|
||||
|
||||
if (dialog != null) {
|
||||
peerId = dialog.getId();
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e){
|
||||
Log.d("DialoggetId", "null");
|
||||
}
|
||||
}
|
||||
|
||||
if (peerId == 0) {
|
||||
return actions;
|
||||
}
|
||||
|
||||
actions.add(DialogAction.DOWNLOAD);
|
||||
@@ -162,7 +176,15 @@ public class DNRInjector {
|
||||
int peerId = 0;
|
||||
|
||||
if (dialog != null) {
|
||||
peerId = dialog.getId();
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e){
|
||||
Log.d("DialoggetId", "null");
|
||||
}
|
||||
}
|
||||
|
||||
if (peerId == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.MARK_AS_READ) {
|
||||
@@ -171,7 +193,7 @@ public class DNRInjector {
|
||||
}
|
||||
|
||||
if (action == DialogAction.DOWNLOAD) {
|
||||
File out = new File(Environment.getExternalStoragePublicDirectory(getDownloadsDir().getName()), "dialog-" + peerId + ".html");
|
||||
File out = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "dialog-" + peerId + ".html");
|
||||
try {
|
||||
new MessagesDownloader().downloadDialog(peerId, new MessagesDownloader.HtmlDialogDownloaderFormatProvider(), out);
|
||||
} catch (Exception e) {
|
||||
@@ -216,7 +238,15 @@ public class DNRInjector {
|
||||
int peerId = 0;
|
||||
|
||||
if (dialog != null) {
|
||||
peerId = dialog.getId();
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e){
|
||||
Log.d("DialoggetId", "null");
|
||||
}
|
||||
}
|
||||
|
||||
if (peerId == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.MARK_AS_READ) {
|
||||
@@ -224,7 +254,7 @@ public class DNRInjector {
|
||||
}
|
||||
|
||||
if (action == DialogAction.DOWNLOAD) {
|
||||
File out = new File(Environment.getExternalStoragePublicDirectory(getDownloadsDir().getPath()), peerId + "-dialog.html");
|
||||
File out = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), peerId + "-dialog.html");
|
||||
try {
|
||||
new MessagesDownloader().downloadDialog(peerId, new MessagesDownloader.HtmlDialogDownloaderFormatProvider(), out);
|
||||
} catch (Exception e) {
|
||||
@@ -275,37 +305,40 @@ public class DNRInjector {
|
||||
}
|
||||
|
||||
public static boolean onClickMsg(Context context, MsgAction action, Msg msg) {
|
||||
var text = ((MsgFromUser) msg).f();
|
||||
var peerId = msg.v1();
|
||||
var fullMsg = ((MsgFromUser) msg).j2(); // text + reply
|
||||
var reply = fullMsg.substring(text.length() + 1);
|
||||
|
||||
if (action == MsgAction.valueOf("READTO")) {
|
||||
DNRModule.hookReadStartMsgTo(msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
var isTextExist = !text.isEmpty() && !text.equals(" ");
|
||||
var isReplyExist = !reply.isEmpty() && !reply.equals(" ");
|
||||
if (msg instanceof MsgFromUser){
|
||||
var text = ((MsgFromUser) msg).f();
|
||||
var fullMsg = ((MsgFromUser) msg).j2(); // text + reply
|
||||
var reply = fullMsg.substring(text.length() + 1);
|
||||
|
||||
var isTextExist = !text.isEmpty() && !text.equals(" ");
|
||||
var isReplyExist = !reply.isEmpty() && !reply.equals(" ");
|
||||
|
||||
|
||||
if (isReplyExist) {
|
||||
reply = decryptMessage(reply, peerId);
|
||||
}
|
||||
if (isReplyExist) {
|
||||
reply = decryptMessage(reply, peerId);
|
||||
}
|
||||
|
||||
if (isTextExist) {
|
||||
text = decryptMessage(text, peerId);
|
||||
}
|
||||
if (isTextExist) {
|
||||
text = decryptMessage(text, peerId);
|
||||
}
|
||||
|
||||
if (action == MsgAction.valueOf("TRANSLATE")) {
|
||||
if (isTextExist && isReplyExist) {
|
||||
Translate.showTranslatedText(context, text + "\n\n" + getString("translator_reply") + "\n" + reply);
|
||||
} else if (isReplyExist) {
|
||||
Translate.showTranslatedText(context, getString("translator_reply") + "\n" + reply);
|
||||
} else if (isTextExist) {
|
||||
Translate.showTranslatedText(context, text);
|
||||
} else {
|
||||
sendToast(getString("translator_no_text"));
|
||||
if (action == MsgAction.valueOf("TRANSLATE")) {
|
||||
if (isTextExist && isReplyExist) {
|
||||
Translate.showTranslatedText(context, text + "\n\n" + getString("translator_reply") + "\n" + reply);
|
||||
} else if (isReplyExist) {
|
||||
Translate.showTranslatedText(context, getString("translator_reply") + "\n" + reply);
|
||||
} else if (isTextExist) {
|
||||
Translate.showTranslatedText(context, text);
|
||||
} else {
|
||||
sendToast(getString("translator_no_text"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.vtosters.lite.dnr;
|
||||
|
||||
import static ru.vtosters.lite.net.Request.makeRequest;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
@@ -1,123 +1,136 @@
|
||||
package ru.vtosters.lite.downloaders;
|
||||
|
||||
import static ru.vtosters.lite.utils.Preferences.getMusicDir;
|
||||
import static ru.vtosters.lite.music.cache.FileCacheImplementation.getTrackFolder;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserId;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
import com.vk.dto.music.Playlist;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import ru.vtosters.lite.downloaders.notifications.NotificationChannels;
|
||||
import ru.vtosters.lite.music.Callback;
|
||||
import ru.vtosters.lite.music.FFMpeg;
|
||||
import ru.vtosters.lite.music.M3UDownloader;
|
||||
import ru.vtosters.lite.music.MP3Downloader;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.music.cache.FileCacheImplementation;
|
||||
import ru.vtosters.lite.music.callback.MusicCallbackBuilder;
|
||||
import ru.vtosters.lite.music.converter.playlist.PlaylistConverter;
|
||||
import ru.vtosters.lite.music.downloader.AudioGet;
|
||||
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.IOUtils;
|
||||
|
||||
/**
|
||||
* Entrypoint for downloading audio
|
||||
* <p>
|
||||
* The actual code is in {@link ru.vtosters.lite.music}
|
||||
*/
|
||||
|
||||
public class AudioDownloader {
|
||||
private static NotificationManagerCompat notificationManager = NotificationManagerCompat.from(AndroidUtils.getGlobalContext());
|
||||
private static final Executor executor = Executors.newFixedThreadPool(4);
|
||||
|
||||
public static void downloadAudio(MusicTrack track) {
|
||||
if (AndroidUtils.getDefaultPrefs().getBoolean("new_music_downloading_way", false)) {
|
||||
downloadMP3(track);
|
||||
} else {
|
||||
downloadM3U8(track);
|
||||
}
|
||||
public static void downloadPlaylist(Playlist playlist) {
|
||||
var tracks = PlaylistConverter.getPlaylist(playlist);
|
||||
|
||||
var playlistName = IOUtils.getValidFileName(playlist.g);
|
||||
|
||||
var musicPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath();
|
||||
var downloadPath = musicPath + File.separator + playlistName;
|
||||
|
||||
var notificationId = playlistName.hashCode();
|
||||
var notification = MusicNotificationBuilder.buildPlaylistDownloadNotification(playlistName, notificationId);
|
||||
|
||||
PlaylistDownloader.downloadPlaylist(
|
||||
tracks,
|
||||
IOUtils.getValidFileName(playlist.g),
|
||||
downloadPath,
|
||||
MusicCallbackBuilder.buildPlaylistCallback(tracks.size(), notification, notificationId)
|
||||
);
|
||||
}
|
||||
|
||||
public static void downloadM3U8(MusicTrack track) {
|
||||
if (track.D == null) {
|
||||
ToastUtils.a(AndroidUtils.getString("link_audio_error"));
|
||||
|
||||
public static void downloadAudio(MusicTrack track) {
|
||||
downloadM3U8(track, false);
|
||||
}
|
||||
|
||||
public static void cacheTrack(MusicTrack track) {
|
||||
var trackId = track.y1();
|
||||
if (CacheDatabaseDelegate.isCached(trackId)) {
|
||||
CacheDatabaseDelegate.removeTrackFromCache(LibVKXClient.asId(track));
|
||||
return;
|
||||
}
|
||||
|
||||
var musicPath = getMusicDir().getAbsolutePath();
|
||||
var musicDir = new File(musicPath);
|
||||
if (!musicDir.exists()) {
|
||||
if (musicDir.mkdirs()) {
|
||||
Log.d("AudioDownloader", "Created music dir");
|
||||
} else {
|
||||
Log.e("AudioDownloader", "Failed to create music dir");
|
||||
return;
|
||||
}
|
||||
var trackFile = FileCacheImplementation.getTrackFile(trackId);
|
||||
if (!trackFile.exists())
|
||||
trackFile.getParentFile().mkdirs();
|
||||
downloadM3U8(track, true);
|
||||
MusicNotificationBuilder.notifySavingToCache(track);
|
||||
CacheDatabaseDelegate.insertTrack(track);
|
||||
}
|
||||
|
||||
public static void cachePlaylist(Playlist playlist) {
|
||||
var tracks = PlaylistConverter.getPlaylist(playlist);
|
||||
|
||||
var notificationId = playlist.g.hashCode();
|
||||
var notification = MusicNotificationBuilder.buildPlaylistDownloadNotification(playlist.g, notificationId);
|
||||
|
||||
PlaylistDownloader.cachePlaylist(
|
||||
tracks,
|
||||
MusicCallbackBuilder.buildPlaylistCallback(tracks.size(), notification, notificationId)
|
||||
);
|
||||
}
|
||||
|
||||
public static void cacheAllAudios() {
|
||||
var tracks = AudioGet.getAudios();
|
||||
|
||||
var notificationId = getUserId();
|
||||
var notification = MusicNotificationBuilder.buildAllAudiosDownloadNotification(notificationId);
|
||||
|
||||
PlaylistDownloader.cachePlaylist(
|
||||
tracks,
|
||||
MusicCallbackBuilder.buildPlaylistCallback(tracks.size(), notification, notificationId)
|
||||
);
|
||||
}
|
||||
|
||||
public static void downloadAllAudios() {
|
||||
var tracks = AudioGet.getAudios();
|
||||
|
||||
var notificationId = getUserId();
|
||||
var notification = MusicNotificationBuilder.buildAllAudiosDownloadNotification(notificationId);
|
||||
|
||||
var playlistName = "Audios of " + getUserId();
|
||||
|
||||
var musicPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath();
|
||||
var downloadPath = musicPath + File.separator + playlistName;
|
||||
|
||||
PlaylistDownloader.downloadPlaylist(
|
||||
tracks,
|
||||
playlistName,
|
||||
downloadPath,
|
||||
MusicCallbackBuilder.buildPlaylistCallback(tracks.size(), notification, notificationId)
|
||||
);
|
||||
}
|
||||
|
||||
private static void downloadM3U8(MusicTrack track, boolean cache) {
|
||||
if (track.D == null) {
|
||||
ToastUtils.a(getString("link_audio_error"));
|
||||
return;
|
||||
}
|
||||
|
||||
var musicPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath();
|
||||
var tempId = track.d;
|
||||
var downloadPath = musicPath + File.separator + tempId;
|
||||
var downloadPath = musicPath + File.separator;
|
||||
var notification = MusicNotificationBuilder.buildDownloadNotification(track, tempId);
|
||||
|
||||
var notification = buildDownloadNotification(track, tempId);
|
||||
downloadM3U8(track, downloadPath, new Callback() {
|
||||
@Override
|
||||
public void onProgress(int progress) {
|
||||
notification.setProgress(100, progress, false);
|
||||
notificationManager.notify(tempId, notification.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
try {
|
||||
var fileName = track.toString();
|
||||
var success = FFMpeg.convert(downloadPath, musicPath + File.separator + fileName + ".mp3");
|
||||
if (success) {
|
||||
notification
|
||||
.setContentText(AndroidUtils.getString("player_download_finished"))
|
||||
.setProgress(0, 0, false)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download_done);
|
||||
notificationManager.notify(tempId, notification.build());
|
||||
} else {
|
||||
onFailure();
|
||||
}
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
Log.e("AudioDownloader", "native libs");
|
||||
Log.e("AudioDownloader", e.getMessage());
|
||||
onFailure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
notification.setContentText(AndroidUtils.getString("load_audio_error")).setProgress(0, 0, false);
|
||||
notificationManager.notify(tempId, notification.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSizeReceived(long size, long header) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void downloadM3U8(MusicTrack track, String path, Callback callback) {
|
||||
File outDir = new File(path);
|
||||
if (!outDir.exists())
|
||||
if (outDir.mkdir())
|
||||
Log.v("AudioDownloader", "Directory created");
|
||||
else
|
||||
Log.e("AudioDownloader", "Directory creation failed");
|
||||
Log.i("AudioDownloader", "Downloading audio to " + path);
|
||||
M3UDownloader.execute(track.D, outDir, callback);
|
||||
}
|
||||
|
||||
private static void downloadMP3(MusicTrack track) {
|
||||
MP3Downloader.execute(track);
|
||||
}
|
||||
|
||||
private static NotificationCompat.Builder buildDownloadNotification(MusicTrack track, int id) {
|
||||
var notificationBuilder = new NotificationCompat.Builder(AndroidUtils.getGlobalContext(), NotificationChannels.MUSIC_DOWNLOAD_CHANNEL_ID)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
.setContentTitle(AndroidUtils.getString("audio_downloading"))
|
||||
.setContentText(track.toString())
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||
.setAutoCancel(true);
|
||||
notificationBuilder.setProgress(100, 0, false);
|
||||
notificationManager.notify(id, notificationBuilder.build());
|
||||
return notificationBuilder;
|
||||
if (cache) {
|
||||
TrackDownloader.cacheTrack(track, MusicCallbackBuilder.buildOneTrackCallback(tempId, notification));
|
||||
} else {
|
||||
TrackDownloader.downloadTrack(track, downloadPath, MusicCallbackBuilder.buildOneTrackCallback(tempId, notification));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ 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 static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
|
||||
import android.util.SparseArray;
|
||||
import android.widget.Toast;
|
||||
@@ -33,6 +35,8 @@ public class MessagesDownloader{
|
||||
|
||||
private static SparseArray<MiniUser> usersArray;
|
||||
|
||||
private static final String VK_DOMAIN = "vk.com";
|
||||
|
||||
public static String formatTime(long now){
|
||||
return sdformat.format(new Date(now));
|
||||
}
|
||||
@@ -66,7 +70,7 @@ public class MessagesDownloader{
|
||||
}
|
||||
fos.write(format.provideDocumentEnd().getBytes(StandardCharsets.UTF_8));
|
||||
fos.close();
|
||||
Toast.makeText(getGlobalContext(), "Сохранено как " + out.getAbsolutePath(), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getGlobalContext(), getString("saved_as") + " " + out.getAbsolutePath(), Toast.LENGTH_SHORT).show();
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -264,10 +268,17 @@ public class MessagesDownloader{
|
||||
".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>Экспорт из VTLite</title><style>" + style + "</style></head><body>";
|
||||
return "<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><meta charset=\"utf-8\"><title>" + getString("chat_export_title") + "</title><style>" + style + "</style></head><body>";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -277,12 +288,13 @@ public class MessagesDownloader{
|
||||
|
||||
@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\">Экспорт истории чата (" + date + ")</h5></div><div class=\"vtex-milk-msgcont\">";
|
||||
return "<div class=\"vtex-milk-header\"><h4 class=\"vtex-milk-header-txt\">VTLite</h4><h5 class=\"vtex-milk-header-sub\">" + getString("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");
|
||||
@@ -295,14 +307,15 @@ public class MessagesDownloader{
|
||||
"</a>";
|
||||
}
|
||||
}
|
||||
|
||||
String chatAction = (message.chat_action != null) ? getHtmlForChatAction(message.chat_action) : "";
|
||||
String attaches = (message.attachments.size() > 0) ? "<p class=\"msg-attaches\">Вложения: " + getHtmlForAttach(message.attachments) + "</p>" : "";
|
||||
String attaches = (message.attachments.size() > 0) ? "<p class=\"msg-attaches\">" + getString("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\">от <a href=\"https://vk.ru/" + userLink + "\">" + user.firstName + " " + user.lastName + "</a> <span class=\"msg-from-date\">" + formatTime(message.date) + "</span></p>" + // TODO photo100
|
||||
"<p class=\"msg-from\">" + getString("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 +
|
||||
@@ -325,12 +338,12 @@ public class MessagesDownloader{
|
||||
if (fwdMessages != null) {
|
||||
var length = fwdMessages.length();
|
||||
if (length > 0) text = length + " " + pluralMsg(length);
|
||||
} else text = "Вложение";
|
||||
} else text = getString("attachment"); // Вложение
|
||||
}
|
||||
|
||||
return "<a href=\"#" + messageId + "\" class=\"msg-attach-link\">" +
|
||||
"<div class=\"msg-reply\">" +
|
||||
"<p class=\"reply-header\">Пересланное сообщение</p>" +
|
||||
"<p class=\"reply-header\">" + getString("vkim_msg_fwd_single") + "</p>" +
|
||||
"<p class=\"reply-content\">" + user.firstName + " " + user.lastName + ": " + text + "</p>" +
|
||||
"</div>" +
|
||||
"</a>";
|
||||
@@ -371,7 +384,7 @@ public class MessagesDownloader{
|
||||
|
||||
JSONObject reply_message = fwd_message.optJSONObject("reply_message");
|
||||
|
||||
var attachesHtml = (attaches.size() > 0) ? "Вложения: " + getHtmlForAttach(attaches) : "";
|
||||
var attachesHtml = (attaches.size() > 0) ? getString("attachments") + ": " + getHtmlForAttach(attaches) : "";
|
||||
var replyHtml = (reply_message != null) ? provideReply(reply_message) : "";
|
||||
var fwdsHtml = (fwdsMsg.size() > 0) ? provideForwardMessages(fwdsMsg) : ""; // recursion XD :>
|
||||
|
||||
@@ -381,7 +394,7 @@ public class MessagesDownloader{
|
||||
|
||||
var userLink = ((userId < 0) ? "club" : "id") + Math.abs(userId);
|
||||
|
||||
fwdmsgs.append("<p class=\"reply-content\"><a class=\"msg-attach-link\" href=\"https://vk.ru/").append(userLink).append("\">@").append(userLink).append("</a>: ").append(text).append(attachesHtml).append(replyHtml).append(fwdsHtml);
|
||||
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();
|
||||
@@ -390,11 +403,11 @@ public class MessagesDownloader{
|
||||
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.ru/$1\">$2</a>");
|
||||
return matcher.replaceAll("<a class=\"msg-attach-link\" href=\"https://" + VK_DOMAIN + "/$1\">$2</a>");
|
||||
}
|
||||
|
||||
private String pluralMsg(int count) {
|
||||
String[] plurals = {"сообщение", "сообщения", "сообщений"};
|
||||
String[] plurals = getArray("msg_plurals");
|
||||
|
||||
var hundredModulo = count % 100;
|
||||
var tenModulo = count % 10;
|
||||
@@ -413,70 +426,59 @@ public class MessagesDownloader{
|
||||
|
||||
switch(type) {
|
||||
case "chat_photo_update":
|
||||
htmlAction.append("Обновил фотографию беседы");
|
||||
htmlAction.append(getString("chat_export_avatar_update"));
|
||||
break;
|
||||
case "chat_photo_remove":
|
||||
htmlAction.append("Удалил фотографию беседы");
|
||||
htmlAction.append(getString("chat_export_avatar_remove"));
|
||||
break;
|
||||
case "chat_create":
|
||||
var name = action.optString("text");
|
||||
htmlAction.append("Создал беседу").append((!name.isEmpty()) ? " с названием \"" + name + "\"" : "");
|
||||
htmlAction.append(getString("chat_export_chat_created")).append((!name.isEmpty()) ? " \"" + name + "\"" : "");
|
||||
break;
|
||||
case "chat_title_update":
|
||||
var newName = action.optString("text");
|
||||
htmlAction.append("Сменил название беседы").append((!newName.isEmpty()) ? " на \"" + newName : "\"");
|
||||
htmlAction.append(getString("chat_export_name_changed")).append((!newName.isEmpty()) ? (" " + getString("chat_export_to") + " \"" + newName + "\"") : "");
|
||||
break;
|
||||
case "chat_invite_user":
|
||||
var newUserId = action.optInt("member_id");
|
||||
htmlAction.append("Добавил ").append((newUserId > 0) ? "пользователя" : "группу");
|
||||
htmlAction.append(getString("chat_export_user_added") + " ").append((newUserId > 0) ? getString("chat_export_type_user") : getString("chat_export_type_group"));
|
||||
if (newUserId != 0) {
|
||||
var userLink = ((newUserId < 0) ? "club" : "id") + Math.abs(newUserId);
|
||||
htmlAction.append(" <a href=\"https://vk.ru/").append(userLink).append("\" class=\"msg-attach-link\">@").append(userLink).append("</a>");
|
||||
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("Исключил ").append((removedUserId > 0) ? "пользователя" : "группу");
|
||||
htmlAction.append(getString("chat_export_user_kicked") + " ").append((removedUserId > 0) ? getString("chat_export_type_user") : getString("chat_export_type_group"));
|
||||
if (removedUserId != 0) {
|
||||
var userLink = ((removedUserId < 0) ? "club" : "id") + Math.abs(removedUserId);
|
||||
htmlAction.append(" <a href=\"https://vk.ru/").append(userLink).append("\" class=\"msg-attach-link\">@").append(userLink).append("</a>");
|
||||
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("Закрепил сообщение").append((!message.isEmpty()) ? (" с текстом: \"" + message + "\"") : "");
|
||||
htmlAction.append(getString("chat_export_msg_pinned")).append((!message.isEmpty()) ? (" \"" + message + "\"") : "");
|
||||
break;
|
||||
case "chat_unpin_message":
|
||||
htmlAction.append("Открепил сообщение");
|
||||
htmlAction.append(getString("chat_export_msg_unpinned"));
|
||||
break;
|
||||
case "chat_invite_user_by_link":
|
||||
htmlAction.append("Вступил в беседу по ссылке");
|
||||
htmlAction.append(getString("chat_export_join_by_link"));
|
||||
break;
|
||||
case "chat_screenshot":
|
||||
htmlAction.append("Сделал скриншот беседы");
|
||||
htmlAction.append(getString("chat_export_chat_screenshot"));
|
||||
break;
|
||||
case "custom":
|
||||
htmlAction.append(action.optString("message"));
|
||||
break;
|
||||
default:
|
||||
htmlAction.append("Действие не поддерживается (").append(type).append(")");
|
||||
htmlAction.append(getString("vkim_msg_unsupported") + " (").append(type).append(")");
|
||||
break;
|
||||
}
|
||||
|
||||
return htmlAction.append("</p>").toString();
|
||||
}
|
||||
|
||||
/*
|
||||
TODO:
|
||||
1) poll (опросы)
|
||||
2) mini_app (поделиться миниаппом)
|
||||
3) audio_playlist (плейлист песен)
|
||||
4) story (история)
|
||||
5) wall_reply (комментарий на стене)
|
||||
6) podcast (подкаст)
|
||||
7) gift (подарок)
|
||||
*/
|
||||
|
||||
private String getHtmlForAttach(List<JSONObject> attaches) throws JSONException{
|
||||
StringBuilder rs = new StringBuilder();
|
||||
|
||||
@@ -486,34 +488,71 @@ public class MessagesDownloader{
|
||||
|
||||
if (item == null) continue;
|
||||
|
||||
switch(type) {
|
||||
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\">фотография</a>");
|
||||
rs.append("<a href=\"").append(sizes.getJSONObject(sizes.length() - 1).getString("url")).append("\" class=\"msg-attach-link\">").append(getString("chat_export_type_photo")).append("</a>");
|
||||
break;
|
||||
case "doc":
|
||||
rs.append("<a href=\"").append(item.getString("url")).append("\" class=\"msg-attach-link\">документ</a>");
|
||||
rs.append("<a href=\"").append(item.getString("url")).append("\" class=\"msg-attach-link\">").append(getString("chat_export_type_doc")).append("</a>");
|
||||
break;
|
||||
case "link":
|
||||
rs.append("<a href=\"").append(item.getString("url")).append("\" class=\"msg-attach-link\">ссылка</a>");
|
||||
rs.append("<a href=\"").append(item.getString("url")).append("\" class=\"msg-attach-link\">").append(getString("chat_export_type_link")).append("</a>");
|
||||
break;
|
||||
case "wall":
|
||||
rs.append("<a href=\"https://vk.ru/wall").append(item.optString("to_id", item.optString("owner_id"))).append("_").append(item.getString("id")).append("\" class=\"msg-attach-link\">запись на стене</a>");
|
||||
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(getString("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\">голосовое сообщение</a>");
|
||||
rs.append("<a href=\"").append(item.optString("link_mp3")).append("\" class=\"msg-attach-link\">").append(getString("chat_export_type_audiomsg")).append("</a>");
|
||||
break;
|
||||
case "audio":
|
||||
rs.append("аудиозапись (").append(item.optString("artist")).append(" — ").append(item.optString("title")).append(")");
|
||||
rs.append(getString("chat_export_type_audio")).append(" (").append(item.optString("artist")).append(" — ").append(item.optString("title")).append(")");
|
||||
break;
|
||||
case "video":
|
||||
rs.append("видеозапись ( ").append(getVideoHtml(item.optJSONObject("files"))).append(")");
|
||||
rs.append(getString("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(getString("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(getString("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(getString("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(getString("chat_export_type_miniapp")).append("</a>");
|
||||
break;
|
||||
}
|
||||
|
||||
rs.append(getString("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(getString("chat_export_type_playlist")).append(" (").append(item.optString("title")).append(")</a>");
|
||||
break;
|
||||
case "poll":
|
||||
rs.append(getString(item.optBoolean("anonymous") ? "chat_export_poll_anon" : "chat_export_poll_publ")).append(" ").append(getString("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(getString("chat_export_type_market")).append("</a>");
|
||||
break;
|
||||
default:
|
||||
rs.append("не поддерживается (").append(type).append(")");
|
||||
rs.append(getString("vkim_msg_unsupported")).append(" (").append(type).append(")");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -524,9 +563,27 @@ public class MessagesDownloader{
|
||||
}
|
||||
}
|
||||
|
||||
private static String getVideoHtml(JSONObject files) throws JSONException {
|
||||
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>"
|
||||
);
|
||||
|
||||
if (files == null) return "ссылки отсутствуют";
|
||||
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(getString("chat_export_poll_voted")).append(" ").append(poll.optString("votes")).append(" ").append(getString("chat_export_users_name")).append("</p>");
|
||||
|
||||
return pollHtml.append("</div>").toString();
|
||||
}
|
||||
|
||||
private static String getVideoHtml(JSONObject files) throws JSONException {
|
||||
if (files == null) return getString("chat_export_video_nolinks");
|
||||
|
||||
Iterator< ? > keys = files.keys();
|
||||
StringBuilder videoHtml = new StringBuilder();
|
||||
@@ -539,7 +596,7 @@ public class MessagesDownloader{
|
||||
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 == 7) break;
|
||||
if (qualityIndex == quality.length - 1) break;
|
||||
++qualityIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package ru.vtosters.lite.downloaders;
|
||||
|
||||
import static ru.vtosters.lite.downloaders.VideoDownloader.downloadVideo;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.Preferences.getPhotosDir;
|
||||
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
@@ -12,7 +11,6 @@ import android.os.Environment;
|
||||
import com.vk.dto.common.ImageSize;
|
||||
import com.vk.dto.stories.model.StoryEntry;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class StoryDownloader {
|
||||
@@ -25,7 +23,7 @@ public class StoryDownloader {
|
||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setTitle("photo" + story.E.a + ".jpg");
|
||||
request.setDestinationInExternalPublicDir(getPhotosDir().getName(), "photo" + story.E.a + ".jpg");
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, "photo" + story.E.a + ".jpg");
|
||||
request.allowScanningByMediaScanner();
|
||||
((DownloadManager) getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
|
||||
return;
|
||||
|
||||
@@ -6,9 +6,7 @@ import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
import static ru.vtosters.lite.utils.Preferences.getVideosDir;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.DownloadManager;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
@@ -109,7 +107,7 @@ public class VideoDownloader {
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setTitle(videoFile.toString());
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setDestinationInExternalPublicDir(getVideosDir().getName(), videoFile + ".mp4");
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_MOVIES, videoFile + ".mp4");
|
||||
((DownloadManager) getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
|
||||
return;
|
||||
}
|
||||
@@ -121,19 +119,19 @@ public class VideoDownloader {
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setTitle(videoFile.toString());
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setDestinationInExternalPublicDir(getVideosDir().getName(), videoFile + ".mp4");
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_MOVIES, videoFile + ".mp4");
|
||||
((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
|
||||
}));
|
||||
builder.show();
|
||||
}
|
||||
|
||||
public static void parseVideoLink(String url, Context ctx) {
|
||||
if (url.contains("vk.ru/story") || url.contains("vk.com/story")) {
|
||||
if (url.contains("vk.com/story") || url.contains("vk.com/story")) {
|
||||
ToastUtils.a(AndroidUtils.getString("video_dl_stories_not_supported"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!url.contains("vk.ru/video") || !url.contains("vk.com/video")) {
|
||||
if (!url.contains("vk.com/video") || !url.contains("vk.com/video")) {
|
||||
ToastUtils.a(AndroidUtils.getString("video_dl_wrong_link"));
|
||||
return;
|
||||
}
|
||||
|
||||
+29
-2
@@ -1,5 +1,7 @@
|
||||
package ru.vtosters.lite.downloaders.notifications;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
@@ -12,12 +14,21 @@ import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class NotificationChannels {
|
||||
public static final String MUSIC_DOWNLOAD_CHANNEL_ID = "music_download_channel";
|
||||
public static final String MUSIC_DOWNLOAD_CHANNEL_NAME = AndroidUtils.getString("music_dl_title");
|
||||
public static final String MUSIC_DOWNLOAD_CHANNEL_DESCRIPTION = AndroidUtils.getString("music_dl_progress");
|
||||
public static final String MUSIC_DOWNLOAD_CHANNEL_NAME = getString("music_downloading");
|
||||
public static final String MUSIC_DOWNLOAD_CHANNEL_DESCRIPTION = getString("music_downloading_progress");
|
||||
|
||||
public static final String MUSIC_PLAYLIST_DOWNLOAD_CHANNEL_ID = "music_playlist_download_channel";
|
||||
public static final String MUSIC_PLAYLIST_DOWNLOAD_CHANNEL_NAME = getString("playlist_downloading");
|
||||
public static final String MUSIC_PLAYLIST_DOWNLOAD_CHANNEL_DESCRIPTION = getString("playlist_downloading_progress");
|
||||
|
||||
public static final String MUSIC_CACHING_NAME = getString("caching_track_or_pic");
|
||||
|
||||
private static NotificationManagerCompat notificationManagerCompat;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
public static void createChannels() {
|
||||
createMusicDownloadChannel();
|
||||
createMusicPlaylistDownloadChannel();
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
@@ -29,4 +40,20 @@ public class NotificationChannels {
|
||||
var notificationManager = NotificationManagerCompat.from(AndroidUtils.getGlobalContext());
|
||||
notificationManager.createNotificationChannel(musicDownloadChannel);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
public static void createMusicPlaylistDownloadChannel() {
|
||||
var musicDownloadChannel = new NotificationChannel(MUSIC_PLAYLIST_DOWNLOAD_CHANNEL_ID, MUSIC_PLAYLIST_DOWNLOAD_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
|
||||
musicDownloadChannel.setDescription(MUSIC_PLAYLIST_DOWNLOAD_CHANNEL_DESCRIPTION);
|
||||
musicDownloadChannel.setShowBadge(true);
|
||||
musicDownloadChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
var notificationManager = NotificationManagerCompat.from(AndroidUtils.getGlobalContext());
|
||||
notificationManager.createNotificationChannel(musicDownloadChannel);
|
||||
}
|
||||
|
||||
public static NotificationManagerCompat getNotificationManager() {
|
||||
if (notificationManagerCompat == null)
|
||||
notificationManagerCompat = NotificationManagerCompat.from(AndroidUtils.getGlobalContext());
|
||||
return notificationManagerCompat;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package ru.vtosters.lite.feature.discover;
|
||||
|
||||
import com.vk.dto.discover.DiscoverItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DiscoverTemplates {
|
||||
public static ArrayList<String> getTemplates() {
|
||||
var templates = DiscoverItem.Template.values();
|
||||
var arrayList = new ArrayList<String>();
|
||||
|
||||
for (var template : templates) {
|
||||
if (template != DiscoverItem.Template.GRID_MEDIA) {
|
||||
arrayList.add(template.b());
|
||||
}
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package ru.vtosters.lite.feature.music;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.vk.music.fragment.MusicFragment;
|
||||
|
||||
public class MusicArtistSelectorHook {
|
||||
public static void navigateToSearch(Context context, String artist) {
|
||||
var fr = new MusicFragment.f();
|
||||
fr.a(artist);
|
||||
|
||||
// navigate
|
||||
fr.a(context);
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,17 @@ package ru.vtosters.lite.foaf;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static android.widget.Toast.makeText;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isAnyProxyEnabled;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isApiProxyEnabled;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.exifinterface.media.ExifInterface;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.core.network.Network;
|
||||
|
||||
@@ -35,7 +33,6 @@ import java.util.regex.Pattern;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import ru.vtosters.lite.net.Request;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
|
||||
public class FoafBase {
|
||||
private static final Pattern FOAF_REGEX = Pattern.compile("<ya:created dc:date=\"(.+?)\"\\/>");
|
||||
@@ -115,12 +112,12 @@ public class FoafBase {
|
||||
private static String getLink(int i) {
|
||||
String str;
|
||||
StringBuilder sb;
|
||||
if (isApiProxyEnabled()) {
|
||||
if (isAnyProxyEnabled()) {
|
||||
sb = new StringBuilder();
|
||||
str = "https://" + getApi() + "/_/vk.ru/foaf.php?id=";
|
||||
str = "https://" + getApi() + "/_/vk.com/foaf.php?id=";
|
||||
} else {
|
||||
sb = new StringBuilder();
|
||||
str = "https://vk.ru/foaf.php?id=";
|
||||
str = "https://vk.com/foaf.php?id=";
|
||||
}
|
||||
sb.append(str);
|
||||
sb.append(i);
|
||||
@@ -166,7 +163,7 @@ public class FoafBase {
|
||||
}
|
||||
|
||||
private static String getNormalHumanDate(String str) {
|
||||
String[] split = str.split(ExifInterface.GPS_DIRECTION_TRUE);
|
||||
String[] split = str.split("T");
|
||||
return split[1].split("\\+")[0] + " " + split[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,358 @@
|
||||
package ru.vtosters.lite.hooks;
|
||||
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.checkCaption;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.checkCopyright;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isBadNews;
|
||||
import static ru.vtosters.lite.utils.Preferences.ads;
|
||||
import static ru.vtosters.lite.utils.Preferences.adsgroup;
|
||||
import static ru.vtosters.lite.utils.Preferences.adsstories;
|
||||
import static ru.vtosters.lite.utils.Preferences.authorsrecomm;
|
||||
import static ru.vtosters.lite.utils.Preferences.dev;
|
||||
import static ru.vtosters.lite.utils.Preferences.friendsrecomm;
|
||||
import static ru.vtosters.lite.utils.Preferences.postsrecomm;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.NewsFeedFiltersUtils;
|
||||
|
||||
public class AdBlockHook {
|
||||
public static Boolean discoverAdBlock(JSONObject jsonObject) {
|
||||
if (jsonObject == null) return true;
|
||||
|
||||
try {
|
||||
var type = jsonObject.optString("type");
|
||||
var post = jsonObject.optJSONObject("post");
|
||||
|
||||
if (jsonObject.optString("template").contains("ads") || jsonObject.has("ads")) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: ads");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isAds(post, type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (authorsrecomm() && (type.equals("authors_rec")
|
||||
|| type.startsWith("recommended_") && (type.endsWith("audios")
|
||||
|| type.endsWith("artists")
|
||||
|| type.endsWith("playlists")
|
||||
|| type.endsWith("groups")))) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: authorsrecomm");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (postsrecomm() && (type.equals("inline_user_rec") || type.equals("live_recommended"))) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: postsrecomm");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (friendsrecomm() && (type.equals("user_rec") || type.equals("friends_recomm"))) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + (post != null ? post.optInt("post_id") : 0) + " from discover, Reason: friendsrecomm");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (adsgroup() && (post != null ? post.optInt("marked_as_ads") : 0) == 1 && !isWhitelistedAd(post)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: marked_as_ads is true");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (post != null) {
|
||||
if (isBadNews(post.optString("text")) && !isWhitelistedFilters(post)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: text filters");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (checkCopyright(post) && !isWhitelistedFilters(post)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: copyright filters");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (checkCaption(post) && !isWhitelistedFilters(post)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: caption filters");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NewsFeedFiltersUtils.injectFiltersReposts(post) && !isWhitelistedFilters(post)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + post.optInt("post_id") + " from discover, Reason: repost ad");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d("NewsfeedAdBlockV2", "discover: " + e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static JSONObject discoverInject(JSONObject json) throws JSONException {
|
||||
var items = json.optJSONArray("items");
|
||||
var newObj = new JSONArray();
|
||||
|
||||
// newObj.put(discoverObj()); // template injection
|
||||
|
||||
for (int i = 0; i < (items != null ? items.length() : 0); i++) {
|
||||
try {
|
||||
var curr = items.getJSONObject(i);
|
||||
if (!curr.optString("template").contains("info") && discoverAdBlock(curr)) {
|
||||
newObj.put(items.optJSONObject(i));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d("NewsfeedAdBlockV2", "discover: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
json.put("items", newObj);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSONObject discoverObj() throws JSONException {
|
||||
var mainjson = new JSONObject();
|
||||
|
||||
var info = new JSONObject();
|
||||
info.put("title", "Test Injection");
|
||||
info.put("text_color", "#ffffff");
|
||||
info.put("description", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat");
|
||||
|
||||
var image = new JSONArray();
|
||||
var imageQuality1 = new JSONObject();
|
||||
imageQuality1.put("url", "https://w7.pngwing.com/pngs/505/1021/png-transparent-konata-izumi-lucky-star-desktop-anime-anime-blue-mammal-face.png");
|
||||
imageQuality1.put("width", 72); // 72, 108, 144, 216, 288
|
||||
imageQuality1.put("height", 72); // 72, 108, 144, 216, 288
|
||||
image.put(imageQuality1);
|
||||
|
||||
var background = new JSONArray();
|
||||
var backgroundQuality1 = new JSONObject();
|
||||
backgroundQuality1.put("url", "https://2ch.life/vg/arch/2022-08-22/src/38524739/16440606579870.jpg");
|
||||
backgroundQuality1.put("width", 344); // 344, 516, 680, 1032, 1376
|
||||
backgroundQuality1.put("height", 215); // 215, 323, 426, 645, 860
|
||||
background.put(backgroundQuality1);
|
||||
|
||||
info.put("image", image);
|
||||
info.put("background", background);
|
||||
|
||||
mainjson.put("info", info);
|
||||
mainjson.put("track_code", "info_banner_donut_catalog");
|
||||
mainjson.put("template", "info");
|
||||
|
||||
var action = new JSONObject();
|
||||
action.put("type", "open_url");
|
||||
action.put("url", "vk.com/vtosters_official");
|
||||
action.put("target", "internal");
|
||||
|
||||
mainjson.put("action", action);
|
||||
|
||||
return mainjson;
|
||||
}
|
||||
|
||||
public static JSONArray feedInject(JSONArray items) {
|
||||
if (items.length() == 0) return items;
|
||||
|
||||
try {
|
||||
var newItems = new JSONArray();
|
||||
|
||||
for (int j = 0; j < items.length(); j++) {
|
||||
var list = items.optJSONObject(j);
|
||||
|
||||
if (list == null) continue;
|
||||
|
||||
var type = list.optString("type");
|
||||
|
||||
if (isAds(list, type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (authorsrecomm() && (type.equals("authors_rec")
|
||||
|| type.startsWith("recommended_") && (type.endsWith("audios")
|
||||
|| type.endsWith("artists")
|
||||
|| type.endsWith("playlists")
|
||||
|| type.endsWith("groups")))) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: authorsrecomm");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (postsrecomm() && (type.equals("inline_user_rec") || type.equals("live_recommended"))) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: postsrecomm");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (friendsrecomm() && (type.equals("user_rec") || type.equals("friends_recomm"))) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: friendsrecomm");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (adsgroup() && list.optInt("marked_as_ads") == 1 && !isWhitelistedAd(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: marked_as_ads is true");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isBadNews(list.optString("text")) && !isWhitelistedFilters(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: text filters");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (checkCopyright(list) && !isWhitelistedFilters(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: copyright filters");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (checkCaption(list) && !isWhitelistedFilters(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: caption filters");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NewsFeedFiltersUtils.injectFiltersReposts(list) && !isWhitelistedFilters(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: repost ad");
|
||||
continue;
|
||||
}
|
||||
|
||||
newItems.put(list);
|
||||
}
|
||||
|
||||
return newItems;
|
||||
} catch (Exception e) {
|
||||
Log.d("NewsfeedAdBlockV2", e.getMessage());
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
public static JSONObject storiesads(JSONObject json, boolean isDeleteFix) throws JSONException {
|
||||
if (!adsstories()) {
|
||||
return json;
|
||||
}
|
||||
|
||||
if (json.has("ads")) {
|
||||
var ad = json.optJSONObject("ads");
|
||||
if (isDeleteFix) {
|
||||
if (ad != null) {
|
||||
ad.optJSONObject("settings")
|
||||
.put("stories_interval", 0)
|
||||
.put("authors_interval", 0)
|
||||
.put("time_interval", 0)
|
||||
.put("stories_init", 0)
|
||||
.put("authors_init", 0)
|
||||
.put("time_init", 0);
|
||||
}
|
||||
if (dev()) Log.d("StoriesAds", "Set ads settings at zero values");
|
||||
} else {
|
||||
json.remove("ads");
|
||||
if (dev()) Log.d("StoriesAds", "Removed ads block");
|
||||
}
|
||||
}
|
||||
|
||||
if (!json.has("items")) return json;
|
||||
|
||||
var items = json.optJSONArray("items");
|
||||
if (items != null) {
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
var item = items.optJSONObject(i);
|
||||
if (item != null) {
|
||||
parseStoriesItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
private static void parseStoriesItem(JSONObject item) throws JSONException {
|
||||
var stories = item.optJSONArray("stories");
|
||||
var newStories = new JSONArray();
|
||||
|
||||
if (stories == null) return;
|
||||
|
||||
for (int j = 0; j < stories.length(); j++) {
|
||||
var story = stories.optJSONObject(j);
|
||||
|
||||
if (!story.optBoolean("is_ads") && !story.optBoolean("is_promo")) {
|
||||
newStories.put(story);
|
||||
} else {
|
||||
if (dev())
|
||||
Log.d("StoriesAds", "Fetched ad, owner id " + story.optString("owner_id") + ", caption " + story.optString("caption"));
|
||||
}
|
||||
}
|
||||
|
||||
item.put("stories", newStories);
|
||||
}
|
||||
|
||||
public static Boolean isAds(JSONObject list, String type) throws JSONException {
|
||||
if (list == null || type == null || !ads()) return false;
|
||||
|
||||
if (list.has("ads")
|
||||
|| type.equals("ads")
|
||||
|| type.equals("carousel")
|
||||
|| type.equals("html5_ad")
|
||||
|| type.equals("ads_easy_promote")) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: ads");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type.equals("promo_button")
|
||||
|| type.equals("app_widget")
|
||||
|| type.equals("app_video")
|
||||
|| type.equals("app_slider")
|
||||
|| type.equals("tags_suggestions")) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: promo");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Boolean isWhitelistedFilters(JSONObject list) {
|
||||
var id = String.valueOf(list.optInt("owner_id"));
|
||||
|
||||
if (id.equals("0")) {
|
||||
id = String.valueOf(list.optInt("source_id"));
|
||||
}
|
||||
|
||||
if (id.equals("-189659924")){
|
||||
return true;
|
||||
}
|
||||
|
||||
var whitelist = AndroidUtils.getDefaultPrefs().getStringSet("whitelisted_filters_groups", Collections.synchronizedSet(new LinkedHashSet<>()));
|
||||
|
||||
return whitelist.contains(id);
|
||||
}
|
||||
|
||||
public static Boolean isWhitelistedAd(JSONObject list) {
|
||||
var id = String.valueOf(list.optInt("owner_id"));
|
||||
|
||||
if (id.equals("0")) {
|
||||
id = String.valueOf(list.optInt("source_id"));
|
||||
}
|
||||
|
||||
var whitelist = AndroidUtils.getDefaultPrefs().getStringSet("whitelisted_ad_groups", Collections.synchronizedSet(new LinkedHashSet<>()));
|
||||
|
||||
return whitelist.contains(id);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import static ru.vtosters.lite.utils.LifecycleUtils.getCurrentActivity;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAlertStyle;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getSTextAttr;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.text.Editable;
|
||||
@@ -57,7 +58,14 @@ public class CryptImHook{
|
||||
}
|
||||
|
||||
IMProcessor finalEnabled = enabled;
|
||||
new VkAlertDialog.Builder(getCurrentActivity())
|
||||
Activity ctx = getCurrentActivity();
|
||||
|
||||
if (ctx == null) {
|
||||
sendToast(getString("app_activities_error"));
|
||||
return;
|
||||
}
|
||||
|
||||
new VkAlertDialog.Builder(ctx)
|
||||
.setTitle(getString("encryption_sett"))
|
||||
.setSingleChoiceItems(titles, enabledPosition, (dialog, which) -> {
|
||||
if (which == 0) {
|
||||
@@ -103,6 +111,11 @@ public class CryptImHook{
|
||||
|
||||
Context ctx = getCurrentActivity();
|
||||
|
||||
if (ctx == null) {
|
||||
sendToast(getString("app_activities_error"));
|
||||
return;
|
||||
}
|
||||
|
||||
LinearLayout linearLayout = new LinearLayout(ctx);
|
||||
|
||||
final EditText editText = new EditText(ctx);
|
||||
|
||||
@@ -4,13 +4,10 @@ import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class DeviceInfoHook{
|
||||
public static String getDeviceInfo(String input) {
|
||||
Log.d("DeviceInfoHook", "getDeviceInfo: " + input);
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.vk.core.fragments.FragmentImpl;
|
||||
import com.vk.core.util.StringUtils;
|
||||
import com.vk.navigation.right.RightMenu;
|
||||
import com.vtosters.lite.MenuCountersState;
|
||||
import com.vtosters.lite.fragments.ProfileFragment;
|
||||
import com.vtosters.lite.ui.bottomnavigation.BottomNavigationMenuView;
|
||||
import com.vtosters.lite.ui.bottomnavigation.BottomNavigationView;
|
||||
|
||||
@@ -209,7 +208,6 @@ public class DockBarInjector {
|
||||
val = MenuCountersState.n();
|
||||
break;
|
||||
case tab_feedback:
|
||||
case tab_news:
|
||||
if (milkshake())
|
||||
val = MenuCountersState.k();
|
||||
break;
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
package ru.vtosters.lite.hooks;
|
||||
|
||||
import static ru.vtosters.lite.foaf.FoafBase.getBypassedOnlineInfo;
|
||||
import static ru.vtosters.lite.hooks.OnlineFormatterHook.onlineHookProfiles;
|
||||
import static ru.vtosters.lite.hooks.DateHook.getLocale;
|
||||
import static ru.vtosters.lite.hooks.OnlineFormatterHook.onlineHookProfiles;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getStatic;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.checkCaption;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.checkCopyright;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isBadNews;
|
||||
import static ru.vtosters.lite.utils.Preferences.ads;
|
||||
import static ru.vtosters.lite.utils.Preferences.adsgroup;
|
||||
import static ru.vtosters.lite.utils.Preferences.adsstories;
|
||||
import static ru.vtosters.lite.utils.Preferences.authorsrecomm;
|
||||
import static ru.vtosters.lite.utils.Preferences.dev;
|
||||
import static ru.vtosters.lite.utils.Preferences.friendsblock;
|
||||
import static ru.vtosters.lite.utils.Preferences.friendsrecomm;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.hasVerification;
|
||||
import static ru.vtosters.lite.utils.Preferences.podcastcatalog;
|
||||
import static ru.vtosters.lite.utils.Preferences.postsrecomm;
|
||||
import static ru.vtosters.lite.utils.VTVerifications.isDeveloper;
|
||||
import static ru.vtosters.lite.utils.VTVerifications.isPrometheus;
|
||||
import static ru.vtosters.lite.utils.VTVerifications.isVerified;
|
||||
@@ -47,7 +38,6 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.NewsFeedFiltersUtils;
|
||||
|
||||
public class JsonInjectors {
|
||||
private static final OkHttpClient mClient = new OkHttpClient();
|
||||
@@ -76,7 +66,7 @@ public class JsonInjectors {
|
||||
|
||||
public static JSONObject donateRecomm() throws JSONException {
|
||||
var title = AndroidUtils.getString("donate_to_vtl");
|
||||
var link = "https://vk.ru/vtosters_official";
|
||||
var link = "https://vk.com/vtosters_official";
|
||||
var text_color = "2D81E0";
|
||||
|
||||
var json = new JSONObject();
|
||||
@@ -246,30 +236,12 @@ public class JsonInjectors {
|
||||
}
|
||||
|
||||
public static JSONObject musiclink(JSONObject json) {
|
||||
var oldItems = json.optJSONArray("links");
|
||||
var section = json.optJSONObject("section");
|
||||
var linksblock = section.optJSONArray("blocks");
|
||||
var newBlock = new JSONArray();
|
||||
var links = json.optJSONArray("links");
|
||||
|
||||
if (oldItems != null) {
|
||||
if (oldItems.optJSONObject(0).optString("url").contains("?section=recent")) {
|
||||
if (links != null) {
|
||||
if (links.optJSONObject(0).optString("url").contains("?section=recent")) {
|
||||
json.remove("links");
|
||||
|
||||
for (int i = 0; i < linksblock.length(); i++) {
|
||||
var item = linksblock.optJSONObject(i);
|
||||
var datatype = item.optString("data_type");
|
||||
var layname = item.optJSONObject("layout").optString("name");
|
||||
if (!datatype.equals("links") && !layname.equals("separator")) {
|
||||
newBlock.put(item);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
section.putOpt("blocks", newBlock);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (dev()) Log.d("VKMusic", "Removed links buttons");
|
||||
}
|
||||
}
|
||||
@@ -277,7 +249,7 @@ public class JsonInjectors {
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSONObject setOnlineInfo(JSONObject json) throws ParseException, IOException, JSONException {
|
||||
public static JSONObject setOnlineInfo(JSONObject json) throws JSONException {
|
||||
var id = json.optInt("id");
|
||||
if (id == AccountManagerUtils.getUserId()) {
|
||||
return json;
|
||||
@@ -306,7 +278,7 @@ public class JsonInjectors {
|
||||
return json;
|
||||
}
|
||||
|
||||
public static JSONArray setOnlineInfoUsers(JSONArray profiles) throws ParseException, IOException, JSONException {
|
||||
public static JSONArray setOnlineInfoUsers(JSONArray profiles) throws JSONException {
|
||||
if (profiles == null || profiles.length() == 0) return profiles;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var curVkId = AccountManagerUtils.getUserId();
|
||||
@@ -354,111 +326,6 @@ public class JsonInjectors {
|
||||
return profiles;
|
||||
}
|
||||
|
||||
|
||||
public static JSONObject storiesads(JSONObject json, boolean isDeleteFix) throws JSONException {
|
||||
if (!adsstories()) {
|
||||
return json;
|
||||
}
|
||||
|
||||
if (json.has("ads")) {
|
||||
if (isDeleteFix) {
|
||||
json.optJSONObject("ads").optJSONObject("settings")
|
||||
.put("stories_interval", 0)
|
||||
.put("authors_interval", 0)
|
||||
.put("time_interval", 0)
|
||||
.put("stories_init", 0)
|
||||
.put("authors_init", 0)
|
||||
.put("time_init", 0);
|
||||
if (dev()) Log.d("StoriesAds", "Set ads settings at zero values");
|
||||
} else {
|
||||
json.remove("ads");
|
||||
if (dev()) Log.d("StoriesAds", "Removed ads block");
|
||||
}
|
||||
}
|
||||
|
||||
if (!json.has("items")) return json;
|
||||
|
||||
var items = json.optJSONArray("items");
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
var item = items.optJSONObject(i);
|
||||
if (item != null) {
|
||||
parseStoriesItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
private static void parseStoriesItem(JSONObject item) throws JSONException {
|
||||
var stories = item.optJSONArray("stories");
|
||||
var newStories = new JSONArray();
|
||||
|
||||
if (stories == null) return;
|
||||
|
||||
for (int j = 0; j < stories.length(); j++) {
|
||||
var story = stories.optJSONObject(j);
|
||||
|
||||
if (!story.optBoolean("is_ads") && !story.optBoolean("is_promo")) {
|
||||
newStories.put(story);
|
||||
} else {
|
||||
if (dev())
|
||||
Log.d("StoriesAds", "Fetched ad, owner id " + story.optString("owner_id") + ", caption " + story.optString("caption"));
|
||||
}
|
||||
}
|
||||
|
||||
item.put("stories", newStories);
|
||||
}
|
||||
|
||||
public static Boolean isAds(JSONObject list, String type) throws JSONException {
|
||||
if (list == null || type == null || !ads()) return false;
|
||||
|
||||
if (list.has("ads")
|
||||
|| type.equals("ads")
|
||||
|| type.equals("carousel")
|
||||
|| type.equals("html5_ad")
|
||||
|| type.equals("ads_easy_promote")) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: ads");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type.equals("promo_button")
|
||||
|| type.equals("app_widget")
|
||||
|| type.equals("app_video")
|
||||
|| type.equals("app_slider")
|
||||
|| type.equals("tags_suggestions")) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: promo");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Boolean isWhitelistedFilters(JSONObject list) throws JSONException {
|
||||
var id = String.valueOf(list.optInt("owner_id"));
|
||||
|
||||
if (id.equals("0")) {
|
||||
id = String.valueOf(list.optInt("source_id"));
|
||||
}
|
||||
|
||||
var whitelist = AndroidUtils.getDefaultPrefs().getStringSet("whitelisted_filters_groups", Collections.synchronizedSet(new LinkedHashSet<>()));
|
||||
|
||||
return whitelist.contains(id);
|
||||
}
|
||||
|
||||
public static Boolean isWhitelistedAd(JSONObject list) throws JSONException {
|
||||
var id = String.valueOf(list.optInt("owner_id"));
|
||||
|
||||
if (id.equals("0")) {
|
||||
id = String.valueOf(list.optInt("source_id"));
|
||||
}
|
||||
|
||||
var whitelist = AndroidUtils.getDefaultPrefs().getStringSet("whitelisted_ad_groups", Collections.synchronizedSet(new LinkedHashSet<>()));
|
||||
|
||||
return whitelist.contains(id);
|
||||
}
|
||||
|
||||
public static JSONArray newsfeedlist(JSONArray items) throws JSONException {
|
||||
var selectedItems = getDefaultPrefs().getString("news_feed_selected_items", "");
|
||||
var filtersSet = getDefaultPrefs().getStringSet("news_feed_items_set", null);
|
||||
@@ -496,76 +363,6 @@ public class JsonInjectors {
|
||||
return items;
|
||||
}
|
||||
|
||||
public static JSONArray newsfeedadtest(JSONArray items) throws JSONException {
|
||||
if (!getBoolValue("newadblock", true)) return items;
|
||||
var newItems = new JSONArray();
|
||||
|
||||
for (int j = 0; j < items.length(); j++) {
|
||||
var list = items.optJSONObject(j);
|
||||
var type = list.optString("type");
|
||||
|
||||
if (isAds(list, type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (authorsrecomm() && (type.equals("authors_rec")
|
||||
|| type.startsWith("recommended_") && (type.endsWith("audios")
|
||||
|| type.endsWith("artists")
|
||||
|| type.endsWith("playlists")
|
||||
|| type.endsWith("groups")))) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: authorsrecomm");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (postsrecomm() && (type.equals("inline_user_rec") || type.equals("live_recommended"))) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: postsrecomm");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (friendsrecomm() && (type.equals("user_rec") || type.equals("friends_recomm"))) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: friendsrecomm");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (adsgroup() && list.optInt("marked_as_ads") == 1 && !isWhitelistedAd(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: marked_as_ads is true");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isBadNews(list.optString("text")) && !isWhitelistedFilters(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: text filters");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (checkCopyright(list) && !isWhitelistedFilters(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: copyright filters");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (checkCaption(list) && !isWhitelistedFilters(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: caption filters");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NewsFeedFiltersUtils.injectFiltersReposts(list) && !isWhitelistedFilters(list)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", "Removed post " + list.optInt("post_id") + " from feed, Reason: repost ad");
|
||||
continue;
|
||||
}
|
||||
|
||||
newItems.put(list);
|
||||
}
|
||||
|
||||
return newItems;
|
||||
}
|
||||
|
||||
public static JSONObject music(JSONObject json) throws JSONException {
|
||||
var catalog = json.optJSONObject("catalog");
|
||||
|
||||
@@ -591,7 +388,7 @@ public class JsonInjectors {
|
||||
}
|
||||
}
|
||||
|
||||
var playlists = fetchCatalogId("https://vk.ru/audio?section=my_playlists");
|
||||
var playlists = fetchCatalogId("https://vk.com/audio?section=my_playlists");
|
||||
if (playlists != null) {
|
||||
var catalogarr = playlists.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0);
|
||||
|
||||
@@ -604,7 +401,7 @@ public class JsonInjectors {
|
||||
oldItems.put(new JSONObject().put("id", id).put("title", title).put("url", url));
|
||||
}
|
||||
|
||||
var albums = fetchCatalogId("https://vk.ru/audio?section=albums");
|
||||
var albums = fetchCatalogId("https://vk.com/audio?section=albums");
|
||||
if (albums != null) {
|
||||
var catalogarr = albums.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0);
|
||||
|
||||
@@ -617,7 +414,7 @@ public class JsonInjectors {
|
||||
oldItems.put(new JSONObject().put("id", id).put("title", title).put("url", url));
|
||||
}
|
||||
|
||||
var recent = fetchCatalogId("https://vk.ru/audio?section=recent");
|
||||
var recent = fetchCatalogId("https://vk.com/audio?section=recent");
|
||||
if (recent != null) {
|
||||
var catalogarr = recent.optJSONObject("catalog").optJSONArray("sections").optJSONObject(0);
|
||||
|
||||
@@ -650,7 +447,7 @@ public class JsonInjectors {
|
||||
}
|
||||
|
||||
public static JSONObject fetchCatalogId(String section) {
|
||||
if (section == null) return null;
|
||||
if (section.isEmpty()) return null;
|
||||
|
||||
var request = new Request.a()
|
||||
.b("https://" + getApi() + "/method/catalog.getAudio"
|
||||
@@ -763,10 +560,7 @@ public class JsonInjectors {
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
public static boolean haveDonateButton() {
|
||||
int randomshower = new Random().nextInt(6);
|
||||
|
||||
return hasVerification() || randomshower != 1;
|
||||
return hasVerification() || new Random().nextInt(6) != 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package ru.vtosters.lite.hooks;
|
||||
|
||||
import static ru.vtosters.lite.ui.dialogs.ServerDialog.sendRequest;
|
||||
import static ru.vtosters.lite.utils.CacheUtils.getInstance;
|
||||
import static ru.vtosters.lite.utils.DeletedMessagesHandler.reloadMessagesList;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.setupFilters;
|
||||
import static ru.vtosters.lite.utils.Preferences.checkupdates;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.isDarkTheme;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.setNeededTheme;
|
||||
@@ -11,21 +11,26 @@ import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.vk.core.concurrent.VkExecutors;
|
||||
|
||||
import ru.vtosters.lite.downloaders.notifications.NotificationChannels;
|
||||
import ru.vtosters.lite.ui.dialogs.DisableBattery;
|
||||
import ru.vtosters.lite.ui.dialogs.InstallGMS;
|
||||
import ru.vtosters.lite.ui.dialogs.OTADialog;
|
||||
import ru.vtosters.lite.ui.dialogs.ServerDialog;
|
||||
import ru.vtosters.lite.ui.dialogs.Start;
|
||||
import ru.vtosters.lite.utils.DeletedMessagesHandler;
|
||||
|
||||
/**
|
||||
* @
|
||||
*/
|
||||
public class MainActivityInjector {
|
||||
|
||||
public static void inject(Activity activity) {
|
||||
setNeededTheme(activity);
|
||||
ServerDialog.activity = activity;
|
||||
sendRequest();
|
||||
if (checkupdates()) OTADialog.checkUpdates(activity);
|
||||
reloadMessagesList();
|
||||
VkExecutors.x.f().a(DeletedMessagesHandler::reloadMessagesList); // ioScheduler
|
||||
Start.alert(activity);
|
||||
InstallGMS.alert(activity);
|
||||
DisableBattery.alert(activity);
|
||||
@@ -33,7 +38,14 @@ public class MainActivityInjector {
|
||||
.edit()
|
||||
.putBoolean("isdark", isDarkTheme())
|
||||
.commit();
|
||||
getInstance().autoCleaningCache();
|
||||
|
||||
|
||||
VkExecutors.x.q().a(() -> {
|
||||
getInstance().autoCleaningCache();
|
||||
}); // slowTasksScheduler
|
||||
|
||||
setupFilters();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannels.createChannels();
|
||||
}
|
||||
|
||||
@@ -7,16 +7,17 @@ import static ru.vtosters.lite.utils.Preferences.autoalltranslate;
|
||||
import static ru.vtosters.lite.utils.Preferences.autotranslate;
|
||||
import static ru.vtosters.lite.utils.Preferences.savemsgsett;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.vk.api.internal.MethodCall;
|
||||
|
||||
import ru.vtosters.lite.translators.BaseTranslator;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import ru.vtosters.lite.translators.BaseTranslator;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
|
||||
public class MessagesHook {
|
||||
public static String injectOwnText(String oldText) {
|
||||
@@ -73,6 +74,14 @@ public class MessagesHook {
|
||||
});
|
||||
}
|
||||
|
||||
public static Context fixCTX(Context ctx) {
|
||||
if (ctx == null){
|
||||
return LifecycleUtils.getCurrentActivity();
|
||||
} else {
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
|
||||
public static void injRequest(MethodCall.a req) {
|
||||
var time = expireTime();
|
||||
|
||||
|
||||
@@ -1,34 +1,22 @@
|
||||
package ru.vtosters.lite.hooks;
|
||||
|
||||
import static java.lang.Long.MAX_VALUE;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.*;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.checkCaption;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.checkCopyright;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.injectFiltersReposts;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isAds;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isAuthorRecommendations;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isBadNews;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isFriendsRecommendations;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isGroupAds;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isMusicBlock;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isNewsBlock;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isPostRecommendations;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.isRecomsGroup;
|
||||
import static ru.vtosters.lite.utils.Preferences.ads;
|
||||
import static ru.vtosters.lite.utils.Preferences.adsslider;
|
||||
import static ru.vtosters.lite.utils.Preferences.authorsrecomm;
|
||||
import static ru.vtosters.lite.utils.Preferences.friendsrecomm;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import com.vk.core.preference.Preference;
|
||||
import com.vtosters.lite.api.ExtendedCommunityProfile;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -36,36 +24,8 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class NewsfeedHook {
|
||||
public static boolean injectFilters(JSONObject obj) throws JSONException {
|
||||
if (getBoolValue("newadblock", true)) return true;
|
||||
|
||||
var optString = obj.optString("type", "");
|
||||
if (isAds(optString) || isAuthorRecommendations(optString) || isPostRecommendations(optString) || isFriendsRecommendations(optString) || isRecomsGroup(optString) || isMusicBlock(optString) || isNewsBlock(optString)) {
|
||||
return false;
|
||||
}
|
||||
optString = obj.optString("post_type", "");
|
||||
if (isAds(optString) || isAuthorRecommendations(optString) || isPostRecommendations(optString) || isFriendsRecommendations(optString) || isMusicBlock(optString) || isNewsBlock(optString)) {
|
||||
return false;
|
||||
}
|
||||
optString = obj.optString("filters", "");
|
||||
if (isAds(optString) || isAuthorRecommendations(optString) || isPostRecommendations(optString) || isFriendsRecommendations(optString)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (checkCopyright(obj)) return false;
|
||||
|
||||
if (isBadNews(obj.optString("text", ""))) return false;
|
||||
|
||||
if (checkCaption(obj)) return false;
|
||||
|
||||
if (isGroupAds(obj)) return false;
|
||||
|
||||
return !injectFiltersReposts(obj);
|
||||
} // inject our filters to newsfeed, getpost and discover
|
||||
|
||||
public static long getUpdateNewsfeed(boolean refresh_timeout) {
|
||||
if (vkme()) {
|
||||
return MAX_VALUE;
|
||||
@@ -93,7 +53,7 @@ public class NewsfeedHook {
|
||||
params.add("photo");
|
||||
params.add("photo_tag");
|
||||
|
||||
if (!friendsrecomm()) {
|
||||
if (!friendsrecomm() && !getBoolValue("donotgetads", false)) {
|
||||
params.add("friends_recomm");
|
||||
}
|
||||
|
||||
@@ -102,7 +62,7 @@ public class NewsfeedHook {
|
||||
params.add("promo_button");
|
||||
}
|
||||
|
||||
if (!authorsrecomm()) {
|
||||
if (!authorsrecomm() && !getBoolValue("donotgetads", false)) {
|
||||
params.add("authors_rec");
|
||||
}
|
||||
|
||||
@@ -150,14 +110,15 @@ public class NewsfeedHook {
|
||||
public static void adsParams(HashSet<String> hashSet) {
|
||||
if (ads()) {
|
||||
hashSet.add("ads_disabled");
|
||||
hashSet.add("ads_app_slider");
|
||||
return;
|
||||
if (getBoolValue("donotgetads", false)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
hashSet.add("ads_app");
|
||||
hashSet.add("ads_site");
|
||||
hashSet.add("ads_post");
|
||||
if (adsslider()) {
|
||||
if (!adsslider()) {
|
||||
hashSet.add("ads_app_slider");
|
||||
}
|
||||
hashSet.add("ads_site_slider");
|
||||
@@ -165,4 +126,10 @@ public class NewsfeedHook {
|
||||
hashSet.add("ads_post_pretty_cards");
|
||||
hashSet.add("ads_post_snippet_video");
|
||||
}
|
||||
|
||||
public static boolean isPowerSaveMode() {
|
||||
var pw = (PowerManager) getGlobalContext().getSystemService(Context.POWER_SERVICE);
|
||||
|
||||
return !getBoolValue("force_disable_psm", false) && pw.isPowerSaveMode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ package ru.vtosters.lite.hooks;
|
||||
import static ru.vtosters.lite.hooks.JsonInjectors.setOnlineInfo;
|
||||
import static ru.vtosters.lite.hooks.JsonInjectors.setOnlineInfoUsers;
|
||||
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.getString;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.Preferences.dev;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.getPrefsFromFile;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
@@ -123,13 +123,19 @@ public class OnlineFormatterHook {
|
||||
case 5632485:
|
||||
return "SpaceVK";
|
||||
case 6287487:
|
||||
return "vk.ru";
|
||||
return "vk.com";
|
||||
case 4542624:
|
||||
return "Black VK";
|
||||
case 3917910:
|
||||
return "Miranda NG (bridge)";
|
||||
case 8043814:
|
||||
return "Quise";
|
||||
case 7221936:
|
||||
return "Вечный Online";
|
||||
case 6892935:
|
||||
return "VK Helper";
|
||||
case 6248661:
|
||||
return "MemeVoices for VK";
|
||||
default:
|
||||
return getAppNameFromOnline(appid);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.vtosters.lite.hooks;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ClipData;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package ru.vtosters.lite.hooks;
|
||||
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isRandomProxyEnabled;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isVikaProxyEnabled;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isZaboronaEnabled;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplication;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isRandomProxyEnabled;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isZaboronaEnabled;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAlertStyle;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
@@ -45,8 +45,8 @@ public class ProxyHook {
|
||||
RadioButton rgVika = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton));
|
||||
|
||||
rg.addView(rgDefault);
|
||||
rg.addView(rgZaborona);
|
||||
rg.addView(rgVika);
|
||||
rg.addView(rgZaborona);
|
||||
rg.addView(rgRandomProxy);
|
||||
|
||||
rgDefault.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp2px(14f));
|
||||
@@ -62,10 +62,10 @@ public class ProxyHook {
|
||||
rgZaborona.setText(AndroidUtils.getString("proxy_enable") + " (Zaborona)");
|
||||
rgZaborona.setTextColor(getTextAttr());
|
||||
|
||||
rgRandomProxy.setText(AndroidUtils.getString("proxy_enable") + " (Random Proxy)");
|
||||
rgRandomProxy.setText(AndroidUtils.getString("proxy_enable") + " (Random Socks Proxy)");
|
||||
rgRandomProxy.setTextColor(getTextAttr());
|
||||
|
||||
rgVika.setText(AndroidUtils.getString("proxy_enable") + " (Vika)");
|
||||
rgVika.setText(AndroidUtils.getString("proxy_enable") + " (Vika Mobile)");
|
||||
rgVika.setTextColor(getTextAttr());
|
||||
|
||||
rgZaborona.setChecked(isZaboronaEnabled());
|
||||
|
||||
@@ -8,9 +8,9 @@ import com.vk.api.internal.MethodCall;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class RequestDumper{
|
||||
public static void addParams(MethodCall.a paramslist, String method, LinkedHashMap params, String apiver) {
|
||||
public static void addParams(MethodCall.a paramslist, String method, LinkedHashMap<String, String> params, String apiver) {
|
||||
if (method.contains("execute.getGiftByStickerId") ) {
|
||||
apiver = "5.187";
|
||||
apiver = "5.186";
|
||||
}
|
||||
|
||||
if (dev()) {
|
||||
|
||||
@@ -6,16 +6,14 @@ import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
import static ru.vtosters.lite.utils.Preferences.superapp;
|
||||
import static ru.vtosters.lite.utils.Preferences.useNewSettings;
|
||||
import static ru.vtosters.lite.utils.Preferences.videonewcatalog;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme;
|
||||
|
||||
import com.vk.apps.AppsFragment;
|
||||
import com.vk.discover.ThemedFeedFragment;
|
||||
import com.vk.discover.DiscoverFragment;
|
||||
import com.vk.fave.fragments.FaveTabFragment;
|
||||
import com.vk.menu.MenuFragment;
|
||||
import com.vk.menu.SearchMenuFragment;
|
||||
import com.vk.music.fragment.MusicCatalogFragment1;
|
||||
import com.vk.music.fragment.MusicFragment;
|
||||
import com.vk.newsfeed.HomeFragment;
|
||||
import com.vk.newsfeed.NewsfeedFragment;
|
||||
import com.vk.notifications.NotificationsContainerFragment;
|
||||
@@ -47,19 +45,19 @@ public class StartFragmentHook {
|
||||
case "groups":
|
||||
return milkshake() ? CommunitiesCatalogFragment.class : GroupsFragment1.class;
|
||||
case "music":
|
||||
return getBoolValue("musicnewcatalog", true) ? MusicCatalogFragment1.class : MusicFragment.class;
|
||||
return MusicCatalogFragment1.class;
|
||||
case "friends":
|
||||
return FriendsFragment.class;
|
||||
case "photos":
|
||||
return PhotosFragment.class;
|
||||
case "videos":
|
||||
return videonewcatalog() ? VideoCatalogFragment.class : VideosFragment.class;
|
||||
return VideoCatalogFragment.class;
|
||||
case "settings":
|
||||
return useNewSettings();
|
||||
case "apps":
|
||||
return AppsFragment.class;
|
||||
case "discover":
|
||||
return ThemedFeedFragment.class;
|
||||
return DiscoverFragment.class;
|
||||
case "notifications":
|
||||
return NotificationsContainerFragment.class;
|
||||
case "money":
|
||||
|
||||
@@ -4,7 +4,6 @@ import static ru.vtosters.lite.utils.Preferences.feedcache;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
import static ru.vtosters.lite.utils.Preferences.miniapps;
|
||||
import static ru.vtosters.lite.utils.Preferences.musicnewcatalog;
|
||||
import static ru.vtosters.lite.utils.Preferences.postsredesign;
|
||||
import static ru.vtosters.lite.utils.Preferences.superapp;
|
||||
|
||||
@@ -133,8 +132,6 @@ public class TogglesHook {
|
||||
case FEATURE_MILKSHAKE_FORCE_DISABLED:
|
||||
case FEATURE_MILKSHAKE_ACTIVATION_DISABLED:
|
||||
return !milkshake();
|
||||
case FEATURE_MUSIC_NEW_CATALOG:
|
||||
return musicnewcatalog();
|
||||
case AB_NEWS_VIDEO_LAYOUT_TEXT:
|
||||
case FEATURE_COMPACT_REPOST:
|
||||
case EXPERIMENT_NEWS_VIDEO_LAYOUT_TEXT:
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package ru.vtosters.lite.hooks;
|
||||
import static ru.vtosters.lite.utils.Preferences.wbios;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class WritebarHook{
|
||||
public static int getWriteBar(){
|
||||
return AndroidUtils.getIdentifier((wbios() ? "write_bar_i" : "write_bar"), "layout");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
package ru.vtosters.lite.hooks.ui;
|
||||
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.*;
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.asId;
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.getInstance;
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.isVkxInstalled;
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.lambdaplay;
|
||||
import static ru.vtosters.lite.music.cache.CacheDatabaseDelegate.isCached;
|
||||
import static ru.vtosters.lite.music.cache.CacheDatabaseDelegate.isVkxCached;
|
||||
import static ru.vtosters.lite.utils.NetworkUtils.isNetworkConnected;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
|
||||
import android.os.RemoteException;
|
||||
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
import com.vk.dto.music.Playlist;
|
||||
import com.vk.music.bottomsheets.a.MusicAction;
|
||||
import com.vk.music.common.MusicPlaybackLaunchContext;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClientImpl;
|
||||
import ru.vtosters.lite.downloaders.AudioDownloader;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class MusicBottomSheetHook {
|
||||
private static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
public static ArrayList<MusicAction> hook(ArrayList<MusicAction> actions, MusicTrack musicTrack) {
|
||||
if (musicTrack.F1()) return actions;
|
||||
|
||||
var trackid = asId(musicTrack);
|
||||
|
||||
if (isVkxInstalled()) {
|
||||
actions.add(getPlayInVKXAction());
|
||||
}
|
||||
|
||||
if (isIntegrationEnabled()) {
|
||||
if (isVkxCached(trackid)){
|
||||
actions.add(getRemoveCacheTrackVkxAction());
|
||||
} else {
|
||||
actions.add(addToCacheTrackVkxAction());
|
||||
}
|
||||
}
|
||||
|
||||
if (isNetworkConnected()){
|
||||
actions.add(downloadAsMp3Action());
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<MusicAction> hookDownloadBTN(ArrayList<MusicAction> actions, MusicTrack musicTrack) {
|
||||
if (musicTrack.F1()) return actions;
|
||||
|
||||
var trackid = asId(musicTrack);
|
||||
|
||||
if (isCached(trackid)){
|
||||
actions.add(new MusicAction(
|
||||
AndroidUtils.getIdentifier("music_action_toggle_download", "id"),
|
||||
milkshake() ? R.drawable.ic_delete_outline_28 : R.drawable.ic_delete_24,
|
||||
AndroidUtils.getIdentifier("remove_from_cache", "string"),
|
||||
musicTrack.F1() ? R.color.music_action_button_gray_50_alpha : R.color.caption_gray,
|
||||
R.string.music_talkback_empty,
|
||||
false
|
||||
));
|
||||
} else {
|
||||
actions.add(new MusicAction(
|
||||
AndroidUtils.getIdentifier("music_action_toggle_download", "id"),
|
||||
milkshake() ? R.drawable.ic_download_outline_28 : R.drawable.ic_download_24,
|
||||
AndroidUtils.getIdentifier("add_to_cache", "string"),
|
||||
musicTrack.F1() ? R.color.music_action_button_gray_50_alpha : R.color.caption_gray,
|
||||
R.string.music_talkback_empty,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
public static ArrayList<MusicAction> hook(ArrayList<MusicAction> actions, Playlist playlist) {
|
||||
if (playlist.D) return actions;
|
||||
|
||||
if (isVkxInstalled()) actions.add(getPlayInVKXAction());
|
||||
|
||||
if (isIntegrationEnabled()){
|
||||
if (isVkxCached(playlist.a, playlist.b)){
|
||||
actions.add(getRemoveCacheTrackVkxAction());
|
||||
} else {
|
||||
actions.add(addToCacheTrackVkxAction());
|
||||
}
|
||||
} else {
|
||||
actions.add(addToCacheTrackAction());
|
||||
}
|
||||
|
||||
if (isNetworkConnected()) actions.add(downloadAsMp3Action());
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
public static boolean injectOnClick(int actionId, MusicTrack track, MusicPlaybackLaunchContext context, Playlist playlist) { // musictrack inj
|
||||
if (actionId == AndroidUtils.getIdentifier("play_in_vkx", "id"))
|
||||
return tryPlayInVKX(track, context, playlist);
|
||||
|
||||
if (actionId == AndroidUtils.getIdentifier("remove_from_cache_vkx", "id")) {
|
||||
getInstance().runOnService(service -> {
|
||||
try {
|
||||
service.deleteTrackFromCache(track.d, track.e);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} else if (actionId == AndroidUtils.getIdentifier("add_to_cache_vkx", "id")) {
|
||||
getInstance().runOnService(service -> {
|
||||
try {
|
||||
service.addTrackToCache(track.d, track.e, (track.J != null) ? track.J : "");
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
if (actionId == AndroidUtils.getIdentifier("download_mp3", "id")) {
|
||||
if (isIntegrationEnabled()) {
|
||||
getInstance().runOnService(service -> {
|
||||
try {
|
||||
service.downloadTrack(track.d, track.e, (track.J != null) ? track.J : "");
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
AudioDownloader.downloadAudio(track);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean injectOnClick(int actionId, Playlist playlist) { // playlist inj
|
||||
if (actionId == AndroidUtils.getIdentifier("play_in_vkx", "id"))
|
||||
return tryPlayInVKX(null, null, playlist);
|
||||
|
||||
if (actionId == AndroidUtils.getIdentifier("add_to_cache", "id")) {
|
||||
executor.submit(() -> AudioDownloader.cachePlaylist(playlist));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (actionId == AndroidUtils.getIdentifier("remove_from_cache_vkx", "id")) {
|
||||
getInstance().runOnService(service -> {
|
||||
try {
|
||||
service.deletePlaylistFromCache(playlist.a, playlist.b);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} else if (actionId == AndroidUtils.getIdentifier("add_to_cache_vkx", "id")) {
|
||||
getInstance().runOnService(service -> {
|
||||
try {
|
||||
service.addPlaylistToCache(playlist.a, playlist.b, (playlist.Q != null) ? playlist.Q : "");
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
if (actionId == AndroidUtils.getIdentifier("download_mp3", "id")) {
|
||||
if (isIntegrationEnabled()) {
|
||||
getInstance().runOnService(service -> {
|
||||
try {
|
||||
service.downloadPlaylist(playlist.a, playlist.b, (playlist.Q != null) ? playlist.Q : "");
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
executor.submit(() -> AudioDownloader.downloadPlaylist(playlist));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean tryPlayInVKX(MusicTrack track, MusicPlaybackLaunchContext context, Playlist playlist) {
|
||||
var trackList = new ArrayList<MusicTrack>();
|
||||
|
||||
if (playlist != null) {
|
||||
trackList.addAll(playlist.R);
|
||||
} else {
|
||||
trackList.add(track);
|
||||
}
|
||||
|
||||
LibVKXClientImpl.LibVKXAction action = iLibVkxService -> lambdaplay(trackList, track, iLibVkxService, context);
|
||||
return getInstance().runOnService(action);
|
||||
}
|
||||
|
||||
private static MusicAction getPlayInVKXAction() {
|
||||
return new MusicAction(
|
||||
AndroidUtils.getIdentifier("play_in_vkx", "id"),
|
||||
milkshake() ? R.drawable.ic_music_outline_24 : R.drawable.ic_music_24,
|
||||
AndroidUtils.getIdentifier("play_in_vkx", "string"),
|
||||
R.color.caption_gray,
|
||||
R.string.music_talkback_empty,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
private static MusicAction getRemoveCacheTrackAction() {
|
||||
return new MusicAction(
|
||||
AndroidUtils.getIdentifier("remove_from_cache", "id"),
|
||||
milkshake() ? R.drawable.ic_delete_outline_28 : R.drawable.ic_delete_24,
|
||||
AndroidUtils.getIdentifier("remove_from_cache", "string"),
|
||||
R.color.caption_gray,
|
||||
R.string.music_talkback_empty,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
private static MusicAction addToCacheTrackAction() {
|
||||
return new MusicAction(
|
||||
AndroidUtils.getIdentifier("add_to_cache", "id"),
|
||||
milkshake() ? R.drawable.ic_add_outline_28 : R.drawable.ic_add_24,
|
||||
AndroidUtils.getIdentifier("add_to_cache", "string"),
|
||||
R.color.caption_gray,
|
||||
R.string.music_talkback_empty,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
private static MusicAction getRemoveCacheTrackVkxAction() {
|
||||
return new MusicAction(
|
||||
AndroidUtils.getIdentifier("remove_from_cache_vkx", "id"),
|
||||
milkshake() ? R.drawable.ic_delete_outline_28 : R.drawable.ic_delete_24,
|
||||
AndroidUtils.getIdentifier("remove_from_cache_vkx", "string"),
|
||||
R.color.caption_gray,
|
||||
R.string.music_talkback_empty,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
private static MusicAction addToCacheTrackVkxAction() {
|
||||
return new MusicAction(
|
||||
AndroidUtils.getIdentifier("add_to_cache_vkx", "id"),
|
||||
milkshake() ? R.drawable.ic_add_outline_28 : R.drawable.ic_add_24,
|
||||
AndroidUtils.getIdentifier("add_to_cache_vkx", "string"),
|
||||
R.color.caption_gray,
|
||||
R.string.music_talkback_empty,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
private static MusicAction downloadAsMp3Action() {
|
||||
return new MusicAction(
|
||||
AndroidUtils.getIdentifier("download_mp3", "id"),
|
||||
milkshake() ? R.drawable.ic_download_outline_28 : R.drawable.ic_download_24,
|
||||
AndroidUtils.getIdentifier("download_mp3", "string"),
|
||||
R.color.caption_gray,
|
||||
R.string.music_talkback_empty,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package ru.vtosters.lite.hooks.ui;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class SystemThemeChangerHook {
|
||||
private static int latestTheme = 0;
|
||||
|
||||
public static void onThemeChanged(Configuration configuration) {
|
||||
if (Preferences.systemtheme()) {
|
||||
var theme = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
if (theme == latestTheme) return;
|
||||
|
||||
switch (theme) {
|
||||
case Configuration.UI_MODE_NIGHT_YES:
|
||||
// Night mode is active, we're using dark theme
|
||||
ThemesUtils.applyTheme(ThemesUtils.getDarkTheme());
|
||||
latestTheme = theme;
|
||||
break;
|
||||
case Configuration.UI_MODE_NIGHT_NO:
|
||||
case Configuration.UI_MODE_NIGHT_UNDEFINED:
|
||||
// Night mode is not active, we're using light theme
|
||||
ThemesUtils.applyTheme(ThemesUtils.getLightTheme());
|
||||
latestTheme = theme;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.vtosters.lite.music;
|
||||
|
||||
import android.util.Log;
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -8,63 +8,119 @@ import java.io.InputStream;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
|
||||
import java8.util.concurrent.CompletableFuture;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import ru.vtosters.lite.music.converter.ts.FFMpeg;
|
||||
import ru.vtosters.lite.music.converter.ts.TSMerger;
|
||||
import ru.vtosters.lite.music.downloader.ThumbnailDownloader;
|
||||
import ru.vtosters.lite.music.interfaces.ITrackDownloader;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
public class M3UDownloader {
|
||||
public class M3UDownloader implements ITrackDownloader {
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
private static OkHttpClient client = new OkHttpClient();
|
||||
public static M3UDownloader getInstance() {
|
||||
return Holder.INSTANCE;
|
||||
}
|
||||
|
||||
public static void execute(String url, File outDir, Callback callback) {
|
||||
public void downloadTrack(MusicTrack track, File outDir, Callback callback, boolean cache) {
|
||||
var request = new Request.a()
|
||||
.b(url)
|
||||
.b(track.D)
|
||||
.a();
|
||||
client.a(request).a(new okhttp3.Callback() {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
|
||||
callback.onFailure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(Call call, Response response) throws IOException {
|
||||
parse(response.a().g(), outDir, callback);
|
||||
parse(response.a().g(), outDir, callback, track, cache);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void parse(String payload, File outDir, Callback callback) {
|
||||
try {
|
||||
VKM3UParser parser = new VKM3UParser(payload);
|
||||
List<TransportStream> tses = parser.getTransportStreams();
|
||||
callback.onProgress(5);
|
||||
for (TransportStream ts : tses) {
|
||||
String tsURL = parser.getBaseUrl() + ts.getName();
|
||||
Log.d("M3UDownloader", "Downloading " + tsURL);
|
||||
InputStream is = IOUtils.openStream(tsURL);
|
||||
byte[] content;
|
||||
if (TransportStream.METHOD_AES128.equals(ts.getMethod())) {
|
||||
String key = IOUtils.readAllLines(IOUtils.openStream(ts.getKeyURL()));
|
||||
content = IOUtils.decodeStream(is, key);
|
||||
} else {
|
||||
content = IOUtils.readAllBytes(is);
|
||||
}
|
||||
File tsDump = new File(outDir, ts.getName());
|
||||
IOUtils.writeToFile(tsDump, content);
|
||||
callback.onSizeReceived((long) content.length * tses.size(), parser.getHeapSize());
|
||||
callback.onProgress(10 + Math.round(80.0f * tses.indexOf(ts) / tses.size()));
|
||||
private void parse(String payload, File outDir, Callback callback, MusicTrack track, boolean cache) {
|
||||
if (cache)
|
||||
try {
|
||||
ThumbnailDownloader.downloadThumbnails(track);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
VKM3UParser parser = new VKM3UParser(payload);
|
||||
List<TransportStream> tses = parser.getTransportStreams();
|
||||
AtomicInteger progress = new AtomicInteger(0);
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
|
||||
var tsesDir = new File(outDir, String.valueOf(track.d));
|
||||
tsesDir.mkdirs();
|
||||
var resultTs = new File(tsesDir, "result.ts");
|
||||
|
||||
String title = null;
|
||||
|
||||
if (track.f != null) {
|
||||
title = track.f;
|
||||
if (!track.g.isEmpty()) {
|
||||
title += " (" + track.g + ")";
|
||||
}
|
||||
} catch (IOException | NoSuchPaddingException | NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
callback.onFailure();
|
||||
return;
|
||||
}
|
||||
callback.onSuccess();
|
||||
|
||||
var fileName = IOUtils.getValidFileName((cache ? "track" : track.C + " - " + title) + ".mp3");
|
||||
var resultMp3 = new File(outDir, fileName);
|
||||
|
||||
callback.onProgress(5);
|
||||
for (TransportStream ts : tses) {
|
||||
String tsURL = parser.getBaseUrl() + ts.getName();
|
||||
|
||||
futures.add(CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
InputStream is = IOUtils.openStream(tsURL);
|
||||
byte[] content;
|
||||
if (TransportStream.METHOD_AES128.equals(ts.getMethod())) {
|
||||
String key = IOUtils.readAllLines(IOUtils.openStream(ts.getKeyURL()));
|
||||
content = IOUtils.decodeStream(is, key);
|
||||
} else {
|
||||
content = IOUtils.readAllBytes(is);
|
||||
}
|
||||
File tsDump = new File(tsesDir, ts.getName());
|
||||
IOUtils.writeToFile(tsDump, content);
|
||||
callback.onProgress(10 + Math.round(80.0f * progress.addAndGet(1) / tses.size()));
|
||||
callback.onSizeReceived((long) content.length * tses.size(), parser.getHeapSize());
|
||||
} catch (IOException | NoSuchPaddingException | NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeyException e) {
|
||||
callback.onFailure();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
var future = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
|
||||
future.exceptionally(throwable -> {
|
||||
callback.onFailure();
|
||||
return null;
|
||||
})
|
||||
.thenApply(v -> TSMerger.merge(tsesDir, resultTs))
|
||||
.thenApply(mergeResult -> mergeResult && FFMpeg.convert(resultTs, resultMp3.getAbsolutePath(), track))
|
||||
.thenApply(convertResult -> {
|
||||
if (convertResult)
|
||||
callback.onProgress(10 + Math.round(80.0f * progress.addAndGet(1) / tses.size()));
|
||||
else callback.onFailure();
|
||||
return convertResult;
|
||||
})
|
||||
.thenRun(() -> IOUtils.deleteRecursive(tsesDir))
|
||||
.thenRun(callback::onSuccess);
|
||||
}
|
||||
|
||||
// Initialization-on-demand
|
||||
private static class Holder {
|
||||
private static final M3UDownloader INSTANCE = new M3UDownloader();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +1,76 @@
|
||||
package ru.vtosters.lite.music;
|
||||
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.utils.Preferences.getMusicDir;
|
||||
|
||||
import android.app.DownloadManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import ru.vtosters.lite.downloaders.AudioDownloader;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class MP3Downloader {
|
||||
|
||||
private static final String URL_FORMAT = "https://" + getApi() + "/method/audio.getById?v=5.131&access_token=%s&audios=%s©right=https://vtosters.app/";
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
public static void execute(MusicTrack track) {
|
||||
var token = AndroidUtils.getPreferences().getString("vk_admin_token", "");
|
||||
if (token.isEmpty()) {
|
||||
Toast.makeText(AndroidUtils.getGlobalContext(), AndroidUtils.getString("update_vk_admin_token"), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
var request = new Request.a()
|
||||
.b(String.format(URL_FORMAT, token, track.y1()))
|
||||
.a();
|
||||
client.a(request).a(new Callback() {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
Log.d("MP3Downloader", e + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(Call call, Response response) throws IOException {
|
||||
var payload = response.a().g();
|
||||
Log.d("MP3Downloader", payload);
|
||||
try {
|
||||
JSONObject jsonObj = new JSONObject(payload);
|
||||
if (jsonObj.has("response")) {
|
||||
JSONObject responseNode = new JSONObject(payload).getJSONArray("response")
|
||||
.getJSONObject(0);
|
||||
if (responseNode.has("url")) {
|
||||
var url = responseNode.optString("url");
|
||||
Log.d("MP3Downloader", url);
|
||||
if (url.endsWith(".mp3")) {
|
||||
downloadMP3(track.toString(), url);
|
||||
} else if (VKM3UParser.isM3U8(url)) {
|
||||
AudioDownloader.downloadM3U8(track);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.d("MP3Downloader", e + "");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
private static void downloadMP3(String title, String url) {
|
||||
var downloadManager = AndroidUtils.getGlobalContext().getSystemService(DownloadManager.class);
|
||||
var request = new DownloadManager.Request(Uri.parse(url))
|
||||
.setAllowedOverRoaming(true)
|
||||
.setTitle("Downloading " + title)
|
||||
.setDestinationInExternalFilesDir(AndroidUtils.getGlobalContext(),
|
||||
getMusicDir().getAbsolutePath(),
|
||||
title + ".mp3")
|
||||
.setVisibleInDownloadsUi(true);
|
||||
downloadManager.enqueue(request);
|
||||
}
|
||||
}
|
||||
//package ru.vtosters.lite.music;
|
||||
//
|
||||
//import android.text.TextUtils;
|
||||
//import android.util.Log;
|
||||
//import android.widget.Toast;
|
||||
//
|
||||
//import com.vk.dto.music.MusicTrack;
|
||||
//
|
||||
//import org.json.JSONException;
|
||||
//import org.json.JSONObject;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.io.IOException;
|
||||
//
|
||||
//import okhttp3.Call;
|
||||
//import okhttp3.Callback;
|
||||
//import okhttp3.OkHttpClient;
|
||||
//import okhttp3.Request;
|
||||
//import okhttp3.Response;
|
||||
//import ru.vtosters.lite.downloaders.AudioDownloader;
|
||||
//import ru.vtosters.lite.music.interfaces.ITrackDownloader;
|
||||
//import ru.vtosters.lite.utils.AndroidUtils;
|
||||
//
|
||||
//public class MP3Downloader implements ITrackDownloader {
|
||||
// private static final String URL_FORMAT = "https://api.vk.com/method/audio.getById?v=5.131&access_token=%s&audios=%s©right=";
|
||||
//
|
||||
// private static final OkHttpClient client = new OkHttpClient();
|
||||
//
|
||||
// public static void downloadMP3(MusicTrack track) {
|
||||
// var token = AndroidUtils.getPreferences().getString("vk_admin_token", "");
|
||||
// if (token.isEmpty()) {
|
||||
// Toast.makeText(AndroidUtils.getGlobalContext(), "Обновите токен VK Admin в настройках", Toast.LENGTH_SHORT).show();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// var request = new Request.a()
|
||||
// .b(String.format(URL_FORMAT, token, track.y1()))
|
||||
// .a();
|
||||
// client.a(request).a(new Callback() {
|
||||
// @Override
|
||||
// public void a(Call call, IOException e) {
|
||||
// Log.d("MP3Downloader", e + "");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void a(Call call, Response response) throws IOException {
|
||||
// var payload = response.a().g();
|
||||
// Log.d("MP3Downloader", payload);
|
||||
// try {
|
||||
// JSONObject jsonObj = new JSONObject(payload);
|
||||
// if (!jsonObj.has("response"))
|
||||
// return;
|
||||
// JSONObject responseNode = new JSONObject(payload).getJSONArray("response")
|
||||
// .getJSONObject(0);
|
||||
// if (!responseNode.has("url"))
|
||||
// return;
|
||||
// var url = responseNode.optString("url");
|
||||
// Log.d("MP3Downloader", url);
|
||||
// if (TextUtils.isEmpty(url))
|
||||
// return;
|
||||
// if (VKM3UParser.isM3U8(url)) {
|
||||
// AudioDownloader.downloadM3U8(track);
|
||||
// return;
|
||||
// }
|
||||
// } catch (JSONException e) {
|
||||
// Log.d("MP3Downloader", e + "");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void downloadTrack(String url, File outDir, ru.vtosters.lite.music.Callback callback) {
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -6,6 +6,7 @@ import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.Preferences.autocache;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
@@ -19,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import ru.vtosters.lite.downloaders.AudioDownloader;
|
||||
import ru.vtosters.lite.net.NetCall;
|
||||
import ru.vtosters.lite.net.NetCallback;
|
||||
import ru.vtosters.lite.net.NetClient;
|
||||
@@ -86,6 +88,8 @@ public class Scrobbler {
|
||||
return;
|
||||
}
|
||||
|
||||
if (autocache()) AudioDownloader.cacheTrack(musictrack);
|
||||
|
||||
scrobbleTrack(duration, artist, title, uid);
|
||||
}
|
||||
|
||||
@@ -120,7 +124,7 @@ public class Scrobbler {
|
||||
@Override
|
||||
public void onFailure(NetCall call, IOException e) {
|
||||
Log.d("Scrobbler", "Auth failed", e);
|
||||
sendToast(AndroidUtils.getString("lastfm_auth_error"));
|
||||
sendToast(AndroidUtils.getString("auth_error_vtl"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,344 @@
|
||||
package ru.vtosters.lite.music.cache;
|
||||
|
||||
import static ru.vtosters.lite.music.cache.FileCacheImplementation.getCacheDir;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.*;
|
||||
import static ru.vtosters.lite.utils.IOUtils.*;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.ILibVkxService;
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClientImpl;
|
||||
|
||||
public class CacheDatabaseDelegate {
|
||||
private static final int DB_VERSION = 0x1;
|
||||
private static final String DB_NAME = "vt_lite_cache.db";
|
||||
private static final String TABLE_NAME = "tracks";
|
||||
private static final String COLUMN_ID = "id";
|
||||
private static final String COLUMN_TRACK_ID = "trackId";
|
||||
private static final String COLUMN_ALBUM_ID = "albumId";
|
||||
private static final String COLUMN_TITLE = "title";
|
||||
private static final String COLUMN_SUBTITLE = "subtitle";
|
||||
private static final String COLUMN_ARTIST = "artist";
|
||||
private static final String COLUMN_ALBUM_TITLE = "albumTitle";
|
||||
private static final String COLUMN_EXPLICIT = "explicit";
|
||||
private static final String COLUMN_HAS_ARTWORK = "hasArtwork";
|
||||
private static final String COLUMN_DURATION = "duration";
|
||||
private static DbHelper helperInstance;
|
||||
|
||||
protected static DbHelper getHelper() {
|
||||
if (helperInstance == null) helperInstance = new DbHelper(getGlobalContext());
|
||||
return helperInstance;
|
||||
}
|
||||
|
||||
// You MUST call this method ONLY AFTER TRACK IS DOWNLOADED!
|
||||
public static void insertTrack(MusicTrack track) {
|
||||
try {
|
||||
var json = track.J();
|
||||
var albumNode = json.optJSONObject("album");
|
||||
|
||||
var hasArtwork = false;
|
||||
var albumId = -1;
|
||||
var albumName = "";
|
||||
|
||||
if (albumNode != null) {
|
||||
hasArtwork = albumNode.has("thumb");
|
||||
albumId = albumNode.getInt("id");
|
||||
albumName = albumNode.getString("title");
|
||||
}
|
||||
|
||||
var formula = String.format(
|
||||
"INSERT INTO %s (%s, %s, %s, %s, %s, %s, %s, %s, %s) VALUES ('%s', %s, '%s', '%s', '%s', '%s', %s, %s, %s)",
|
||||
TABLE_NAME,
|
||||
COLUMN_TRACK_ID, COLUMN_ALBUM_ID, COLUMN_TITLE, COLUMN_SUBTITLE, COLUMN_ARTIST, COLUMN_ALBUM_TITLE, COLUMN_EXPLICIT, COLUMN_DURATION, COLUMN_HAS_ARTWORK,
|
||||
track.y1(),
|
||||
albumId,
|
||||
URLEncoder.encode(json.getString("title"), "UTF-8"),
|
||||
URLEncoder.encode(json.optString("subtitle"), "UTF-8"),
|
||||
URLEncoder.encode(json.getString("artist"), "UTF-8"),
|
||||
URLEncoder.encode(albumName, "UTF-8"),
|
||||
json.optInt("is_explicit"),
|
||||
json.getInt("duration"),
|
||||
hasArtwork ? 1 : 0
|
||||
);
|
||||
getHelper().getReadableDatabase().execSQL(formula);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ToastUtils.a(getString("track_bd_insert_err") + " [" + e.getMessage() + "]", true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void insertTracks(List<MusicTrack> tracks) {
|
||||
for (var track : tracks) insertTrack(track);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
getHelper().getReadableDatabase().execSQL(String.format("DELETE FROM %s", TABLE_NAME));
|
||||
deleteRecursive(getCacheDir());
|
||||
sendToast(getString("cached_tracks_deleted"));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static JSONObject reconstructFromDb(Cursor cursor) {
|
||||
try {
|
||||
var trackId = cursor.getString(getColumnIndex(cursor, COLUMN_TRACK_ID));
|
||||
var splits = trackId.split("_");
|
||||
var id = Integer.parseInt(splits[1]);
|
||||
var ownerId = Integer.parseInt(splits[0]);
|
||||
|
||||
return new JSONObject()
|
||||
.put("url", FileCacheImplementation.getServerPath())
|
||||
.put("id", id)
|
||||
.put("owner_id", ownerId)
|
||||
.put("title", URLDecoder.decode(cursor.getString(getColumnIndex(cursor, COLUMN_TITLE)), "UTF-8"))
|
||||
.put("subtitle", URLDecoder.decode(cursor.getString(getColumnIndex(cursor, COLUMN_SUBTITLE)), "UTF-8"))
|
||||
.put("artist", URLDecoder.decode(cursor.getString(getColumnIndex(cursor, COLUMN_ARTIST)), "UTF-8"))
|
||||
.put("duration", cursor.getInt(getColumnIndex(cursor, COLUMN_DURATION)))
|
||||
.put("is_explicit", cursor.getInt(getColumnIndex(cursor, COLUMN_EXPLICIT)))
|
||||
.put("access_key", 2281488)
|
||||
.putOpt("album", reconstructAlbumFromDb(cursor, trackId));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new JSONObject();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JSONObject reconstructAlbumFromDb(Cursor cursor, String trackId) {
|
||||
try {
|
||||
if (!FileCacheImplementation.getTrackThumbnail(trackId, 300).exists()
|
||||
&& !FileCacheImplementation.getTrackThumbnail(trackId, 600).exists()
|
||||
&& !FileCacheImplementation.getTrackThumbnail(trackId, 1200).exists()
|
||||
) {
|
||||
var ownerId = Integer.parseInt(trackId.split("_")[1]);
|
||||
return new JSONObject()
|
||||
.put("id", cursor.getInt(getColumnIndex(cursor, COLUMN_ALBUM_ID)))
|
||||
.put("owner_id", ownerId)
|
||||
.put("title", URLDecoder.decode(cursor.getString(getColumnIndex(cursor, COLUMN_ALBUM_TITLE)), "UTF-8"))
|
||||
.putOpt("thumb", reconstructAlbumThumbFromDb(cursor, trackId));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JSONObject reconstructAlbumThumbFromDb(Cursor cursor, String trackId) {
|
||||
try {
|
||||
if (cursor.getInt(getColumnIndex(cursor, COLUMN_HAS_ARTWORK)) != 0)
|
||||
new JSONObject()
|
||||
.put("height", 600)
|
||||
.put("width", 600)
|
||||
.putOpt("photo_300", FileCacheImplementation.getFileUri(FileCacheImplementation.getTrackThumbnail(trackId, 300)))
|
||||
.putOpt("photo_600", FileCacheImplementation.getFileUri(FileCacheImplementation.getTrackThumbnail(trackId, 600)))
|
||||
.putOpt("photo_1200", FileCacheImplementation.getFileUri(FileCacheImplementation.getTrackThumbnail(trackId, 1200)));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static int getColumnIndex(Cursor cursor, String name) {
|
||||
return cursor.getColumnIndexOrThrow(name);
|
||||
}
|
||||
|
||||
public static boolean hasTracks() {
|
||||
if (LibVKXClient.isIntegrationEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var formula = String.format(
|
||||
"SELECT COUNT(%s) FROM %s",
|
||||
COLUMN_ID,
|
||||
TABLE_NAME
|
||||
);
|
||||
var cursor = getHelper().getReadableDatabase().rawQuery(formula, null);
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
int count = cursor.getInt(0);
|
||||
cursor.close();
|
||||
return count > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<MusicTrack> getTracks() {
|
||||
return getTracks(String.format(
|
||||
"SELECT * FROM %s",
|
||||
TABLE_NAME
|
||||
));
|
||||
}
|
||||
|
||||
public static List<MusicTrack> getTracksAsPlaylist() {
|
||||
return getTracks(String.format(
|
||||
"SELECT * FROM %s WHERE %s > -1 GROUP BY %s HAVING COUNT(*) > 1 ORDER by id DESC",
|
||||
TABLE_NAME,
|
||||
COLUMN_ALBUM_ID,
|
||||
COLUMN_ALBUM_ID
|
||||
));
|
||||
}
|
||||
|
||||
public static List<MusicTrack> getTracksByAlbum(String id) {
|
||||
return getTracks(String.format(
|
||||
"SELECT COUNT(%s) FROM %s WHERE %s = %s",
|
||||
COLUMN_ID,
|
||||
TABLE_NAME,
|
||||
COLUMN_ALBUM_ID,
|
||||
id
|
||||
));
|
||||
}
|
||||
|
||||
public static List<MusicTrack> getTracksByAlbumOne(String id) {
|
||||
return getTracks(String.format(
|
||||
"SELECT * FROM %s WHERE %s = %s LIMIT 1",
|
||||
TABLE_NAME,
|
||||
COLUMN_ALBUM_ID,
|
||||
id
|
||||
));
|
||||
}
|
||||
|
||||
public static List<MusicTrack> getTracks(String query) {
|
||||
List<MusicTrack> list = new ArrayList<>();
|
||||
try (Cursor cursor = getHelper().getReadableDatabase().rawQuery(query, new String[0])) {
|
||||
while (cursor.moveToNext()) {
|
||||
list.add(new MusicTrack(reconstructFromDb(cursor)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static boolean isCached(String trackId) {
|
||||
var formula = String.format(
|
||||
"SELECT COUNT(%s) FROM %s WHERE %s = '%s'",
|
||||
COLUMN_ID,
|
||||
TABLE_NAME,
|
||||
COLUMN_TRACK_ID,
|
||||
trackId
|
||||
);
|
||||
try {
|
||||
Cursor size = getHelper().getReadableDatabase().rawQuery(formula, null);
|
||||
if (size != null) {
|
||||
size.moveToFirst();
|
||||
int count = size.getInt(0);
|
||||
size.close();
|
||||
return count != 0;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isVkxCached(int playlist_id, int owner_id) {
|
||||
return LibVKXClient.getInstance().runOnServiceSync(new LibVKXClientImpl.LibVKXActionGeneric<>(){
|
||||
@Override
|
||||
public Boolean run(ILibVkxService service){
|
||||
try {
|
||||
return service.isPlaylistCached(playlist_id, owner_id);
|
||||
} catch (RemoteException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean defaultValue(){
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isVkxCached(String trackId) {
|
||||
return LibVKXClient.getInstance().runOnServiceSync(new LibVKXClientImpl.LibVKXActionGeneric<>(){
|
||||
@Override
|
||||
public Boolean run(ILibVkxService service){
|
||||
try {
|
||||
var splits = trackId.split("_");
|
||||
var id = Integer.parseInt(splits[1]);
|
||||
var owner = Integer.parseInt(splits[0]);
|
||||
return service.isTrackCached(id, owner);
|
||||
} catch (RemoteException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean defaultValue(){
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void removeTrackFromCache(String trackId) {
|
||||
deleteRecursive(FileCacheImplementation.getTrackFolder(trackId));
|
||||
|
||||
var formula = String.format(
|
||||
"DELETE FROM %s WHERE %s = '%s'",
|
||||
TABLE_NAME,
|
||||
COLUMN_TRACK_ID,
|
||||
trackId
|
||||
);
|
||||
getHelper().getWritableDatabase().execSQL(formula);
|
||||
}
|
||||
|
||||
public static long getTrackCount() {
|
||||
if (!LibVKXClient.isIntegrationEnabled())
|
||||
return DatabaseUtils.queryNumEntries(getHelper().getReadableDatabase(), TABLE_NAME);
|
||||
return LibVKXClient.getInstance().runOnServiceSync(new LibVKXClientImpl.LibVKXActionGeneric<Long>() {
|
||||
@Override
|
||||
public Long run(ILibVkxService service) {
|
||||
try {
|
||||
return (long) service.getCache().size();
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
return defaultValue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long defaultValue() {
|
||||
return 0L;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class DbHelper extends SQLiteOpenHelper {
|
||||
public DbHelper(Context context) {
|
||||
super(context, DB_NAME, null, DB_VERSION);
|
||||
}
|
||||
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
var formula = String.format(
|
||||
"CREATE TABLE %s (%s INTEGER PRIMARY KEY AUTOINCREMENT, %s TEXT, %s INTEGER, %s TEXT, %s TEXT, %s TEXT, %s TEXT, %s INTEGER, %s INTEGER, %s INTEGER)",
|
||||
TABLE_NAME,
|
||||
COLUMN_ID, COLUMN_TRACK_ID, COLUMN_ALBUM_ID, COLUMN_TITLE, COLUMN_SUBTITLE, COLUMN_ARTIST, COLUMN_ALBUM_TITLE, COLUMN_EXPLICIT, COLUMN_DURATION, COLUMN_HAS_ARTWORK
|
||||
);
|
||||
db.execSQL(formula);
|
||||
}
|
||||
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package ru.vtosters.lite.music.cache;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
public class FileCacheImplementation {
|
||||
|
||||
public static void clear() {
|
||||
CacheDatabaseDelegate.clear();
|
||||
IOUtils.deleteRecursive(getCacheDir(), false);
|
||||
}
|
||||
|
||||
public static File getCacheDir() {
|
||||
return AndroidUtils.getGlobalContext().getDir("vt_tracks", Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public static File getTrackFolder(String trackId) {
|
||||
var dir = new File(getCacheDir(), trackId);
|
||||
dir.mkdirs();
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static File getThumbnailsFolder(String trackId) {
|
||||
var dir = new File(getTrackFolder(trackId), "thumbs");
|
||||
dir.mkdirs();
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static File getTrackFile(String trackId) {
|
||||
return new File(getTrackFolder(trackId), "track.mp3");
|
||||
}
|
||||
|
||||
public static boolean isTrackExist(String trackId) {
|
||||
return CacheDatabaseDelegate.isCached(trackId);
|
||||
}
|
||||
|
||||
public static File getTrackFile(MusicTrack track) {
|
||||
return getTrackFile(track.y1());
|
||||
}
|
||||
|
||||
public static File getTrackThumbnail(String trackId, int factor) {
|
||||
return new File(getThumbnailsFolder(trackId), "thumb_" + factor + ".png");
|
||||
}
|
||||
|
||||
public static String getFileUri(File file) {
|
||||
if (!file.exists()) return null;
|
||||
return Uri.fromFile(file).toString();
|
||||
}
|
||||
|
||||
public static String getServerPath() {
|
||||
return "https://vtosters.app";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package ru.vtosters.lite.music.cache.helpers;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
|
||||
import com.vk.dto.music.Playlist;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.music.cache.FileCacheImplementation;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
|
||||
public class PlaylistHelper {
|
||||
|
||||
public static Playlist createCachedPlaylistMetadata() {
|
||||
try {
|
||||
var obj = new JSONObject()
|
||||
.put("id", -1)
|
||||
.put("owner_id", AccountManagerUtils.getUserId())
|
||||
.put("type", 0)
|
||||
.put("album_type", "playlist")
|
||||
.put("title", getString("cached_tracks_title"))
|
||||
.put("description", getString("cached_tracks_desc"))
|
||||
.put("count", 0);
|
||||
return new Playlist(obj);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Playlist createCachedPlaylistMetadata(String id) {
|
||||
var track = TracklistHelper.getTracksOne(id).get(0);
|
||||
var albumLink = track.I;
|
||||
var thumb = albumLink.u1();
|
||||
return createAlbum(
|
||||
thumb != null ? thumb.h(600) : "",
|
||||
albumLink.getTitle(),
|
||||
track.C,
|
||||
track.y1(),
|
||||
albumLink.getId()
|
||||
);
|
||||
}
|
||||
|
||||
public static Playlist createAlbum(String photo, String title, String artist, String trackId, int albumId) {
|
||||
try {
|
||||
var jPhoto = new JSONObject();
|
||||
if (!photo.isEmpty())
|
||||
jPhoto.put("height", 600)
|
||||
.put("width", 600)
|
||||
.putOpt("photo_300", FileCacheImplementation.getFileUri(FileCacheImplementation.getTrackThumbnail(trackId, 300)))
|
||||
.putOpt("photo_600", FileCacheImplementation.getFileUri(FileCacheImplementation.getTrackThumbnail(trackId, 600)));
|
||||
var obj = new JSONObject()
|
||||
.put("id", -2)
|
||||
.put("owner_id", albumId)
|
||||
.put("type", 1)
|
||||
.put("album_type", "main_only")
|
||||
.put("title", title)
|
||||
.put("description", albumId + "/ " + getString("cached_album_warning"))
|
||||
.put("main_artists", new JSONArray()
|
||||
.put(new JSONObject().put("name", artist)
|
||||
.put("id", "-1")
|
||||
.put("domain", "-1")))
|
||||
.putOpt("photo", jPhoto)
|
||||
.put("count", 0);
|
||||
return new Playlist(obj);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Playlist> getAlbumPlaylists() {
|
||||
List<Playlist> list = new ArrayList<>();
|
||||
for (var track : CacheDatabaseDelegate.getTracksAsPlaylist()) {
|
||||
var albumLink = track.I;
|
||||
var thumb = albumLink.u1();
|
||||
list.add(createAlbum(
|
||||
thumb != null ? thumb.h(600) : "",
|
||||
albumLink.getTitle(),
|
||||
track.C,
|
||||
track.y1(),
|
||||
albumLink.getId()
|
||||
));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package ru.vtosters.lite.music.cache.helpers;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.List;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.music.cache.FileCacheImplementation;
|
||||
|
||||
public class TracklistHelper {
|
||||
|
||||
public static List<MusicTrack> getTracks() {
|
||||
return CacheDatabaseDelegate.getTracks();
|
||||
}
|
||||
|
||||
public static List<MusicTrack> getTracks(String id) {
|
||||
return CacheDatabaseDelegate.getTracksByAlbum(id);
|
||||
}
|
||||
|
||||
public static List<MusicTrack> getTracksOne(String id) {
|
||||
return CacheDatabaseDelegate.getTracksByAlbumOne(id);
|
||||
}
|
||||
|
||||
public static JSONArray tracksToIds(List<MusicTrack> tracks) {
|
||||
var arr = new JSONArray();
|
||||
for (MusicTrack track : tracks) {
|
||||
arr.put(track.y1());
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static JSONArray tracksToJsons(List<MusicTrack> tracks) {
|
||||
var arr = new JSONArray();
|
||||
for (MusicTrack track : tracks) {
|
||||
var json = track.J();
|
||||
var folder = FileCacheImplementation.getThumbnailsFolder(LibVKXClient.asId(track));
|
||||
try {
|
||||
addCachedThumbnails(json, folder);
|
||||
} catch (JSONException | MalformedURLException e) {
|
||||
Log.d("TracklistHelper", e+"");
|
||||
}
|
||||
arr.put(json);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
private static void addCachedThumbnails(JSONObject target, File thumbnailsDir)
|
||||
throws JSONException, MalformedURLException {
|
||||
var sizes = new JSONArray();
|
||||
var files = thumbnailsDir.listFiles();
|
||||
if (files == null || files.length == 0)
|
||||
return;
|
||||
for (var file : files) {
|
||||
var filename = file.getName();
|
||||
var width = Integer.parseInt(filename.substring(6, filename.length() - 4));
|
||||
var src = file.toURI().toURL().toString();
|
||||
Log.d("tracksToJsons", src);
|
||||
var size = new JSONObject()
|
||||
.put("width", width)
|
||||
.put("src", src);
|
||||
sizes.put(size);
|
||||
}
|
||||
target.put("album", new JSONObject().put("thumb", new JSONObject().put("sizes", sizes)));
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package ru.vtosters.lite.music.cache.injectors;
|
||||
|
||||
import android.os.RemoteException;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.api.audio.AudioGetPlaylist;
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
import com.vk.dto.music.Playlist;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import ru.vtosters.lite.downloaders.AudioDownloader;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
import ru.vtosters.lite.music.cache.helpers.PlaylistHelper;
|
||||
import ru.vtosters.lite.music.cache.helpers.TracklistHelper;
|
||||
import ru.vtosters.lite.utils.NetworkUtils;
|
||||
|
||||
public class PlaylistInjector {
|
||||
|
||||
public final static String CHANNEL_NAME = "VTCH";
|
||||
|
||||
public static void injectDownloadPlaylist(Playlist playlist) {
|
||||
AudioDownloader.downloadPlaylist(playlist);
|
||||
}
|
||||
|
||||
public static boolean eligibleForOfflineCaching() {
|
||||
Log.d("PlaylistInjector", "eligibleForOfflineCaching");
|
||||
|
||||
return !NetworkUtils.isNetworkConnected() && CacheDatabaseDelegate.hasTracks();
|
||||
}
|
||||
|
||||
public static Observable<AudioGetPlaylist.c> injectGetPlaylist(AudioGetPlaylist audioGetPlaylist) {
|
||||
Log.d("PlaylistInjector", "injectGetPlaylist");
|
||||
|
||||
try {
|
||||
if (!eligibleForOfflineCaching())
|
||||
return null;
|
||||
var requestArgs = audioGetPlaylist.b();
|
||||
|
||||
var id = requestArgs.get("id");
|
||||
var ownerId = requestArgs.get("owner_id");
|
||||
var accessKey = requestArgs.get("access_key");
|
||||
boolean isVirtualPlaylist = accessKey != null && (accessKey.equals("cache"));
|
||||
boolean isAlbumVirtualPlaylist = accessKey != null && (accessKey.equals("cacheAlbum"));
|
||||
|
||||
Log.d("PlaylistInjector", "id = " + id + " / owner = " + ownerId + " / access = " + accessKey + " / " + isVirtualPlaylist + " + " + isAlbumVirtualPlaylist);
|
||||
|
||||
if (TextUtils.isEmpty(id) || (!isVirtualPlaylist && !isAlbumVirtualPlaylist))
|
||||
return null;
|
||||
|
||||
return Observable.a((ObservableOnSubscribe<AudioGetPlaylist.c>) observableEmitter -> {
|
||||
AudioGetPlaylist.c response = new AudioGetPlaylist.c();
|
||||
|
||||
if (LibVKXClient.isIntegrationEnabled()) {
|
||||
LibVKXClient.getInstance().runOnService((service) -> {
|
||||
try {
|
||||
List<String> cache;
|
||||
ArrayList<MusicTrack> tracks = new ArrayList<>();
|
||||
|
||||
if (isAlbumVirtualPlaylist) {
|
||||
response.b = new Playlist(new JSONObject(service.getPlaylistDefJson(id, ownerId)));
|
||||
cache = service.getTracksInPlaylist(id, ownerId);
|
||||
} else {
|
||||
response.b = PlaylistHelper.createCachedPlaylistMetadata();
|
||||
cache = service.getCache();
|
||||
}
|
||||
|
||||
for (String json : cache) {
|
||||
tracks.add(new MusicTrack(new JSONObject(json)));
|
||||
}
|
||||
|
||||
response.c = tracks;
|
||||
} catch (RemoteException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
response.c = new ArrayList<>();
|
||||
}
|
||||
observableEmitter.b(response);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isVirtualPlaylist) {
|
||||
response.c = (ArrayList<MusicTrack>) TracklistHelper.getTracks();
|
||||
response.b = PlaylistHelper.createCachedPlaylistMetadata();
|
||||
} else {
|
||||
response.c = (ArrayList<MusicTrack>) TracklistHelper.getTracks(requestArgs.get("owner_id"));
|
||||
response.b = PlaylistHelper.createCachedPlaylistMetadata(requestArgs.get("owner_id"));
|
||||
}
|
||||
|
||||
observableEmitter.b(response);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
package ru.vtosters.lite.music.cache.injectors;
|
||||
|
||||
import static ru.vtosters.lite.music.cache.CacheDatabaseDelegate.hasTracks;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.catalog2.core.CatalogParser;
|
||||
import com.vk.catalog2.core.api.dto.CatalogResponse;
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import ru.vtosters.lite.music.cache.helpers.PlaylistHelper;
|
||||
import ru.vtosters.lite.music.cache.helpers.TracklistHelper;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.NetworkUtils;
|
||||
|
||||
public class TracklistInjector {
|
||||
|
||||
public static boolean eligibleForOfflineCaching() {
|
||||
return !NetworkUtils.isNetworkConnected();
|
||||
}
|
||||
|
||||
public static Observable<CatalogResponse> createOfflineRx(CatalogParser parser) {
|
||||
Log.d("TracklistInjector", "createOfflineRx");
|
||||
|
||||
return Observable.a((ObservableOnSubscribe<CatalogResponse>) observableEmitter -> {
|
||||
if (LibVKXClient.isIntegrationEnabled()) {
|
||||
LibVKXClient.getInstance().runOnService((service) -> {
|
||||
try {
|
||||
try {
|
||||
Log.d("TracklistInjector", "Using vkx cache catalog");
|
||||
observableEmitter.b(parser.c(new JSONObject(service.getCacheCatalog())));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
List<MusicTrack> tracks = new ArrayList<>();
|
||||
List<String> cache = service.getCache();
|
||||
|
||||
for (String json : cache) {
|
||||
Log.d("TracklistInjector", "added " + json);
|
||||
tracks.add(new MusicTrack(new JSONObject(json)));
|
||||
}
|
||||
|
||||
Log.d("TracklistInjector", "Using own cache catalog from vkx");
|
||||
observableEmitter.b(parser.c(createVirtualCatalog(tracks)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (!hasTracks()){
|
||||
observableEmitter.b(parser.c(getEmptyCatalog()));
|
||||
} else {
|
||||
observableEmitter.b(parser.c(createVirtualCatalog(TracklistHelper.getTracks())));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static JSONObject getEmptyCatalog() throws JSONException{
|
||||
return new JSONObject("{\"catalog\":{\"default_section\":\"cache\",\"sections\":[{\"id\":\"cache\",\"title\":\"" + getString("cached_content_title") + "\",\"blocks\":[{\"data_type\":\"placeholder\",\"id\":\"0\",\"layout\":{\"name\":\"placeholder_big\"},\"placeholder_ids\":[\"_synth_trackEmpty\"]}]}]},\"audios\":[],\"playlists\":[],\"placeholders\":[{\"id\":\"_synth_trackEmpty\",\"title\":\"" + getString("cached_content_empty") + "\",\"text\":\"" + getString("cached_content_empty_desc") + "\",\"buttons\":[]}]}");
|
||||
}
|
||||
|
||||
public static void injectIntoExistingCatalog(JSONObject catalogNode) {
|
||||
Log.d("TracklistInjector", "injectIntoExistingCatalog");
|
||||
|
||||
if (!hasTracks()) return;
|
||||
try {
|
||||
var sectionsNode = catalogNode.getJSONObject("catalog")
|
||||
.getJSONArray("sections");
|
||||
var firstSection = sectionsNode.getJSONObject(0);
|
||||
if (!firstSection.getString("url").equals("https://vk.com/audios" + AccountManagerUtils.getUserId() + "?section=all"))
|
||||
return;
|
||||
|
||||
var foundPlaylistBlock = false;
|
||||
var suitableIndex = 0;
|
||||
|
||||
var blocks = firstSection.getJSONArray("blocks");
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
var block = blocks.getJSONObject(i);
|
||||
var dataType = block.getString("data_type");
|
||||
if ("music_audios".equals(dataType)) {
|
||||
suitableIndex = i - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!"music_playlists".equals(dataType))
|
||||
continue;
|
||||
|
||||
var playlistIds = block.getJSONArray("playlists_ids");
|
||||
var newPlaylistIds = new JSONArray()
|
||||
.put(AccountManagerUtils.getUserId() + "_-1");
|
||||
|
||||
for (int j = 0; j < playlistIds.length(); j++)
|
||||
newPlaylistIds.put(playlistIds.get(j));
|
||||
|
||||
block.put("playlists_ids", newPlaylistIds);
|
||||
|
||||
// need test
|
||||
blocks.remove(i);
|
||||
blocks.put(i, block);
|
||||
|
||||
foundPlaylistBlock = true;
|
||||
}
|
||||
|
||||
if (foundPlaylistBlock) {
|
||||
var playlists = catalogNode.getJSONArray("playlists")
|
||||
.put(0, PlaylistHelper.createCachedPlaylistMetadata().J());
|
||||
catalogNode.put("playlists", playlists);
|
||||
return;
|
||||
}
|
||||
|
||||
var ids = new JSONArray()
|
||||
.put(0, AccountManagerUtils.getUserId() + "_-1");
|
||||
|
||||
var playlistsBlock = new JSONObject()
|
||||
.put("id", getRandomId())
|
||||
.put("data_type", "music_playlists")
|
||||
.put("url", "synth:cache:playlists")
|
||||
.put("playlists_ids", ids);
|
||||
|
||||
var layout = new JSONObject()
|
||||
.put("name", "large_slider")
|
||||
.put("owner_id", AccountManagerUtils.getUserId());
|
||||
|
||||
playlistsBlock.put("layout", layout);
|
||||
|
||||
blocks.put(suitableIndex, playlistsBlock);
|
||||
|
||||
firstSection.put("blocks", blocks);
|
||||
|
||||
var playlists = new JSONArray()
|
||||
.put(0, PlaylistHelper.createCachedPlaylistMetadata().J());
|
||||
catalogNode.put("playlists", playlists);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static JSONObject createVirtualCatalog(List<MusicTrack> tracks)
|
||||
throws JSONException {
|
||||
Log.d("TracklistInjector", "createVirtualCatalog");
|
||||
|
||||
var clickAction = new JSONObject()
|
||||
.put("type", "open_url")
|
||||
.put("target", "internal")
|
||||
.put("url", "https://vkx.app/index.html?app=vt_ctg");
|
||||
|
||||
var catalogBanner = new JSONObject()
|
||||
.put("id", 1234)
|
||||
.put("image_mode", "cover")
|
||||
.put("title", getString("vkx_integration_title"))
|
||||
.put("text", getString("vkx_integration_desc"))
|
||||
.put("click_action", new JSONObject().put("action", clickAction));
|
||||
var catalogBanners = new JSONArray()
|
||||
.put(catalogBanner);
|
||||
|
||||
var audiosBlock = new JSONObject()
|
||||
.put("id", getRandomId())
|
||||
.put("data_type", "music_audios")
|
||||
.put("url", "synth:cache:list")
|
||||
.put("audios_ids", TracklistHelper.tracksToIds(tracks));
|
||||
|
||||
var layout = new JSONObject()
|
||||
.put("name", "list")
|
||||
.put("owner_id", AccountManagerUtils.getUserId());
|
||||
|
||||
audiosBlock.put("layout", layout);
|
||||
|
||||
var blocks = new JSONArray()
|
||||
.put(audiosBlock);
|
||||
|
||||
// var vkxPostirony = new JSONObject()
|
||||
// .put("id", getRandomId())
|
||||
// .put("data_type", "catalog_banners")
|
||||
// .put("url", "synth:cache:vkx")
|
||||
// .put("catalog_banner_ids", new JSONArray().put(1234));
|
||||
//
|
||||
// var vkxlayout = new JSONObject()
|
||||
// .put("name", "large_list")
|
||||
// .put("owner_id", Globals.getUserId())
|
||||
// .put("infinite_repeat", true);
|
||||
//
|
||||
// vkxPostirony.put("layout", vkxlayout);
|
||||
//
|
||||
// if (eligibleForVkxAd())
|
||||
// blocks.put(vkxPostirony);
|
||||
var randomId = getRandomId();
|
||||
|
||||
var section = new JSONObject()
|
||||
.put("id", randomId)
|
||||
.put("title", getString("saved_tracks_title"))
|
||||
.put("url", "synth:cache")
|
||||
.put("blocks", blocks);
|
||||
|
||||
var sections = new JSONArray()
|
||||
.put(section);
|
||||
|
||||
var catalog = new JSONObject()
|
||||
.put("sections", sections)
|
||||
.put("default_section", randomId);
|
||||
|
||||
return new JSONObject()
|
||||
.put("catalog", catalog)
|
||||
.put("audios", TracklistHelper.tracksToJsons(tracks))
|
||||
.put("catalog_banners", catalogBanners);
|
||||
}
|
||||
|
||||
private static String getRandomId() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package ru.vtosters.lite.music.callback;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import ru.vtosters.lite.downloaders.notifications.NotificationChannels;
|
||||
import ru.vtosters.lite.music.Callback;
|
||||
|
||||
public class MusicCallbackBuilder {
|
||||
private static NotificationManagerCompat notificationManager = NotificationChannels.getNotificationManager();
|
||||
|
||||
public static Callback buildOneTrackCallback(int notificationId, NotificationCompat.Builder notification) {
|
||||
return new Callback() {
|
||||
long startTime = 0;
|
||||
long elapsedTime = 0;
|
||||
|
||||
@Override
|
||||
public void onProgress(int progress) {
|
||||
if (elapsedTime > 1000) {
|
||||
notification.setProgress(100, progress, false);
|
||||
notificationManager.notify(notificationId, notification.build());
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
elapsedTime = 0;
|
||||
} else {
|
||||
elapsedTime = System.currentTimeMillis() - startTime;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
try {
|
||||
notification
|
||||
.setContentText(getString("player_download_finished"))
|
||||
.setProgress(0, 0, false)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download_done);
|
||||
notificationManager.notify(notificationId, notification.build());
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
Log.e("AudioDownloader", "native libs");
|
||||
Log.e("AudioDownloader", e.getMessage());
|
||||
onFailure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
notification.setContentText(getString("load_audio_error")).setProgress(0, 0, false);
|
||||
notificationManager.notify(notificationId, notification.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSizeReceived(long size, long header) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Callback buildPlaylistCallback(int playlistSize, NotificationCompat.Builder notification, int notificationId) {
|
||||
return new Callback() {
|
||||
@Override
|
||||
public void onProgress(int progress) {
|
||||
if (progress == playlistSize) {
|
||||
onSuccess();
|
||||
} else {
|
||||
notification.setContentText(String.format(getString("playlist_download_notf"), progress, playlistSize));
|
||||
notification.setProgress(playlistSize, progress, false);
|
||||
}
|
||||
notificationManager.notify(notificationId, notification.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
notification.setContentText(getString("player_download_finished"));
|
||||
notification.setProgress(0, 0, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
notification.setContentText(getString("load_audio_error")).setProgress(0, 0, false);
|
||||
notificationManager.notify(notificationId, notification.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSizeReceived(long size, long header) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package ru.vtosters.lite.music.converter.playlist;
|
||||
|
||||
import static ru.vtosters.lite.hooks.DateHook.getLocale;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
|
||||
import com.vk.core.network.Network;
|
||||
import com.vk.core.util.DeviceIdProvider;
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
import com.vk.dto.music.Playlist;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import java8.util.concurrent.CompletableFuture;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
/**
|
||||
* stuff for converting playlists DTO
|
||||
*/
|
||||
public class PlaylistConverter {
|
||||
public static List<MusicTrack> getPlaylist(Playlist oldPlaylist) {
|
||||
var tracks = requestPlaylist(0, oldPlaylist.b, oldPlaylist.Q, oldPlaylist.a);
|
||||
return tracks.stream().filter(track -> !track.D.isEmpty()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static List<MusicTrack> requestPlaylist(int offset, int ownerId, String accessKey, int id) {
|
||||
var audioCount = 1000;
|
||||
var requestUrl = "https://" + getApi() + "/method/execute.getPlaylist" +
|
||||
"?v=5.119" +
|
||||
"&https=1" +
|
||||
"&audio_count=" + audioCount +
|
||||
"&need_playlist=1" +
|
||||
"&device_id=" + DeviceIdProvider.d(AndroidUtils.getGlobalContext()) +
|
||||
"&owner_id=" + ownerId +
|
||||
"&access_key=" + accessKey +
|
||||
"&func_v=5" +
|
||||
"&id=" + id +
|
||||
"&lang=" + getLocale() +
|
||||
"&audio_offset=" + offset +
|
||||
"&need_owner=1" +
|
||||
"&access_token=" + AccountManagerUtils.getUserToken();
|
||||
|
||||
var request = new Request.a()
|
||||
.b(requestUrl)
|
||||
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8")).a();
|
||||
|
||||
try {
|
||||
var response = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return new OkHttpClient().a(request).execute().a().g();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
).get();
|
||||
var jsonObj = new JSONObject(response);
|
||||
if (!jsonObj.has("response"))
|
||||
return null;
|
||||
var playlist = new JSONObject(response).getJSONObject("response").getJSONArray("audios");
|
||||
var tracks = new ArrayList<MusicTrack>();
|
||||
for (int i = 0; i < playlist.length(); i++) {
|
||||
var track = new MusicTrack(playlist.getJSONObject(i));
|
||||
tracks.add(track);
|
||||
}
|
||||
|
||||
if (tracks.size() == audioCount) {
|
||||
tracks.addAll(requestPlaylist(offset + audioCount, ownerId, accessKey, id));
|
||||
}
|
||||
|
||||
return tracks;
|
||||
} catch (JSONException | ExecutionException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+58
-37
@@ -1,21 +1,78 @@
|
||||
package ru.vtosters.lite.music;
|
||||
package ru.vtosters.lite.music.converter.ts;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.arthenica.ffmpegkit.FFmpegKit;
|
||||
import com.arthenica.ffmpegkit.ReturnCode;
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vk.dto.music.Artist;
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
public class FFMpeg {
|
||||
private static final int BUFFER_SIZE = 2048;
|
||||
/**
|
||||
* @param in Merged .ts file via {@link ru.vtosters.lite.music.converter.ts.TSMerger}
|
||||
* @param out Output .mp3 file
|
||||
* @param track Track to be converted
|
||||
* @return True if success, else false
|
||||
*/
|
||||
public static boolean convert(File in, String out, MusicTrack track) {
|
||||
checkFFMpegLibs();
|
||||
|
||||
|
||||
// convert .ts file to .mp3 file via ffmpeg
|
||||
var sb = new StringBuilder();
|
||||
sb.append("-y -i \"").append(in.getAbsolutePath()).append("\"");
|
||||
sb.append(" -map 0 -dn ");
|
||||
//sb.append(" -loglevel error");
|
||||
sb.append(" -hide_banner");
|
||||
sb.append(" -write_id3v2 1");
|
||||
|
||||
String title = null;
|
||||
|
||||
if (track.f != null) {
|
||||
title = track.f;
|
||||
if (!track.g.isEmpty()) {
|
||||
title += " (" + track.g + ")";
|
||||
}
|
||||
}
|
||||
|
||||
if (title != null) {
|
||||
sb.append(" -metadata title=\"").append(IOUtils.getValidFileName(title)).append("\"");
|
||||
}
|
||||
|
||||
if (track.L != null) {
|
||||
sb.append(" -metadata artist=\"").append(track.L.stream().map(Artist::w1).collect(Collectors.joining(", "))).append("\"");
|
||||
} else if (track.C != null) {
|
||||
sb.append(" -metadata artist=\"").append(track.C).append("\"");
|
||||
}
|
||||
if (track.I != null) {
|
||||
sb.append(" -metadata album=\"").append(track.I.getTitle()).append("\"");
|
||||
}
|
||||
|
||||
sb.append(" -c copy \"").append(out).append("\"");
|
||||
|
||||
var command = sb.toString();
|
||||
|
||||
var session = FFmpegKit.execute(command);
|
||||
var rc = session.getReturnCode();
|
||||
|
||||
if (ReturnCode.isSuccess(rc)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.e("FFMpeg", "FFmpegKit failed with return code " + rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void copyAssets() {
|
||||
try {
|
||||
@@ -45,40 +102,4 @@ public class FFMpeg {
|
||||
copyAssets();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean convert(String in, String out) {
|
||||
checkFFMpegLibs();
|
||||
|
||||
// write the list of all .ts files to a txt file in "in" directory
|
||||
var list = new File(in);
|
||||
var listFile = new File(list, "list.txt");
|
||||
try {
|
||||
listFile.createNewFile();
|
||||
var writer = new java.io.FileWriter(listFile);
|
||||
for (var file : list.listFiles()) {
|
||||
if (file.getName().endsWith(".ts")) {
|
||||
writer.write("file " + file.getName() + "\n");
|
||||
}
|
||||
}
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// concatenate .ts files to a single .ts file
|
||||
FFmpegKit.execute("-f concat -safe 0 -i " + in + "/list.txt -c copy " + in + "/all.ts");
|
||||
|
||||
// convert .ts file to .mp3 file via ffmpeg
|
||||
var session = FFmpegKit.execute("-i " + in + "/all.ts -f mp3 -acodec mp3 -q:a 0 -y '" + out + "'");
|
||||
var rc = session.getReturnCode();
|
||||
|
||||
if (ReturnCode.isSuccess(rc)) {
|
||||
// remove temp files
|
||||
IOUtils.deleteRecursive(new File(in));
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.e("FFMpeg", "FFmpegKit failed with return code " + rc);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package ru.vtosters.lite.music.converter.ts;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
public class TSMerger {
|
||||
/**
|
||||
* Merge multiple .ts files into one .ts file
|
||||
* @param in Directory with .ts files
|
||||
* @return True if success, else false
|
||||
*/
|
||||
public static boolean merge(File in, File out) {
|
||||
var tsesList = in.listFiles();
|
||||
|
||||
if (tsesList == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var mergedByteArrayStream = new ByteArrayOutputStream();
|
||||
|
||||
Arrays.sort(tsesList, (o1, o2) -> {
|
||||
var index1 = Integer.parseInt(o1.getName().split("-")[1]);
|
||||
var index2 = Integer.parseInt(o2.getName().split("-")[1]);
|
||||
return index1 - index2;
|
||||
});
|
||||
|
||||
for (var file : tsesList) {
|
||||
if (file.getName().endsWith(".ts")) {
|
||||
try {
|
||||
mergedByteArrayStream.write(IOUtils.readAllBytes(file));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
try {
|
||||
Files.write(out.toPath(), mergedByteArrayStream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
try (FileOutputStream fos = new FileOutputStream(out)) {
|
||||
fos.write(mergedByteArrayStream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package ru.vtosters.lite.music.downloader;
|
||||
import static ru.vtosters.lite.hooks.DateHook.getLocale;
|
||||
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 android.util.Log;
|
||||
|
||||
import com.vk.core.network.Network;
|
||||
import com.vk.core.util.DeviceIdProvider;
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import java8.util.concurrent.CompletableFuture;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class AudioGet{
|
||||
public static List<MusicTrack> getAudios(){
|
||||
var tracks = requestAudios(0);
|
||||
return tracks != null ? tracks.stream().filter(track -> !track.D.isEmpty()).collect(Collectors.toList()) : null;
|
||||
}
|
||||
|
||||
private static List<MusicTrack> requestAudios(int offset){
|
||||
var audioCount = 1000;
|
||||
var requestUrl = "https://" + getApi() + "/method/audio.get" +
|
||||
"?v=5.119" +
|
||||
"&https=1" +
|
||||
"&count=" + audioCount +
|
||||
"&device_id=" + DeviceIdProvider.d(AndroidUtils.getGlobalContext()) +
|
||||
"&owner_id=" + getUserId() +
|
||||
"&access_key=" + getUserToken() +
|
||||
"&lang=" + getLocale() +
|
||||
"&offset=" + offset +
|
||||
"&access_token=" + getUserToken();
|
||||
|
||||
var request = new Request.a()
|
||||
.b(requestUrl)
|
||||
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8")).a();
|
||||
|
||||
try {
|
||||
var response = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return new OkHttpClient().a(request).execute().a().g();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
).get();
|
||||
var jsonObj = new JSONObject(response);
|
||||
if (!jsonObj.has("response"))
|
||||
return null;
|
||||
Log.d("AudioGet", jsonObj.toString());
|
||||
var audios = new JSONObject(response).getJSONObject("response").getJSONArray("items");
|
||||
var tracks = new ArrayList<MusicTrack>();
|
||||
for (int i = 0; i < audios.length(); i++) {
|
||||
var track = new MusicTrack(audios.getJSONObject(i));
|
||||
tracks.add(track);
|
||||
}
|
||||
|
||||
if (tracks.size() == audioCount) {
|
||||
tracks.addAll(requestAudios(offset + audioCount));
|
||||
}
|
||||
|
||||
return tracks;
|
||||
} catch (JSONException | ExecutionException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package ru.vtosters.lite.music.downloader;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import ru.vtosters.lite.downloaders.notifications.NotificationChannels;
|
||||
import ru.vtosters.lite.music.Callback;
|
||||
import ru.vtosters.lite.music.cache.CacheDatabaseDelegate;
|
||||
|
||||
public class PlaylistDownloader {
|
||||
private static NotificationManagerCompat notificationManager = NotificationChannels.getNotificationManager();
|
||||
|
||||
public static void downloadPlaylist(List<MusicTrack> playlist, String playlistName, String path, Callback callback) {
|
||||
File outDir = new File(path);
|
||||
if (!outDir.exists())
|
||||
if (outDir.mkdirs())
|
||||
Log.v("PlaylistDownloader", "Directory created");
|
||||
else
|
||||
Log.e("PlaylistDownloader", "Directory creation failed");
|
||||
|
||||
var downloadedTracks = new AtomicInteger(0);
|
||||
|
||||
for (MusicTrack musicTrack : playlist) {
|
||||
TrackDownloader.downloadTrack(musicTrack, path, new Callback() {
|
||||
@Override
|
||||
public void onProgress(int progress) {}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
var currentProgress = downloadedTracks.incrementAndGet();
|
||||
callback.onProgress(currentProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
callback.onFailure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSizeReceived(long size, long header) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void cachePlaylist(List<MusicTrack> playlist, Callback callback) {
|
||||
var downloadedTracks = new AtomicInteger(0);
|
||||
|
||||
for (MusicTrack musicTrack : playlist) {
|
||||
TrackDownloader.cacheTrack(musicTrack, new Callback() {
|
||||
@Override
|
||||
public void onProgress(int progress) {}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
var currentProgress = downloadedTracks.incrementAndGet();
|
||||
callback.onProgress(currentProgress);
|
||||
CacheDatabaseDelegate.insertTrack(musicTrack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
callback.onFailure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSizeReceived(long size, long header) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package ru.vtosters.lite.music.downloader;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import ru.vtosters.lite.music.cache.FileCacheImplementation;
|
||||
import ru.vtosters.lite.utils.IOUtils;
|
||||
|
||||
public class ThumbnailDownloader {
|
||||
|
||||
public static void downloadThumbnails(MusicTrack track)
|
||||
throws IOException {
|
||||
var obj = track.J();
|
||||
var trackId = LibVKXClient.asId(track);
|
||||
|
||||
if (!obj.has("album")) return;
|
||||
var album = obj.optJSONObject("album");
|
||||
|
||||
if (!album.has("thumb")) return;
|
||||
var thumb = album.optJSONObject("thumb");
|
||||
|
||||
if (thumb.has("sizes")) {
|
||||
var sizes = thumb.optJSONArray("sizes");
|
||||
for (int i = 0; i < sizes.length(); i++) {
|
||||
var size = sizes.optJSONObject(i);
|
||||
var width = size.optInt("width");
|
||||
var src = size.optString("src");
|
||||
downloadThumbnail(src, width, trackId);
|
||||
}
|
||||
} else {
|
||||
var names = thumb.names();
|
||||
for (int i = 0; i < names.length(); i++) {
|
||||
var name = names.optString(i);
|
||||
downloadThumbnail(thumb.optString(name), Integer.parseInt(name.substring(6)), trackId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadThumbnail(String url, int res, String trackId)
|
||||
throws IOException {
|
||||
var data = IOUtils.readAllBytes(new URL(url).openStream());
|
||||
IOUtils.writeToFile(FileCacheImplementation.getTrackThumbnail(trackId, res), data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package ru.vtosters.lite.music.downloader;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.client.LibVKXClient;
|
||||
import ru.vtosters.lite.music.Callback;
|
||||
import ru.vtosters.lite.music.M3UDownloader;
|
||||
import ru.vtosters.lite.music.cache.FileCacheImplementation;
|
||||
import ru.vtosters.lite.music.interfaces.ITrackDownloader;
|
||||
|
||||
public class TrackDownloader {
|
||||
public static void downloadTrack(MusicTrack track, String path, Callback callback) {
|
||||
download(track, path, callback, M3UDownloader.getInstance(), false);
|
||||
}
|
||||
|
||||
public static void cacheTrack(MusicTrack track, Callback callback) {
|
||||
var path = FileCacheImplementation.getTrackFolder(LibVKXClient.asId(track)).getAbsolutePath();
|
||||
download(track, path, callback, M3UDownloader.getInstance(), true);
|
||||
}
|
||||
|
||||
private static void download(MusicTrack track, String path, Callback callback, ITrackDownloader downloader, boolean cache) {
|
||||
File outDir = new File(path);
|
||||
if (!outDir.exists())
|
||||
if (outDir.mkdir())
|
||||
Log.v("TrackDownloader", "Directory created");
|
||||
else
|
||||
Log.e("TrackDownloader", "Directory creation failed");
|
||||
downloader.downloadTrack(track, outDir, callback, cache);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package ru.vtosters.lite.music.interfaces;
|
||||
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import ru.vtosters.lite.music.Callback;
|
||||
|
||||
/**
|
||||
* Interface for track downloaders
|
||||
*/
|
||||
public interface ITrackDownloader {
|
||||
/**
|
||||
* Download track
|
||||
* @param track Music track
|
||||
* @param outDir Directory where to download the track
|
||||
* @param callback Callback to call when download status changes
|
||||
*/
|
||||
void downloadTrack(MusicTrack track, File outDir, Callback callback, boolean cache);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package ru.vtosters.lite.music.notification;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import com.vk.dto.music.MusicTrack;
|
||||
|
||||
import ru.vtosters.lite.downloaders.notifications.NotificationChannels;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class MusicNotificationBuilder {
|
||||
private static NotificationManagerCompat notificationManager = NotificationChannels.getNotificationManager();
|
||||
|
||||
public static NotificationCompat.Builder buildDownloadNotification(MusicTrack track, int id) {
|
||||
var notificationBuilder = new NotificationCompat.Builder(AndroidUtils.getGlobalContext(), NotificationChannels.MUSIC_DOWNLOAD_CHANNEL_ID)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
.setContentTitle(getString("audio_downloading"))
|
||||
.setContentText(track.toString())
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||
.setAutoCancel(true)
|
||||
.setProgress(100, 0, false);
|
||||
notificationManager.notify(id, notificationBuilder.build());
|
||||
return notificationBuilder;
|
||||
}
|
||||
|
||||
public static NotificationCompat.Builder buildPlaylistDownloadNotification(String playlistName, int id) {
|
||||
var notificationBuilder = new NotificationCompat.Builder(AndroidUtils.getGlobalContext(), NotificationChannels.MUSIC_PLAYLIST_DOWNLOAD_CHANNEL_ID)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
.setContentTitle(getString("playlist_downloading") + " «" + playlistName + "»")
|
||||
.setContentText(playlistName)
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||
.setAutoCancel(true)
|
||||
.setProgress(100, 0, false);
|
||||
notificationManager.notify(id, notificationBuilder.build());
|
||||
return notificationBuilder;
|
||||
}
|
||||
|
||||
public static NotificationCompat.Builder buildAllAudiosDownloadNotification(int id) {
|
||||
var notificationBuilder = new NotificationCompat.Builder(AndroidUtils.getGlobalContext(), NotificationChannels.MUSIC_PLAYLIST_DOWNLOAD_CHANNEL_ID)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
.setContentTitle(getString("notf_audio_dl_user") + " " + AccountManagerUtils.getUsername())
|
||||
.setContentText(getString("all_audio"))
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||
.setAutoCancel(true)
|
||||
.setProgress(100, 0, false);
|
||||
notificationManager.notify(id, notificationBuilder.build());
|
||||
return notificationBuilder;
|
||||
}
|
||||
|
||||
public static void notifySavingToCache(MusicTrack track) {
|
||||
Notification.Builder builder;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
builder = new Notification.Builder(AndroidUtils.getGlobalContext(), NotificationChannels.MUSIC_DOWNLOAD_CHANNEL_ID);
|
||||
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
|
||||
} else builder = new Notification.Builder(AndroidUtils.getGlobalContext());
|
||||
|
||||
builder.setSmallIcon(com.vtosters.lite.R.drawable.ic_download_outline_28)
|
||||
.setShowWhen(false)
|
||||
.setContentTitle(getString("cached_track") + ": " + track.toString());
|
||||
|
||||
notificationManager.notify(track.y1().hashCode(), builder.build());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package ru.vtosters.lite.proxy;
|
||||
|
||||
import static java.lang.System.clearProperty;
|
||||
import static ru.vtosters.lite.proxy.api.VikaMobile.getApiHost;
|
||||
import static ru.vtosters.lite.proxy.api.VikaMobile.getOauthHost;
|
||||
import static ru.vtosters.lite.proxy.api.VikaMobile.getStaticHost;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
|
||||
@@ -23,31 +26,47 @@ public class ProxyUtils{
|
||||
public static String getApi(){
|
||||
var proxyapi = getPrefsValue("proxyapi");
|
||||
|
||||
if (isApiProxyEnabled() & !proxyapi.isEmpty()) {
|
||||
if (isVikaProxyEnabled()) {
|
||||
proxyapi = getApiHost();
|
||||
}
|
||||
|
||||
if (isAnyProxyEnabled() & !proxyapi.isEmpty()) {
|
||||
return proxyapi;
|
||||
}
|
||||
|
||||
return "api.vk.ru";
|
||||
return "api.vk.com";
|
||||
}
|
||||
|
||||
public static String getOauth(){
|
||||
var oauth = getPrefsValue("proxyoauth");
|
||||
|
||||
if (isApiProxyEnabled() & !oauth.isEmpty()) {
|
||||
if (isVikaProxyEnabled()) {
|
||||
oauth = getOauthHost();
|
||||
}
|
||||
|
||||
if (isAnyProxyEnabled() & !oauth.isEmpty()) {
|
||||
return oauth;
|
||||
}
|
||||
|
||||
return "oauth.vk.ru";
|
||||
return "oauth.vk.com";
|
||||
}
|
||||
|
||||
public static String getStatic(){
|
||||
var oauth = getPrefsValue("proxystatic");
|
||||
var staticapi = getPrefsValue("proxystatic");
|
||||
|
||||
if (isApiProxyEnabled() & !oauth.isEmpty()) {
|
||||
return oauth;
|
||||
if (isVikaProxyEnabled()) {
|
||||
staticapi = getStaticHost();
|
||||
}
|
||||
|
||||
return "static.vk.ru";
|
||||
if (isAnyProxyEnabled() & !staticapi.isEmpty()) {
|
||||
return staticapi;
|
||||
}
|
||||
|
||||
return "static.vk.com";
|
||||
}
|
||||
|
||||
public static Boolean isAnyProxyEnabled(){
|
||||
return isApiProxyEnabled() || isVikaProxyEnabled();
|
||||
}
|
||||
|
||||
public static Boolean isZaboronaEnabled(){
|
||||
@@ -59,7 +78,7 @@ public class ProxyUtils{
|
||||
}
|
||||
|
||||
public static Boolean isApiProxyEnabled(){
|
||||
return getPrefsValue("proxy").equals("apiproxy") || getPrefsValue("proxy").equals("vika");
|
||||
return getPrefsValue("proxy").equals("apiproxy");
|
||||
}
|
||||
|
||||
public static Boolean isVikaProxyEnabled(){
|
||||
|
||||
@@ -2,7 +2,6 @@ package ru.vtosters.lite.proxy;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.forceProxyApplying;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.resetProxy;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.Preferences.preferences;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package ru.vtosters.lite.proxy.api;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isApiProxyEnabled;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isAnyProxyEnabled;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isVikaProxyEnabled;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
|
||||
@@ -7,12 +7,9 @@ import android.util.Log;
|
||||
|
||||
public class ApiProxy{
|
||||
public static String linkReplacer(String link){
|
||||
var vkapi = "api.vk.ru";
|
||||
var oauth = "oauth.vk.ru";
|
||||
var vkstatic = "static.vk.ru";
|
||||
var vkapiold = "api.vk.com";
|
||||
var oauthold = "oauth.vk.com";
|
||||
var vkstaticold = "static.vk.com";
|
||||
var vkapi = "api.vk.com";
|
||||
var oauth = "oauth.vk.com";
|
||||
var vkstatic = "static.vk.com";
|
||||
|
||||
var proxyapi = getPrefsValue("proxyapi");
|
||||
var proxyoauth = getPrefsValue("proxyoauth");
|
||||
@@ -24,7 +21,7 @@ public class ApiProxy{
|
||||
proxystatic = VikaMobile.getStaticHost();
|
||||
}
|
||||
|
||||
if ((!isApiProxyEnabled() || !isVikaProxyEnabled()) || link.isEmpty()) {
|
||||
if (!isAnyProxyEnabled() || link.isEmpty()) {
|
||||
return link;
|
||||
}
|
||||
|
||||
@@ -45,18 +42,6 @@ public class ApiProxy{
|
||||
return link.replaceAll(vkstatic, proxystatic);
|
||||
}
|
||||
|
||||
if (link.contains(vkapiold)) {
|
||||
return link.replaceAll(vkapiold, proxyapi);
|
||||
}
|
||||
|
||||
if (link.contains(oauthold)) {
|
||||
return link.replaceAll(vkapiold, proxyoauth);
|
||||
}
|
||||
|
||||
if (link.contains(vkstaticold)) {
|
||||
return link.replaceAll(vkapiold, proxystatic);
|
||||
}
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
@@ -67,18 +52,24 @@ public class ApiProxy{
|
||||
string = VikaMobile.getStaticHost();
|
||||
}
|
||||
|
||||
if ((isApiProxyEnabled() || isVikaProxyEnabled()) && string.isEmpty()) return str;
|
||||
if (isAnyProxyEnabled() && !string.isEmpty()) {
|
||||
return str.replaceAll(string, "static.vk.com");
|
||||
}
|
||||
|
||||
return str.replaceAll(string, "static.vk.ru");
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String getAwayPhpCom(){
|
||||
var proxyapi = getPrefsValue("proxyapi");
|
||||
|
||||
if ((isApiProxyEnabled() || isVikaProxyEnabled()) & !proxyapi.isEmpty()) {
|
||||
if (isVikaProxyEnabled()) {
|
||||
proxyapi = VikaMobile.getApiHost();
|
||||
}
|
||||
|
||||
if (isAnyProxyEnabled() && !proxyapi.isEmpty()) {
|
||||
return proxyapi;
|
||||
}
|
||||
|
||||
return "m.vk.ru";
|
||||
return "m.vk.com";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import ru.vtosters.lite.utils.LayoutUtils;
|
||||
|
||||
public class VKAdminTokenActivity extends AppCompatActivity {
|
||||
|
||||
private static final String URL = "https://" + getOauth() +"/authorize?client_id=6121396&scope=1073737727&redirect_uri=https://oauth.vk.ru/blank.html&display=page&response_type=token&revoke=1";
|
||||
private static final String URL = "https://" + getOauth() +"/authorize?client_id=6121396&scope=1073737727&redirect_uri=https://oauth.vk.com/blank.html&display=page&response_type=token&revoke=1";
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle bundle) {
|
||||
|
||||
@@ -24,11 +24,13 @@ import com.aefyr.tsg.g2.TelegramStickersPack;
|
||||
import com.aefyr.tsg.g2.TelegramStickersService;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
|
||||
import ru.vtosters.lite.tgs.TGPref;
|
||||
import ru.vtosters.lite.ui.components.IItemMovingListener;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class StickerPackAdapter extends RecyclerView.Adapter<StickerPackAdapter.StickerPackViewHolder> {
|
||||
public class StickerPackAdapter extends RecyclerView.Adapter<StickerPackAdapter.StickerPackViewHolder> implements IItemMovingListener {
|
||||
private static final TelegramStickersService sService = TelegramStickersService.getInstance(getGlobalContext());
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
@@ -62,6 +64,26 @@ public class StickerPackAdapter extends RecyclerView.Adapter<StickerPackAdapter.
|
||||
return sService.getPacksListReference().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemDismiss(int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemMove(int fromPosition, int toPosition) {
|
||||
if (fromPosition < toPosition) {
|
||||
for (int i = fromPosition; i < toPosition; i++) {
|
||||
sService.swap(sService.getPacksListReference().get(i), sService.getPacksListReference().get(i + 1));
|
||||
}
|
||||
} else {
|
||||
for (int i = fromPosition; i > toPosition; i--) {
|
||||
sService.swap(sService.getPacksListReference().get(i), sService.getPacksListReference().get(i - 1));
|
||||
}
|
||||
}
|
||||
notifyItemMoved(fromPosition, toPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
public class StickerPackViewHolder extends RecyclerView.ViewHolder {
|
||||
private final LinearLayout mContainer;
|
||||
private final ImageView mStickerPreview;
|
||||
|
||||
@@ -6,21 +6,19 @@ import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
import static ru.vtosters.lite.utils.Preferences.superapp;
|
||||
import static ru.vtosters.lite.utils.Preferences.useNewSettings;
|
||||
import static ru.vtosters.lite.utils.Preferences.videonewcatalog;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme_notifs;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import com.vk.apps.AppsFragment;
|
||||
import com.vk.discover.ThemedFeedFragment;
|
||||
import com.vk.discover.DiscoverFragment;
|
||||
import com.vk.fave.fragments.FaveTabFragment;
|
||||
import com.vk.feedlikes.d.FeedLikesFragment;
|
||||
import com.vk.friends.catalog.FriendsCatalogFragment;
|
||||
import com.vk.menu.MenuFragment;
|
||||
import com.vk.menu.SearchMenuFragment;
|
||||
import com.vk.music.fragment.MusicCatalogFragment1;
|
||||
import com.vk.music.fragment.MusicFragment;
|
||||
import com.vk.newsfeed.HomeFragment;
|
||||
import com.vk.newsfeed.NewsfeedFragment;
|
||||
import com.vk.notifications.NotificationsContainerFragment;
|
||||
@@ -154,7 +152,7 @@ public class DockBarEditorManager {
|
||||
milkshake() ? R.drawable.ic_services_outline_28 : R.drawable.ic_menu_search_outline_28,
|
||||
milkshake() ? R.string.super_app_title : R.string.search,
|
||||
R.id.tab_discover,
|
||||
milkshake() ? (superapp() ? SuperAppFragment.class : SearchMenuFragment.class) : ThemedFeedFragment.class);
|
||||
milkshake() ? (superapp() ? SuperAppFragment.class : SearchMenuFragment.class) : DiscoverFragment.class);
|
||||
case "tab_messages":
|
||||
return DockBarTab.valuesOf(
|
||||
"tab_messages",
|
||||
@@ -203,14 +201,14 @@ public class DockBarEditorManager {
|
||||
R.drawable.ic_music_outline_28,
|
||||
R.string.music,
|
||||
R.id.menu_audios,
|
||||
getBoolValue("musicnewcatalog", true) ? MusicCatalogFragment1.class : MusicFragment.class);
|
||||
MusicCatalogFragment1.class);
|
||||
case "tab_videos":
|
||||
return DockBarTab.valuesOf(
|
||||
"tab_videos",
|
||||
R.drawable.ic_video_outline_28,
|
||||
R.string.videos,
|
||||
R.id.menu_videos,
|
||||
videonewcatalog() ? VideoCatalogFragment.class : VideosFragment.class);
|
||||
VideoCatalogFragment.class);
|
||||
case "tab_lives":
|
||||
return DockBarTab.valuesOf(
|
||||
"tab_lives",
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package ru.vtosters.lite.ui.components;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class StickerTouchHelperCallback extends ItemTouchHelper.Callback {
|
||||
private final IItemMovingListener itemAdapter;
|
||||
|
||||
public StickerTouchHelperCallback(IItemMovingListener adapter) {
|
||||
itemAdapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLongPressDragEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemViewSwipeEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
|
||||
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN |
|
||||
ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
|
||||
|
||||
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
|
||||
return makeMovementFlags(dragFlags, swipeFlags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
|
||||
itemAdapter.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import ru.vtosters.lite.ui.items.DockBarTab;
|
||||
import ru.vtosters.lite.ui.items.SuperAppItem;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.content.Context;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
@@ -40,28 +40,28 @@ public class ServerDialog {
|
||||
public static void sendRequest() {
|
||||
if (getBoolValue("dialogrecomm", false)) return;
|
||||
|
||||
if (isNetworkIsSlow()) return;
|
||||
if (!isNetworkIsSlow() && !getBoolValue("isRoamingState", false)) {
|
||||
Request request = new Request.a()
|
||||
.b("https://vtosters.app/dialog.json")
|
||||
.a();
|
||||
|
||||
Request request = new Request.a()
|
||||
.b("https://vtosters.app/dialog.json")
|
||||
.a();
|
||||
|
||||
client.a(request).a(new Callback() {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
Log.d(TAG, "" + e);
|
||||
showAlert = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(Call call, Response response) {
|
||||
try {
|
||||
getResponse(response.a().g());
|
||||
} catch (Exception e) {
|
||||
client.a(request).a(new Callback() {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
Log.d(TAG, "" + e);
|
||||
showAlert = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void a(Call call, Response response) {
|
||||
try {
|
||||
getResponse(response.a().g());
|
||||
} catch (Exception e) {
|
||||
showAlert = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static Boolean showForNotVerified() {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package ru.vtosters.lite.ui.dialogs;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.core.ui.themes.VKThemeHelper;
|
||||
|
||||
import ru.vtosters.lite.hooks.VKUIHook;
|
||||
|
||||
public class ThemeChanging{
|
||||
public static void changeTheme(Activity activity, float[] f){
|
||||
if (getBoolValue("systemtheme", true)) {
|
||||
new VkAlertDialog.Builder(activity)
|
||||
.setTitle(getString("warning"))
|
||||
.setMessage(getString("system_theme_warning"))
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(getString("proxy_disable"), (dialogInterface, i) -> { // Отключить
|
||||
edit().putBoolean("systemtheme", false).commit();
|
||||
VKThemeHelper.b(activity, f);
|
||||
VKUIHook.clearWebCache();
|
||||
})
|
||||
.setNeutralButton(getString("cancel"), null)
|
||||
.show();
|
||||
} else {
|
||||
VKThemeHelper.b(activity, f);
|
||||
VKUIHook.clearWebCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package ru.vtosters.lite.ui.dialogs;
|
||||
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isApiProxyEnabled;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.isAnyProxyEnabled;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
@@ -25,7 +25,7 @@ public class VKIDProtection {
|
||||
// android.content.DialogInterface.OnClickListener
|
||||
builder.setNeutralButton(getString("vkiddisable"), (dialogInterface, i) -> {
|
||||
edit().putBoolean("showAlertVkId", false).apply();
|
||||
VKUIwrapper.setLink((isApiProxyEnabled() ? "https://id.vk.ru/account" : "https://" + getApi() + "/_/id.vk.ru/account"));
|
||||
VKUIwrapper.setLink((isAnyProxyEnabled() ? "https://id.vk.com/account" : "https://" + getApi() + "/_/id.vk.com/account"));
|
||||
Intent a2 = new Navigator(VKUIwrapper.class).b(activity);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
activity.startActivity(a2);
|
||||
|
||||
@@ -22,8 +22,6 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import ru.vtosters.lite.ui.adapters.CategorizedAdapter;
|
||||
import ru.vtosters.lite.ui.components.DockBarEditorManager;
|
||||
import ru.vtosters.lite.ui.components.ItemMovingCallback;
|
||||
|
||||
@@ -2,13 +2,11 @@ package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.setupFilters;
|
||||
import static ru.vtosters.lite.utils.Preferences.copyright_post;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -25,15 +23,15 @@ import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
import ru.vtosters.lite.ui.components.NewsfeedListManager;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class FeedFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class FeedFragment extends MaterialPreferenceToolbarFragment{
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(getIdentifier("preferences_feed", "xml"));
|
||||
prefs();
|
||||
}
|
||||
|
||||
private void prefs() {
|
||||
private void prefs(){
|
||||
findPreference("officialnewssett").setOnPreferenceClickListener(new openofficialsett());
|
||||
findPreference("cringecopyright").setEnabled(!copyright_post());
|
||||
|
||||
@@ -41,6 +39,21 @@ public class FeedFragment extends MaterialPreferenceToolbarFragment {
|
||||
findPreference("sourcenamefilter").setSummary(count(getPrefsValue("sourcenamefilter")));
|
||||
findPreference("linkfilter").setSummary(count(getPrefsValue("linkfilter")));
|
||||
|
||||
findPreference("spamfilters").setOnPreferenceClickListener(preference -> {
|
||||
setupFilters();
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("sourcenamefilter").setOnPreferenceClickListener(preference -> {
|
||||
setupFilters();
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("linkfilter").setOnPreferenceClickListener(preference -> {
|
||||
setupFilters();
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("whitelisted_ad_groups").setSummary(countSet("whitelisted_ad_groups"));
|
||||
findPreference("whitelisted_filters_groups").setSummary(countSet("whitelisted_filters_groups"));
|
||||
|
||||
@@ -68,7 +81,7 @@ public class FeedFragment extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
}
|
||||
|
||||
private String count(String text) {
|
||||
private String count(String text){
|
||||
// count comma separated words in string
|
||||
var count = text.split(", ").length;
|
||||
|
||||
@@ -79,7 +92,7 @@ public class FeedFragment extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void remdialog(String key, Context context) {
|
||||
private void remdialog(String key, Context context){
|
||||
VkAlertDialog.Builder builder = new VkAlertDialog.Builder(context);
|
||||
builder.setTitle(AndroidUtils.getString("warning"));
|
||||
builder.setMessage(AndroidUtils.getString("delete_elements_confirm"));
|
||||
@@ -87,12 +100,13 @@ public class FeedFragment extends MaterialPreferenceToolbarFragment {
|
||||
builder.setPositiveButton(AndroidUtils.getString("yes"), (dialogInterface, i) -> {
|
||||
edit().remove(key).apply();
|
||||
sendToast(AndroidUtils.getString("elements_deleted_success"));
|
||||
setupFilters();
|
||||
});
|
||||
builder.setNegativeButton(AndroidUtils.getString("cancel"), (dialogInterface, i) -> dialogInterface.dismiss());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private String countSet(String key) {
|
||||
private String countSet(String key){
|
||||
var set = getDefaultPrefs().getStringSet(key, null);
|
||||
StringBuilder str = new StringBuilder();
|
||||
if (set != null) {
|
||||
@@ -112,15 +126,16 @@ public class FeedFragment extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
public boolean onPreferenceTreeClick(Preference preference){
|
||||
findPreference("cringecopyright").setEnabled(!copyright_post());
|
||||
setupFilters();
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
public class openofficialsett implements Preference.OnPreferenceClickListener {
|
||||
public class openofficialsett implements Preference.OnPreferenceClickListener{
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Context context = getContext();
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(NewsfeedSettingsFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
|
||||
@@ -2,9 +2,12 @@ package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.isTablet;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplicationWithTimer;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@@ -26,11 +29,20 @@ public class InterfaceFragment extends MaterialPreferenceToolbarFragment {
|
||||
findPreference("swipe").setOnPreferenceClickListener(new restart());
|
||||
findPreference("is_likes_on_right").setOnPreferenceClickListener(new restart());
|
||||
|
||||
if (isTablet()){
|
||||
findPreference("menusett").setVisible(false);
|
||||
findPreference("swipe").setVisible(false);
|
||||
}
|
||||
|
||||
findPreference("customrounding").setOnPreferenceClickListener(preference -> {
|
||||
RoundingSeekbarDialog.dialog(getContext());
|
||||
return true;
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33){
|
||||
findPreference("anim_rtrn_type").setVisible(false);
|
||||
}
|
||||
|
||||
if (getPreferences().getInt("pic_rounding", 0) == 0) {
|
||||
findPreference("customrounding").setSummary(AndroidUtils.getString("disabled"));
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.isVkxInstalled;
|
||||
import static ru.vtosters.lite.music.Scrobbler.isLoggedIn;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
@@ -9,12 +10,12 @@ import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
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.NewsFeedFiltersUtils.setupFilters;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getAlertStyle;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getSTextAttr;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@@ -34,25 +35,26 @@ import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.core.network.Network;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.downloaders.AudioDownloader;
|
||||
import ru.vtosters.lite.downloaders.VideoDownloader;
|
||||
import ru.vtosters.lite.music.Scrobbler;
|
||||
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.FileUriUtils;
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
|
||||
public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
private final int REQUEST_CODE_SET_DOWNLOAD_DIRECTORY = 665;
|
||||
private final int REQUEST_CODE_SET_MUSIC_DIRECTORY = 666;
|
||||
private final int REQUEST_CODE_SET_PHOTOS_DIRECTORY = 667;
|
||||
private final int REQUEST_CODE_SET_VIDEOS_DIRECTORY = 668;
|
||||
|
||||
private static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
@@ -63,31 +65,6 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
var path = data.getData();
|
||||
if (path != null) {
|
||||
var prefs = getPreferences();
|
||||
var editor = prefs.edit();
|
||||
var actualPath = FileUriUtils.getFullPathFromTreeUri(path, getContext());
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_SET_DOWNLOAD_DIRECTORY:
|
||||
editor.putString("downloads_directory", actualPath);
|
||||
break;
|
||||
case REQUEST_CODE_SET_MUSIC_DIRECTORY:
|
||||
editor.putString("music_directory", actualPath);
|
||||
break;
|
||||
case REQUEST_CODE_SET_PHOTOS_DIRECTORY:
|
||||
editor.putString("photos_directory", actualPath);
|
||||
break;
|
||||
case REQUEST_CODE_SET_VIDEOS_DIRECTORY:
|
||||
editor.putString("videos_directory", actualPath);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,7 +76,7 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
private void prefs() {
|
||||
findPreference("download_video").setOnPreferenceClickListener(new MediaFragment.download());
|
||||
findPreference("clearvideohistory").setOnPreferenceClickListener(preference -> {
|
||||
deleteVideoHistory();
|
||||
deleteVideoHistoryDialog(requireContext());
|
||||
return true;
|
||||
});
|
||||
findPreference("dateformat").setOnPreferenceChangeListener(new MediaFragment.restart());
|
||||
@@ -112,56 +89,31 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("downloads_directory").setSummary(
|
||||
AndroidUtils.getString("current_download_folder") + " " + Preferences.getDownloadsDir()
|
||||
);
|
||||
|
||||
findPreference("photos_directory").setSummary(
|
||||
AndroidUtils.getString("current_download_folder") + " " + Preferences.getPhotosDir()
|
||||
);
|
||||
|
||||
findPreference("videos_directory").setSummary(
|
||||
AndroidUtils.getString("current_download_folder") + " " + Preferences.getVideosDir()
|
||||
);
|
||||
|
||||
findPreference("music_directory").setSummary(
|
||||
AndroidUtils.getString("current_download_folder") + " " + Preferences.getMusicDir()
|
||||
);
|
||||
|
||||
findPreference("downloads_directory").setOnPreferenceClickListener(preference -> {
|
||||
var intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
startActivityForResult(intent, REQUEST_CODE_SET_DOWNLOAD_DIRECTORY);
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("photos_directory").setOnPreferenceClickListener(preference -> {
|
||||
var intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
startActivityForResult(intent, REQUEST_CODE_SET_PHOTOS_DIRECTORY);
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("videos_directory").setOnPreferenceClickListener(preference -> {
|
||||
var intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
startActivityForResult(intent, REQUEST_CODE_SET_VIDEOS_DIRECTORY);
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("music_directory").setOnPreferenceClickListener(preference -> {
|
||||
var intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
startActivityForResult(intent, REQUEST_CODE_SET_MUSIC_DIRECTORY);
|
||||
return true;
|
||||
});
|
||||
|
||||
if (isLoggedIn()) {
|
||||
findPreference("lastfm_auth").setSummary(AndroidUtils.getString("lastfm_authorized_as") + " " + Scrobbler.getUserName());
|
||||
} else {
|
||||
findPreference("lastfm_enabled").setEnabled(false);
|
||||
}
|
||||
|
||||
findPreference("cached_tracks").setSummary(String.format(AndroidUtils.getString("cached_tracks_counter"), CacheDatabaseDelegate.getTrackCount()));
|
||||
findPreference("cached_tracks").setOnPreferenceClickListener(preference -> {
|
||||
if (CacheDatabaseDelegate.getTrackCount() == 0){
|
||||
sendToast(AndroidUtils.getString("no_cache_error"));
|
||||
} else {
|
||||
delcache(requireContext());
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("audio_download").setOnPreferenceClickListener(preference -> {
|
||||
dlaudio(requireContext());
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!isVkxInstalled()){
|
||||
findPreference("vkx_sett").setVisible(false);
|
||||
}
|
||||
|
||||
findPreference("select_photo_search_engine").setOnPreferenceClickListener(preference -> {
|
||||
var items = Arrays.asList(
|
||||
new ImagineArrayAdapter.ImagineArrayAdapterItem(getIdentifier("yandex", "drawable"), "Yandex"),
|
||||
@@ -241,17 +193,56 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
alert.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(getResources().getColor(com.vtosters.lite.R.color.red));
|
||||
}
|
||||
|
||||
public static void deleteVideoHistory() {
|
||||
private void delcache(Context ctx) {
|
||||
VkAlertDialog.Builder alertDialog = new VkAlertDialog.Builder(ctx);
|
||||
alertDialog.setTitle(AndroidUtils.getString("warning"));
|
||||
alertDialog.setMessage(AndroidUtils.getString("cached_tracks_remove_confirm"));
|
||||
alertDialog.setPositiveButton(AndroidUtils.getString("yes"), (dialog, which) -> {
|
||||
executor.submit(CacheDatabaseDelegate::clear);
|
||||
});
|
||||
alertDialog.setNeutralButton(AndroidUtils.getString("no"), (dialog, which) -> {
|
||||
dialog.cancel();
|
||||
});
|
||||
var alert = alertDialog.create();
|
||||
alert.show();
|
||||
alert.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(getAccentColor());
|
||||
alert.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(getResources().getColor(com.vtosters.lite.R.color.red));
|
||||
}
|
||||
|
||||
private void dlaudio(Context ctx) {
|
||||
VkAlertDialog.Builder alertDialog = new VkAlertDialog.Builder(ctx);
|
||||
alertDialog.setTitle(AndroidUtils.getString("download_method"));
|
||||
alertDialog.setMessage(AndroidUtils.getString("download_method_desc"));
|
||||
alertDialog.setPositiveButton(AndroidUtils.getString("download_method_cache"), (dialog, which) -> {
|
||||
executor.submit(AudioDownloader::cacheAllAudios);
|
||||
});
|
||||
alertDialog.setNegativeButton(AndroidUtils.getString("download_method_mp3"), (dialog, which) -> {
|
||||
executor.submit(AudioDownloader::downloadAllAudios);
|
||||
});
|
||||
var alert = alertDialog.create();
|
||||
alert.show();
|
||||
alert.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(getAccentColor());
|
||||
alert.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(getAccentColor());;
|
||||
}
|
||||
|
||||
public void deleteVideoHistory() {
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
var request = new Request.a()
|
||||
.b("https://" + getApi() + "/method/" + "video.clearViewingHistoryRecords" + "?https=1" + "&access_token=" + getUserToken() + "&v=5.187")
|
||||
.b("https://" + getApi() + "/method/" + "video.clearViewingHistoryRecords" + "?https=1" + "&access_token=" + getUserToken() + "&v=5.119")
|
||||
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8"))
|
||||
.a();
|
||||
|
||||
try {
|
||||
var response = new OkHttpClient().a(request).execute().a().g();
|
||||
Log.d("VideoHistory", response);
|
||||
var response = new JSONObject(new OkHttpClient().a(request).execute().a().g());
|
||||
|
||||
if (response.optInt("response") == 1){
|
||||
requireActivity().runOnUiThread(() -> sendToast(AndroidUtils.getString("video_history_cleaned")));
|
||||
} else {
|
||||
requireActivity().runOnUiThread(() -> sendToast(AndroidUtils.getString("delete_video_history_error")));
|
||||
}
|
||||
|
||||
Log.d("VideoHistory", response.toString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -261,8 +252,18 @@ public class MediaFragment extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
thread.start();
|
||||
}
|
||||
|
||||
sendToast(AndroidUtils.getString("video_history_cleaned"));
|
||||
private void deleteVideoHistoryDialog(Context context){
|
||||
VkAlertDialog.Builder builder = new VkAlertDialog.Builder(context);
|
||||
builder.setTitle(AndroidUtils.getString("warning"));
|
||||
builder.setMessage(AndroidUtils.getString("delete_video_history_confirm"));
|
||||
builder.setCancelable(false);
|
||||
builder.setPositiveButton(AndroidUtils.getString("yes"), (dialogInterface, i) -> {
|
||||
deleteVideoHistory();
|
||||
});
|
||||
builder.setNegativeButton(AndroidUtils.getString("cancel"), (dialogInterface, i) -> dialogInterface.dismiss());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
public static void download(Context ctx) {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.*;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.isTablet;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplicationWithTimer;
|
||||
import static ru.vtosters.lite.utils.Preferences.autoalltranslate;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.*;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.recolorDrawable;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
@@ -22,12 +23,9 @@ import com.vk.navigation.Navigator;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import ru.vtosters.lite.ui.adapters.ImagineArrayAdapter;
|
||||
import ru.vtosters.lite.ui.wallpapers.WallpaperMenuFragment;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
@Override
|
||||
@@ -72,6 +70,11 @@ public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
findPreference("vkme_notifs").setEnabled(vkme());
|
||||
findPreference("wallpapers").setIcon(recolorDrawable(getGlobalContext().getDrawable(getIdentifier("ic_media_outline_28", "drawable"))));
|
||||
findPreference("vkme").setIcon(getIdentifier("ic_vkme_28", "drawable"));
|
||||
|
||||
if (isTablet()){
|
||||
findPreference("alteremoji").setVisible(false);
|
||||
findPreference("vkmesett").setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,10 +106,11 @@ public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class openwp implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(WallpaperMenuFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
// sendToast("Обои временно недоступны. Следите за новостями на @vtosters в Telegram");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,9 @@ import static ru.vtosters.lite.ui.components.BackupManager.deletePrefs;
|
||||
import static ru.vtosters.lite.ui.components.BackupManager.restoreBackup;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.CacheUtils.deleteCache;
|
||||
import static ru.vtosters.lite.utils.ContactsUtils.setContactsSync;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplication;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
|
||||
|
||||
@@ -57,6 +56,7 @@ 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.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ContactsUtils;
|
||||
|
||||
public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
private static final int VK_ADMIN_TOKEN_REQUEST_CODE = 1;
|
||||
@@ -96,9 +96,8 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("resetfolders").setOnPreferenceClickListener(preference -> {
|
||||
edit().remove("photos_directory").remove("videos_directory").remove("audios_directory").remove("downloads_directory").apply();
|
||||
Toast.makeText(getContext(), AndroidUtils.getString("download_folders_reseted"), LENGTH_SHORT).show();
|
||||
findPreference("contacts_sync").setOnPreferenceClickListener((preference) -> {
|
||||
ContactsUtils.getContactsStatus(requireContext());
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -124,7 +123,11 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
break;
|
||||
}
|
||||
|
||||
findPreference("deleteprefs").setOnPreferenceClickListener(new deleteprefs());
|
||||
findPreference("deleteprefs").setOnPreferenceClickListener(preference -> {
|
||||
delprefs(getContext());
|
||||
return true;
|
||||
});
|
||||
|
||||
findPreference("saveonlines").setOnPreferenceClickListener(new onlines());
|
||||
|
||||
findPreference("saveprefs").setOnPreferenceClickListener(new saveprefs());
|
||||
@@ -303,13 +306,17 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
}
|
||||
|
||||
public static class deleteprefs implements Preference.OnPreferenceClickListener {
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
private void delprefs(Context context) {
|
||||
VkAlertDialog.Builder builder = new VkAlertDialog.Builder(context);
|
||||
builder.setTitle(AndroidUtils.getString("warning"));
|
||||
builder.setMessage(AndroidUtils.getString("settings_reset_confirm"));
|
||||
builder.setCancelable(false);
|
||||
builder.setPositiveButton(AndroidUtils.getString("yes"), (dialogInterface, i) -> {
|
||||
deletePrefs();
|
||||
restartApplication();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(AndroidUtils.getString("cancel"), (dialogInterface, i) -> dialogInterface.dismiss());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
class c implements Preference.OnPreferenceClickListener {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static ru.vtosters.lite.proxy.RandomProxy.setupNewProxy;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
|
||||
@@ -11,7 +10,6 @@ import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import ru.vtosters.lite.proxy.RandomProxy;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class ProxySettingsFragment extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
@@ -3,6 +3,7 @@ package ru.vtosters.lite.ui.fragments;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.isTablet;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplicationWithTimer;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -32,19 +33,19 @@ public class ThemesFragment extends MaterialPreferenceToolbarFragment {
|
||||
findPreference("darktheme").setOnPreferenceChangeListener(new restartdark());
|
||||
findPreference("lighttheme").setOnPreferenceChangeListener(new restartlight());
|
||||
findPreference("iconmanager").setOnPreferenceClickListener(new openicons());
|
||||
findPreference("dockbar_tab_titles").setOnPreferenceChangeListener((preference, o) -> {
|
||||
getPreferences().edit().putBoolean("dockbar_tab_titles", (boolean) o).commit();
|
||||
LifecycleUtils.restartApplication();
|
||||
return false;
|
||||
});
|
||||
findPreference("dockbar_tab_titles").setOnPreferenceClickListener(new restart());
|
||||
findPreference("dockbar_accent").setOnPreferenceClickListener(new restart());
|
||||
findPreference("dockcounter").setOnPreferenceClickListener(new restart());
|
||||
|
||||
if (isTablet()){
|
||||
findPreference("dockbarsett").setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
public class openicons implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(IconsFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
|
||||
@@ -14,7 +14,7 @@ public class VKPayFragment extends FragmentImpl {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
VKUIwrapper.setLink("https://vk.ru/vkpay");
|
||||
VKUIwrapper.setLink("https://vk.com/vkpay");
|
||||
Intent a2 = new Navigator(VKUIwrapper.class).b(getActivity());
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(a2);
|
||||
|
||||
@@ -12,10 +12,12 @@ import static ru.vtosters.lite.utils.AccountManagerUtils.isVKTester;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.isTablet;
|
||||
import static ru.vtosters.lite.utils.CacheUtils.humanReadableByteCountBin;
|
||||
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.devmenu;
|
||||
import static ru.vtosters.lite.utils.Preferences.disableSettingsSumms;
|
||||
import static ru.vtosters.lite.utils.Preferences.hasSpecialVerif;
|
||||
@@ -30,6 +32,7 @@ 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;
|
||||
|
||||
@@ -43,6 +46,7 @@ import android.os.Bundle;
|
||||
import com.aefyr.tsg.g2.TelegramStickersService;
|
||||
import com.vk.about.AboutAppFragment;
|
||||
import com.vk.balance.BalanceFragment;
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.navigation.Navigator;
|
||||
import com.vk.notifications.settings.NotificationsSettingsFragment;
|
||||
import com.vk.webapp.fragments.PrivacyFragment;
|
||||
@@ -55,13 +59,16 @@ import com.vtosters.lite.fragments.w2.BlacklistFragment;
|
||||
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.hooks.ui.SystemThemeChangerHook;
|
||||
import ru.vtosters.lite.ui.components.DockBarEditorManager;
|
||||
import ru.vtosters.lite.ui.components.SuperAppEditorManager;
|
||||
import ru.vtosters.lite.ui.dialogs.OTADialog;
|
||||
import ru.vtosters.lite.ui.fragments.tgstickers.StickersFragment;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.CacheUtils;
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
import ru.vtosters.lite.utils.SSFSUtils;
|
||||
|
||||
public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
@@ -123,13 +130,18 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
return AndroidUtils.getString("autoclearcachesumm") + " " + humanReadableByteCountBin(CacheUtils.getInstance().size);
|
||||
}
|
||||
|
||||
private void switchTheme(boolean isDarkTheme) {
|
||||
setTheme(isDarkTheme ? getDarkTheme() : getLightTheme(), requireActivity());
|
||||
edit().putBoolean("isdark", isDarkTheme).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
|
||||
var feedsumm = getValAsString("vtlfeedsumm", ads());
|
||||
var docksumm = getDocksumm();
|
||||
var msgsumm = getValAsString("vtlmsgsumm", vkme());
|
||||
var msgsumm = isTablet() ? getValAsString("autotranslate_title", autotranslate()) : getValAsString("vtlmsgsumm", vkme());
|
||||
var activitysumm = getValAsString("vtlactivitysumm", offline());
|
||||
var themessumm = getValAsString("vtlthemessumm", navbar());
|
||||
var tgssumm = getTGSsumm();
|
||||
@@ -147,44 +159,58 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
addPreferenceDrawable(this, "", getUsername(), hasVerification() ? AndroidUtils.getString("thanksfordonate") : AndroidUtils.getString("getdonate"), getDrawableFromUrl(getUserPhoto(), "ic_user_circle_outline_28", true, true), preference -> {
|
||||
try {
|
||||
VKAuth.a("logout", false);
|
||||
} catch (Exception ignored) { }
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
var intent = new Intent(getContext(), MainActivity.class);
|
||||
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);
|
||||
getContext().startActivity(intent);
|
||||
requireContext().startActivity(intent);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreferenceCategory(this, AndroidUtils.getString("vtsettdarktheme"));
|
||||
|
||||
addMaterialSwitchPreference(this, "isdark", AndroidUtils.getString("vtsettdarktheme"), "", "ic_palette_outline_28", false, (preference, o) -> {
|
||||
boolean value = (boolean) o;
|
||||
addMaterialSwitchPreference(this, "", AndroidUtils.getString("vtsettdarktheme"), "", "ic_palette_outline_28", isDarkTheme(), (preference, o) -> {
|
||||
final var switchPreference = (MaterialSwitchPreference) preference;
|
||||
final var isDarkTheme = !switchPreference.isChecked();
|
||||
|
||||
if (!value) { // inverted
|
||||
setTheme(getLightTheme(), this.getActivity());
|
||||
} else {
|
||||
setTheme(getDarkTheme(), this.getActivity());
|
||||
if (Preferences.systemtheme()) {
|
||||
new VkAlertDialog.Builder(requireActivity())
|
||||
.setTitle(AndroidUtils.getString("warning"))
|
||||
.setMessage(AndroidUtils.getString("system_theme_warning"))
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(AndroidUtils.getString("proxy_disable"), (dialogInterface, i) -> { // Отключить
|
||||
switchPreference.setChecked(isDarkTheme);
|
||||
((MaterialSwitchPreference) findPreference("systemtheme")).setChecked(false);
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
switchTheme(isDarkTheme);
|
||||
});
|
||||
})
|
||||
.setNeutralButton(AndroidUtils.getString("cancel"), null)
|
||||
.show();
|
||||
return false;
|
||||
}
|
||||
|
||||
edit().putBoolean("isdark", value).commit();
|
||||
switchTheme(isDarkTheme);
|
||||
return true;
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 28 && false) { // TODO refactoring system theme
|
||||
addMaterialSwitchPreference(this, "systemtheme", AndroidUtils.getString("appearance_theme_use_system"), AndroidUtils.getString("appearance_theme_use_system_summary"), "ic_recent_outline_28", true, (preference, o) -> {
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
addMaterialSwitchPreference(this, "systemtheme", AndroidUtils.getString("appearance_theme_use_system"), "", "ic_recent_outline_28", true, (preference, o) -> {
|
||||
boolean value = (boolean) o;
|
||||
|
||||
edit().putBoolean("systemtheme", value).commit();
|
||||
|
||||
SystemThemeChangerHook.onThemeChanged(getResources().getConfiguration());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
if (!isGmsInstalled()) {
|
||||
addPreference(this, "", AndroidUtils.getString("installgms"), "", "ic_about_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(InstallGMSFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -196,7 +222,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
addPreferenceCategory(this, AndroidUtils.getString("sett_debug"));
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("sett_debug"), "", "ic_bug_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(SettingsDebugFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -213,7 +239,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
addPreferenceCategory(this, AndroidUtils.getString("vtsettaccount"));
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("vkconnect"), "", "ic_user_circle_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
VKUIwrapper.officalLinks("account");
|
||||
Intent a2 = new Navigator(VKUIwrapper.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
@@ -222,7 +248,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("privacy_settings"), "", "ic_privacy_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(PrivacyFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -230,7 +256,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("sett_account"), "", "ic_user_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(SettingsAccountFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -239,7 +265,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
if (isVKTester()) {
|
||||
addPreference(this, "", AndroidUtils.getString("bugs"), "", "ic_bug_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
VKUIwrapper.officalLinks("bugs");
|
||||
Intent a2 = new Navigator(VKUIwrapper.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
@@ -249,7 +275,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("vtssfs"), ssfs, "ic_link_circle_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
VKUIwrapper.setLink(SSFSUtils.getSSFSLink());
|
||||
Intent a2 = new Navigator(VKUIwrapper.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
@@ -260,7 +286,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
addPreferenceCategory(this, AndroidUtils.getString("notification_settings"));
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("sett_general"), "", "ic_settings_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(SettingsGeneralFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -268,7 +294,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("blacklist"), "", "ic_users_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(BlacklistFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -276,7 +302,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("sett_notifications"), "", "ic_menu_notification_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(NotificationsSettingsFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -285,7 +311,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
if (VKAccountManager.d().isMusicSubs()) {
|
||||
addPreference(this, "", AndroidUtils.getString("subscription_music"), "", "ic_music_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(MusicSubscriptionControlFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -294,7 +320,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("votes"), "", "ic_coins_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(BalanceFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -305,36 +331,38 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
if (!vkme()) {
|
||||
addPreference(this, "", AndroidUtils.getString("vtlfeed"), feedsumm, "ic_newsfeed_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(FeedFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("dockbar_editor"), docksumm, "ic_list_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Intent intent = new Navigator(DockBarEditorFragment.class).b(context);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
return false;
|
||||
});
|
||||
|
||||
if (milkshake() && superapp()) {
|
||||
addPreference(this, "", AndroidUtils.getString("superapp_editor"), superapp, "ic_services_outline_28", (preference) -> {
|
||||
Context context = getContext();
|
||||
Intent intent = new Navigator(SuperAppEditorFragment.class).b(context);
|
||||
if (!isTablet()) {
|
||||
addPreference(this, "", AndroidUtils.getString("dockbar_editor"), docksumm, "ic_list_outline_28", preference -> {
|
||||
Context context = requireContext();
|
||||
Intent intent = new Navigator(DockBarEditorFragment.class).b(context);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
if (milkshake() && superapp()) {
|
||||
addPreference(this, "", AndroidUtils.getString("superapp_editor"), superapp, "ic_services_outline_28", (preference) -> {
|
||||
Context context = requireContext();
|
||||
Intent intent = new Navigator(SuperAppEditorFragment.class).b(context);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
addPreference(this, "", AndroidUtils.getString("warning"), AndroidUtils.getString("vkme_mode_info"), "ic_about_outline_28", preference -> false);
|
||||
}
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("vtlmedia"), mediasumm, "ic_media_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(MediaFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -342,7 +370,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("vtlmessages"), msgsumm, "ic_message_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(MessagesFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -350,7 +378,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("vtlactivity"), activitysumm, "ic_write_outline_28_new_accent", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(ActivityFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -358,7 +386,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("vtlthemes"), themessumm, "ic_write_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(ThemesFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -366,7 +394,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("vtltgs"), tgssumm, "ic_telegram_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(StickersFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -374,7 +402,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("vtlinterface"), interfacesumm, "ic_interface_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(InterfaceFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -382,7 +410,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("vtlproxy"), proxysumm, "ic_globe_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(ProxySettingsFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -390,7 +418,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("vtlother"), othersumm, "ic_more_horizontal_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(OtherFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -400,7 +428,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
addPreferenceCategory(this, AndroidUtils.getString("vtsettaboutmod"));
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("menu_about"), about, "ic_about_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Context context = requireContext();
|
||||
Intent a2 = new Navigator(AboutAppFragment.class).b(context);
|
||||
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(a2);
|
||||
@@ -408,17 +436,17 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("opencommit"), "", "ic_link_outline_28", preference -> {
|
||||
getContext().startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse(getCommitLink())));
|
||||
requireContext().startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse(getCommitLink())));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("vtfaq"), AndroidUtils.getString("vtfaqsumm"), "ic_help_outline_28", preference -> {
|
||||
getContext().startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse("https://t.me/s/vtosters_faq")));
|
||||
requireContext().startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse("https://t.me/s/vtosters_faq")));
|
||||
return false;
|
||||
});
|
||||
|
||||
addPreference(this, "", AndroidUtils.getString("reportbug"), AndroidUtils.getString("reportbugsumm"), "ic_bug_outline_28", preference -> {
|
||||
getContext().startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse("https://github.com/vtosters/lite/issues")));
|
||||
requireContext().startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse("https://github.com/vtosters/lite/issues")));
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -429,14 +457,6 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
OTADialog.checkUpdates(getActivity());
|
||||
return false;
|
||||
});
|
||||
|
||||
addMaterialSwitchPreference(this, "checkupdates", AndroidUtils.getString("checkupdates"), "", "ic_recent_outline_28", true, (preference, o) -> {
|
||||
boolean value = (boolean) o;
|
||||
|
||||
edit().putBoolean("checkupdates", value).commit();
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
|
||||
@@ -40,10 +41,10 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.vk.navigation.Navigator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
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;
|
||||
|
||||
@@ -121,6 +122,11 @@ public class StickersFragment extends BaseToolbarFragment {
|
||||
|
||||
mAdapter = new StickerPackAdapter();
|
||||
RecyclerView mRecycler = new RecyclerView(getContext());
|
||||
|
||||
var callback = new StickerTouchHelperCallback(mAdapter);
|
||||
var touchHelper = new ItemTouchHelper(callback);
|
||||
touchHelper.attachToRecyclerView(mRecycler);
|
||||
|
||||
mRecycler.setAdapter(mAdapter);
|
||||
mRecycler.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
|
||||
layout.addView(mRecycler, new ViewGroup.LayoutParams(-1, -1));
|
||||
|
||||
@@ -3,18 +3,18 @@ package ru.vtosters.lite.ui.wallpapers;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
||||
public class ConvolutionMatrix {
|
||||
public class ConvolutionMatrix{
|
||||
public static final int SIZE = 3;
|
||||
|
||||
public double[][] Matrix;
|
||||
public double Factor = 1;
|
||||
public double Offset = 1;
|
||||
|
||||
public ConvolutionMatrix(int size) {
|
||||
public ConvolutionMatrix(int size){
|
||||
Matrix = new double[size][size];
|
||||
}
|
||||
|
||||
public static Bitmap computeConvolution3x3(Bitmap src, ConvolutionMatrix matrix) {
|
||||
public static Bitmap computeConvolution3x3(Bitmap src, ConvolutionMatrix matrix){
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
Bitmap result = Bitmap.createBitmap(width, height, src.getConfig());
|
||||
@@ -81,7 +81,7 @@ public class ConvolutionMatrix {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setAll(double value) {
|
||||
public void setAll(double value){
|
||||
for (int x = 0; x < SIZE; ++x) {
|
||||
for (int y = 0; y < SIZE; ++y) {
|
||||
Matrix[x][y] = value;
|
||||
@@ -89,7 +89,7 @@ public class ConvolutionMatrix {
|
||||
}
|
||||
}
|
||||
|
||||
public void applyConfig(double[][] config) {
|
||||
public void applyConfig(double[][] config){
|
||||
for (int x = 0; x < SIZE; ++x) {
|
||||
for (int y = 0; y < SIZE; ++y) {
|
||||
Matrix[x][y] = config[x][y];
|
||||
|
||||
@@ -2,7 +2,7 @@ package ru.vtosters.lite.ui.wallpapers;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getResources;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.Preferences.hasVerification;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
@@ -13,22 +13,46 @@ import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.medianative.MediaNative;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class ImageFilters {
|
||||
public class ImageFilters{
|
||||
public static final double PI = 3.14159d;
|
||||
public static final double HALF_CIRCLE_DEGREE = 180d;
|
||||
public static final double RANGE = 256d;
|
||||
public static final int COLOR_MIN = 0x00;
|
||||
public static final int COLOR_MAX = 0xFF;
|
||||
|
||||
public static Drawable getFilteredDrawable(Drawable orig) {
|
||||
public static Drawable getFilteredDrawable(Drawable orig){
|
||||
if (orig == null) return null;
|
||||
if (!(orig instanceof BitmapDrawable)) return orig;
|
||||
Bitmap instance = ((BitmapDrawable) orig).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
|
||||
|
||||
if (!getPreferences().getString("msg_blur_radius", "disabled").equals("disabled")) {
|
||||
orig = getBlurredWallpaper(orig, getRadius());
|
||||
}
|
||||
|
||||
if (!getPreferences().getString("msg_dim", "off").equals("off")) {
|
||||
orig = getDimmed(orig);
|
||||
}
|
||||
|
||||
if (!getPreferences().getString("msg_mosaic", "disabled").equals("disabled")) {
|
||||
orig = getMosaic(orig);
|
||||
}
|
||||
|
||||
if (!hasVerification()) {
|
||||
return orig;
|
||||
}
|
||||
|
||||
if (getPreferences().getBoolean("msg_monochrome", false)) {
|
||||
orig = getMonochrome(orig);
|
||||
}
|
||||
|
||||
Bitmap bm = ((BitmapDrawable) orig).getBitmap();
|
||||
|
||||
Bitmap instance = bm.copy(Bitmap.Config.ARGB_8888, true);
|
||||
|
||||
if (getPreferences().getBoolean("msg_invert", false)) {
|
||||
instance = applyInvertEffect(instance);
|
||||
@@ -57,11 +81,26 @@ public class ImageFilters {
|
||||
return new BitmapDrawable(getResources(), instance);
|
||||
}
|
||||
|
||||
public static Drawable getBlurredWallpaper(Drawable orig, int radius) {
|
||||
private static int getRadius(){
|
||||
String radius = getPreferences().getString("msg_blur_radius", "disabled");
|
||||
switch(radius) {
|
||||
case "low":
|
||||
return 8;
|
||||
case "med":
|
||||
return 14;
|
||||
default:
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
||||
public static Drawable getBlurredWallpaper(Drawable orig, int radius){
|
||||
try {
|
||||
if (orig == null) return null;
|
||||
if (!(orig instanceof BitmapDrawable)) return orig; // we need only BitmapDrawable
|
||||
Bitmap instance = ((BitmapDrawable) orig).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
|
||||
Bitmap bm = ((BitmapDrawable) orig).getBitmap();
|
||||
|
||||
Bitmap instance = bm.copy(Bitmap.Config.ARGB_8888, true);
|
||||
|
||||
MediaNative.blurBitmap(instance, radius);
|
||||
return new BitmapDrawable(getResources(), instance);
|
||||
} catch (Exception e) {
|
||||
@@ -70,15 +109,20 @@ public class ImageFilters {
|
||||
}
|
||||
}
|
||||
|
||||
public static Drawable getMosaic(Drawable orig) {
|
||||
public static Drawable getMosaic(Drawable orig){
|
||||
int scale = 100;
|
||||
|
||||
if (orig == null) return null;
|
||||
if (!(orig instanceof BitmapDrawable)) return orig;
|
||||
Bitmap instance = ((BitmapDrawable) orig).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
|
||||
Bitmap bm = ((BitmapDrawable) orig).getBitmap();
|
||||
|
||||
|
||||
Bitmap instance = bm.copy(Bitmap.Config.ARGB_8888, true);
|
||||
|
||||
|
||||
String radius = getPreferences().getString("msg_mosaic", "disabled");
|
||||
|
||||
switch (radius) {
|
||||
switch(radius) {
|
||||
case "high":
|
||||
scale = 25;
|
||||
break;
|
||||
@@ -95,12 +139,15 @@ public class ImageFilters {
|
||||
return new BitmapDrawable(getResources(), mosaicBitmap);
|
||||
}
|
||||
|
||||
public static Drawable getDimmed(Drawable orig) {
|
||||
public static Drawable getDimmed(Drawable orig){
|
||||
if (orig == null) return null;
|
||||
if (!(orig instanceof BitmapDrawable)) return orig;
|
||||
Bitmap instance = ((BitmapDrawable) orig).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
|
||||
Bitmap bm = ((BitmapDrawable) orig).getBitmap();
|
||||
|
||||
Bitmap instance = bm.copy(Bitmap.Config.ARGB_8888, true);
|
||||
|
||||
String radius = getPreferences().getString("msg_dim", "disabled");
|
||||
switch (radius) {
|
||||
switch(radius) {
|
||||
case "dim_black":
|
||||
darken(instance);
|
||||
case "dim_white":
|
||||
@@ -109,10 +156,12 @@ public class ImageFilters {
|
||||
return new BitmapDrawable(getResources(), instance);
|
||||
}
|
||||
|
||||
public static Drawable getMonochrome(Drawable orig) {
|
||||
public static Drawable getMonochrome(Drawable orig){
|
||||
if (orig == null) return null;
|
||||
if (!(orig instanceof BitmapDrawable)) return orig;
|
||||
Bitmap instance = ((BitmapDrawable) orig).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
|
||||
Bitmap bm = ((BitmapDrawable) orig).getBitmap();
|
||||
|
||||
Bitmap instance = bm.copy(Bitmap.Config.ARGB_8888, true);
|
||||
|
||||
Bitmap bwBitmap = Bitmap.createBitmap(instance.getWidth(), instance.getHeight(), Bitmap.Config.RGB_565);
|
||||
float[] hsv = new float[3];
|
||||
@@ -130,7 +179,7 @@ public class ImageFilters {
|
||||
return new BitmapDrawable(getResources(), bwBitmap);
|
||||
}
|
||||
|
||||
private static void darken(Bitmap bm) {
|
||||
private static void darken(Bitmap bm){
|
||||
try {
|
||||
Canvas canvas = new Canvas(bm);
|
||||
Paint p = new Paint(Color.RED);
|
||||
@@ -138,11 +187,11 @@ public class ImageFilters {
|
||||
p.setColorFilter(filter);
|
||||
canvas.drawBitmap(bm, new Matrix(), p);
|
||||
} catch (Exception e) {
|
||||
sendToast("Ошибка при работе затемнения обоев");
|
||||
Log.d("WallpaperD", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void lighten(Bitmap bm) {
|
||||
private static void lighten(Bitmap bm){
|
||||
try {
|
||||
Canvas canvas = new Canvas(bm);
|
||||
Paint p = new Paint(Color.RED);
|
||||
@@ -150,11 +199,11 @@ public class ImageFilters {
|
||||
p.setColorFilter(filter);
|
||||
canvas.drawBitmap(bm, new Matrix(), p);
|
||||
} catch (Exception e) {
|
||||
sendToast("Ошибка при работе осветления обоев");
|
||||
Log.d("WallpaperL", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap applyInvertEffect(Bitmap src) {
|
||||
public static Bitmap applyInvertEffect(Bitmap src){
|
||||
// create new bitmap with the same settings as source bitmap
|
||||
Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
|
||||
// color info
|
||||
@@ -184,7 +233,7 @@ public class ImageFilters {
|
||||
return bmOut;
|
||||
}
|
||||
|
||||
public static Bitmap applySepiaEffect(Bitmap src) {
|
||||
public static Bitmap applySepiaEffect(Bitmap src){
|
||||
// image size
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
@@ -221,8 +270,8 @@ public class ImageFilters {
|
||||
return bmOut;
|
||||
}
|
||||
|
||||
public static Bitmap applyEmbossEffect(Bitmap src) {
|
||||
double[][] EmbossConfig = new double[][]{
|
||||
public static Bitmap applyEmbossEffect(Bitmap src){
|
||||
double[][] EmbossConfig = new double[][] {
|
||||
{-1, 0, -1},
|
||||
{0, 4, 0},
|
||||
{-1, 0, -1}
|
||||
@@ -234,7 +283,7 @@ public class ImageFilters {
|
||||
return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
|
||||
}
|
||||
|
||||
public static Bitmap applyEngraveEffect(Bitmap src) {
|
||||
public static Bitmap applyEngraveEffect(Bitmap src){
|
||||
ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
|
||||
convMatrix.setAll(0);
|
||||
convMatrix.Matrix[0][0] = -2;
|
||||
@@ -244,7 +293,7 @@ public class ImageFilters {
|
||||
return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
|
||||
}
|
||||
|
||||
public static Bitmap applyFleaEffect(Bitmap source) {
|
||||
public static Bitmap applyFleaEffect(Bitmap source){
|
||||
// get image size
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
@@ -273,7 +322,7 @@ public class ImageFilters {
|
||||
return bmOut;
|
||||
}
|
||||
|
||||
public static Bitmap applySnowEffect(Bitmap source) {
|
||||
public static Bitmap applySnowEffect(Bitmap source){
|
||||
// get image size
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
@@ -306,7 +355,7 @@ public class ImageFilters {
|
||||
return bmOut;
|
||||
}
|
||||
|
||||
public Bitmap applyDecreaseColorDepthEffect(Bitmap src, int bitOffset) {
|
||||
public Bitmap applyDecreaseColorDepthEffect(Bitmap src, int bitOffset){
|
||||
// get image size
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
@@ -349,7 +398,7 @@ public class ImageFilters {
|
||||
return bmOut;
|
||||
}
|
||||
|
||||
public Bitmap applyContrastEffect(Bitmap src, double value) {
|
||||
public Bitmap applyContrastEffect(Bitmap src, double value){
|
||||
// image size
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
@@ -401,7 +450,7 @@ public class ImageFilters {
|
||||
return bmOut;
|
||||
}
|
||||
|
||||
public Bitmap applyBrightnessEffect(Bitmap src, int value) {
|
||||
public Bitmap applyBrightnessEffect(Bitmap src, int value){
|
||||
// image size
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
@@ -452,8 +501,8 @@ public class ImageFilters {
|
||||
return bmOut;
|
||||
}
|
||||
|
||||
public Bitmap applyGaussianBlurEffect(Bitmap src) {
|
||||
double[][] GaussianBlurConfig = new double[][]{
|
||||
public Bitmap applyGaussianBlurEffect(Bitmap src){
|
||||
double[][] GaussianBlurConfig = new double[][] {
|
||||
{1, 2, 1},
|
||||
{2, 4, 2},
|
||||
{1, 2, 1}
|
||||
@@ -465,8 +514,8 @@ public class ImageFilters {
|
||||
return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
|
||||
}
|
||||
|
||||
public Bitmap applySharpenEffect(Bitmap src, double weight) {
|
||||
double[][] SharpConfig = new double[][]{
|
||||
public Bitmap applySharpenEffect(Bitmap src, double weight){
|
||||
double[][] SharpConfig = new double[][] {
|
||||
{0, -2, 0},
|
||||
{-2, weight, -2},
|
||||
{0, -2, 0}
|
||||
@@ -477,8 +526,8 @@ public class ImageFilters {
|
||||
return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
|
||||
}
|
||||
|
||||
public Bitmap applyMeanRemovalEffect(Bitmap src) {
|
||||
double[][] MeanRemovalConfig = new double[][]{
|
||||
public Bitmap applyMeanRemovalEffect(Bitmap src){
|
||||
double[][] MeanRemovalConfig = new double[][] {
|
||||
{-1, -1, -1},
|
||||
{-1, 9, -1},
|
||||
{-1, -1, -1}
|
||||
@@ -490,7 +539,7 @@ public class ImageFilters {
|
||||
return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
|
||||
}
|
||||
|
||||
public Bitmap applySmoothEffect(Bitmap src, double value) {
|
||||
public Bitmap applySmoothEffect(Bitmap src, double value){
|
||||
ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
|
||||
convMatrix.setAll(1);
|
||||
convMatrix.Matrix[1][1] = value;
|
||||
@@ -499,7 +548,7 @@ public class ImageFilters {
|
||||
return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
|
||||
}
|
||||
|
||||
public Bitmap applyBoostEffect(Bitmap src, int type, float percent) {
|
||||
public Bitmap applyBoostEffect(Bitmap src, int type, float percent){
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
|
||||
@@ -530,7 +579,7 @@ public class ImageFilters {
|
||||
return bmOut;
|
||||
}
|
||||
|
||||
public Bitmap applyTintEffect(Bitmap src, int degree) {
|
||||
public Bitmap applyTintEffect(Bitmap src, int degree){
|
||||
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
@@ -574,7 +623,7 @@ public class ImageFilters {
|
||||
return outBitmap;
|
||||
}
|
||||
|
||||
public Bitmap applyBlackFilter(Bitmap source) {
|
||||
public Bitmap applyBlackFilter(Bitmap source){
|
||||
// get image size
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
@@ -607,7 +656,7 @@ public class ImageFilters {
|
||||
return bmOut;
|
||||
}
|
||||
|
||||
public Bitmap applyShadingFilter(Bitmap source, int shadingColor) {
|
||||
public Bitmap applyShadingFilter(Bitmap source, int shadingColor){
|
||||
// get image size
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
@@ -631,7 +680,7 @@ public class ImageFilters {
|
||||
return bmOut;
|
||||
}
|
||||
|
||||
public Bitmap applySaturationFilter(Bitmap source, int level) {
|
||||
public Bitmap applySaturationFilter(Bitmap source, int level){
|
||||
// get image size
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
@@ -661,7 +710,7 @@ public class ImageFilters {
|
||||
return bmOut;
|
||||
}
|
||||
|
||||
public Bitmap applyHueFilter(Bitmap source, int level) {
|
||||
public Bitmap applyHueFilter(Bitmap source, int level){
|
||||
// get image size
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
|
||||
@@ -8,7 +8,6 @@ import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.removeWallpaper;
|
||||
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.requestUpdateWallpaper;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.CacheUtils.deleteCache;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.hasVerification;
|
||||
|
||||
@@ -33,15 +32,15 @@ import java.io.OutputStream;
|
||||
import ru.vtosters.lite.ui.PreferencesUtil;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment{
|
||||
|
||||
private WallpaperPreferences mWPPreviewPref;
|
||||
|
||||
public static void copyStream(InputStream copyFrom, OutputStream copyTo) throws IOException {
|
||||
public static void copyStream(InputStream copyFrom, OutputStream copyTo) throws IOException{
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = copyFrom.read(buffer)) > 0) {
|
||||
while((length = copyFrom.read(buffer)) > 0) {
|
||||
copyTo.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
@@ -51,7 +50,7 @@ public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
|
||||
int vtosterXml = getIdentifier("empty", "xml");
|
||||
@@ -87,16 +86,16 @@ public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
}
|
||||
|
||||
PreferencesUtil.addListPreference(this, "msg_blur_radius", "disabled", AndroidUtils.getString("filter_blur"), AndroidUtils.getArray("filter_types"), new String[]{
|
||||
PreferencesUtil.addListPreference(this, "msg_blur_radius", "disabled", AndroidUtils.getString("filter_blur"), AndroidUtils.getArray("filter_types"), new String[] {
|
||||
"disabled", "low", "med", "high"
|
||||
});
|
||||
|
||||
PreferencesUtil.addListPreference(this, "msg_dim", "off", AndroidUtils.getString("filter_dim"), AndroidUtils.getArray("filter_dim_types"), new String[]{
|
||||
PreferencesUtil.addListPreference(this, "msg_dim", "off", AndroidUtils.getString("filter_dim"), AndroidUtils.getArray("filter_dim_types"), new String[] {
|
||||
"off", "dim_black", "dim_white"
|
||||
});
|
||||
|
||||
|
||||
PreferencesUtil.addListPreference(this, "msg_mosaic", "disabled", AndroidUtils.getString("filter_mosaic"), AndroidUtils.getArray("filter_types"), new String[]{
|
||||
PreferencesUtil.addListPreference(this, "msg_mosaic", "disabled", AndroidUtils.getString("filter_mosaic"), AndroidUtils.getArray("filter_types"), new String[] {
|
||||
"disabled", "low", "med", "high"
|
||||
});
|
||||
|
||||
@@ -158,7 +157,7 @@ public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
}
|
||||
|
||||
PreferencesUtil.addMaterialSwitchPreference(this, "compresswp", "Сжимать обои", "Значительно ускоряет открытие чатов", null, true, (preference, o) -> {
|
||||
PreferencesUtil.addMaterialSwitchPreference(this, "compresswp", AndroidUtils.getString("compress_wallpaper_title"), AndroidUtils.getString("compress_wallpaper_summ"), null, true, (preference, o) -> {
|
||||
boolean value = (boolean) o;
|
||||
edit().putBoolean("compresswp", value).commit();
|
||||
requestUpdateWallpaper();
|
||||
@@ -200,13 +199,14 @@ public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int i, int i1, @Nullable Intent intent) {
|
||||
public void onActivityResult(int i, int i1, @Nullable Intent intent){
|
||||
super.onActivityResult(i, i1, intent);
|
||||
|
||||
if (intent == null || intent.getData() == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
removeWallpaper();
|
||||
InputStream fileInputStream = requireActivity().getContentResolver().openInputStream(intent.getData());
|
||||
OutputStream outputStream = new FileOutputStream(getWallpaperFile());
|
||||
|
||||
@@ -217,20 +217,21 @@ public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment {
|
||||
if (i == 1488) {
|
||||
mWPPreviewPref.redraw();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(requireActivity(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void removeStickCache() {
|
||||
private void removeStickCache(){
|
||||
SharedPreferences prefs2 = getContext().getSharedPreferences("stickers_storage", Context.MODE_PRIVATE);
|
||||
prefs2.edit().clear().apply();
|
||||
ImEngineProvider.b().a();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
public int T4(){
|
||||
return getIdentifier("wallpapers", "string");
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.vtosters.lite.ui.wallpapers;
|
||||
|
||||
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getWallpaper;
|
||||
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getFilteredFile;
|
||||
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getWallpaperFile;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
|
||||
@@ -18,31 +18,31 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import ru.vtosters.lite.ui.adapters.MessagesPreviewAdapter;
|
||||
|
||||
public class WallpaperPreferences extends Preference {
|
||||
public class WallpaperPreferences extends Preference{
|
||||
|
||||
private MessagesPreviewAdapter mAdapter;
|
||||
RecyclerView mRecyclerView;
|
||||
ImageView mChatBackground;
|
||||
private MessagesPreviewAdapter mAdapter;
|
||||
|
||||
public WallpaperPreferences(Context context) {
|
||||
public WallpaperPreferences(Context context){
|
||||
this(context, null, -1, -1);
|
||||
}
|
||||
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet) {
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet){
|
||||
this(context, attributeSet, -1, -1);
|
||||
}
|
||||
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet, int defStyleAttr) {
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet, int defStyleAttr){
|
||||
this(context, attributeSet, defStyleAttr, -1);
|
||||
}
|
||||
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet, int defStyleAttr, int i1) {
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet, int defStyleAttr, int i1){
|
||||
super(context, attributeSet, defStyleAttr, i1);
|
||||
setLayoutResource(getIdentifier("wppreview", "layout"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder preferenceViewHolder) {
|
||||
public void onBindViewHolder(PreferenceViewHolder preferenceViewHolder){
|
||||
super.onBindViewHolder(preferenceViewHolder);
|
||||
|
||||
mRecyclerView = (RecyclerView) preferenceViewHolder.findViewById(getIdentifier("install_btn_container", "id"));
|
||||
@@ -56,17 +56,17 @@ public class WallpaperPreferences extends Preference {
|
||||
requestBg();
|
||||
}
|
||||
|
||||
private void requestBg() {
|
||||
final Drawable drawable = getWallpaper();
|
||||
private void requestBg(){
|
||||
final Drawable drawable = getFilteredFile();
|
||||
|
||||
if (drawable != null && getWallpaperFile().exists())
|
||||
if (drawable != null && getWallpaperFile() != null)
|
||||
mChatBackground.setImageDrawable(drawable);
|
||||
else
|
||||
mChatBackground.setImageDrawable(null);
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
void redraw() {
|
||||
void redraw(){
|
||||
mAdapter.notifyDataSetChanged();
|
||||
requestBg();
|
||||
}
|
||||
|
||||
@@ -1,46 +1,78 @@
|
||||
package ru.vtosters.lite.ui.wallpapers;
|
||||
|
||||
import static com.vk.im.engine.h.im_bg_chat;
|
||||
import static ru.vtosters.lite.ui.wallpapers.ImageFilters.getBlurredWallpaper;
|
||||
import static ru.vtosters.lite.ui.wallpapers.ImageFilters.getDimmed;
|
||||
import static ru.vtosters.lite.ui.wallpapers.ImageFilters.getFilteredDrawable;
|
||||
import static ru.vtosters.lite.ui.wallpapers.ImageFilters.getMonochrome;
|
||||
import static ru.vtosters.lite.ui.wallpapers.ImageFilters.getMosaic;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.hasVerification;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
import vigo.sdk.Log;
|
||||
|
||||
public class WallpapersHooks {
|
||||
public class WallpapersHooks{
|
||||
private static final boolean compress = getBoolValue("compresswp", true);
|
||||
private static File mWallpaperFile;
|
||||
|
||||
private static Drawable mWallpaper;
|
||||
private static boolean mUpdateWallpaperRequested = true;
|
||||
private static boolean mUpdateWallpaperFileRequested = true;
|
||||
|
||||
public static File getWallpaperFile() {
|
||||
return mWallpaperFile == null ? mWallpaperFile = new File(getGlobalContext().getFilesDir(), "wallpaper.png") : mWallpaperFile;
|
||||
public static File getWallpaperFile(){
|
||||
if (mWallpaperFile == null) {
|
||||
mWallpaperFile = new File(getGlobalContext().getFilesDir(), "wallpaper.webp");
|
||||
}
|
||||
|
||||
return mWallpaperFile;
|
||||
}
|
||||
|
||||
private static Boolean eligibleWallpaperFile(File file) {
|
||||
public static Drawable getFilteredFile(){
|
||||
File file = null;
|
||||
File wp = mWallpaperFile;
|
||||
String temp = getGlobalContext().getFilesDir() + File.separator + "filteredwp.webp";
|
||||
|
||||
if (wp != null && mUpdateWallpaperFileRequested) {
|
||||
try {
|
||||
file = new File(temp);
|
||||
file.createNewFile();
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
((BitmapDrawable) getFilteredDrawable(Drawable.createFromPath(wp.getAbsolutePath()))).getBitmap().compress(Bitmap.CompressFormat.WEBP, (compress ? 80 : 95), bos);
|
||||
byte[] bitmapdata = bos.toByteArray();
|
||||
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(bitmapdata);
|
||||
fos.flush();
|
||||
fos.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.d("Wallpapers", e.getMessage());
|
||||
}
|
||||
|
||||
mUpdateWallpaperFileRequested = false;
|
||||
}
|
||||
|
||||
try {
|
||||
return Drawable.createFromPath(temp);
|
||||
} catch (Exception e) {
|
||||
return Drawable.createFromPath(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
private static Boolean eligibleWallpaperFile(File file){
|
||||
if (file.length() >= 6291456) {
|
||||
sendToast("Размер файла превышает лимит 6 MB");
|
||||
sendToast(getString("wallpaper_size_limit"));
|
||||
removeWallpaper();
|
||||
return false;
|
||||
} else {
|
||||
@@ -48,85 +80,42 @@ public class WallpapersHooks {
|
||||
}
|
||||
}
|
||||
|
||||
public static File compress(File file){
|
||||
try {
|
||||
BitmapFactory.Options o = new BitmapFactory.Options();
|
||||
o.inJustDecodeBounds = true;
|
||||
o.inSampleSize = 6;
|
||||
|
||||
FileInputStream inputStream = new FileInputStream(file);
|
||||
BitmapFactory.decodeStream(inputStream, null, o);
|
||||
inputStream.close();
|
||||
|
||||
final int REQUIRED_SIZE=200;
|
||||
|
||||
int scale = 1;
|
||||
while(o.outWidth / scale / 2 >= REQUIRED_SIZE && o.outHeight / scale / 2 >= REQUIRED_SIZE) {
|
||||
scale *= 2;
|
||||
}
|
||||
|
||||
BitmapFactory.Options o2 = new BitmapFactory.Options();
|
||||
o2.inSampleSize = scale;
|
||||
inputStream = new FileInputStream(file);
|
||||
|
||||
Bitmap selectedBitmap = BitmapFactory.decodeStream(inputStream, null, o2);
|
||||
inputStream.close();
|
||||
|
||||
File outPutFile = File.createTempFile("wallpaper_temp","image");
|
||||
FileOutputStream outputStream = new FileOutputStream(outPutFile);
|
||||
selectedBitmap.compress(Bitmap.CompressFormat.PNG, 85 , outputStream);
|
||||
|
||||
return outPutFile;
|
||||
} catch (Exception e) {
|
||||
Log.d("Wallpapers", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBg(View view) {
|
||||
public static void setBg(View view){
|
||||
if (getWallpaper() != null) {
|
||||
((ImageView) view).setImageDrawable(getWallpaper()); // set picture to background
|
||||
((ImageView) view).setImageDrawable(getFilteredFile()); // set picture to background
|
||||
return;
|
||||
}
|
||||
|
||||
view.setBackgroundColor(ThemesUtils.getColorFromAttr(im_bg_chat)); // set default bg color
|
||||
}
|
||||
|
||||
public static String getWallpaperUrl() {
|
||||
if (getWallpaperFile().exists() && eligibleWallpaperFile(getWallpaperFile()))
|
||||
if (compress(getWallpaperFile()) == null) {
|
||||
return "default";
|
||||
} else if (getBoolValue("compresswp", true)){
|
||||
return compress(getWallpaperFile()).getAbsolutePath();
|
||||
} else {
|
||||
return getWallpaperFile().getAbsolutePath();
|
||||
}
|
||||
else
|
||||
return "default";
|
||||
public static String getWallpaperUrl(){
|
||||
var file = getWallpaperFile();
|
||||
|
||||
if (file.exists() && eligibleWallpaperFile(file)) {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
return "default";
|
||||
}
|
||||
|
||||
public static Drawable getWallpaper() {
|
||||
public static Drawable getWallpaper(){
|
||||
if (mWallpaper == null || mUpdateWallpaperRequested) {
|
||||
if (!getPreferences().getString("msg_blur_radius", "disabled").equals("disabled")) {
|
||||
mWallpaper = getBlurredWallpaper(Drawable.createFromPath(getWallpaperUrl()), getRadius());
|
||||
} else {
|
||||
mWallpaper = Drawable.createFromPath(getWallpaperUrl());
|
||||
}
|
||||
if (!getPreferences().getString("msg_dim", "off").equals("off")) {
|
||||
mWallpaper = getDimmed(mWallpaper);
|
||||
String url = getWallpaperUrl();
|
||||
|
||||
if (url.equals("default") || url.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!getPreferences().getString("msg_mosaic", "disabled").equals("disabled")) {
|
||||
mWallpaper = getMosaic(mWallpaper);
|
||||
Drawable drawable = Drawable.createFromPath(getWallpaperUrl());
|
||||
|
||||
if (drawable == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (hasVerification()) {
|
||||
if (getPreferences().getBoolean("msg_monochrome", false)) {
|
||||
mWallpaper = getMonochrome(mWallpaper);
|
||||
}
|
||||
mWallpaper = drawable;
|
||||
|
||||
mWallpaper = getFilteredDrawable(mWallpaper);
|
||||
}
|
||||
mWallpaper = getFilteredDrawable(mWallpaper);
|
||||
|
||||
mUpdateWallpaperRequested = false;
|
||||
}
|
||||
@@ -134,64 +123,59 @@ public class WallpapersHooks {
|
||||
return mWallpaper;
|
||||
}
|
||||
|
||||
public static void requestUpdateWallpaper() {
|
||||
public static void requestUpdateWallpaper(){
|
||||
mUpdateWallpaperRequested = true;
|
||||
mUpdateWallpaperFileRequested = true;
|
||||
}
|
||||
|
||||
private static int getRadius() {
|
||||
public static String getRadiusSummary(){
|
||||
String radius = getPreferences().getString("msg_blur_radius", "disabled");
|
||||
switch (radius) {
|
||||
switch(radius) {
|
||||
case "low":
|
||||
return 8;
|
||||
return getString("wallpapers_low");
|
||||
case "med":
|
||||
return 14;
|
||||
default:
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getRadiusSummary() {
|
||||
String radius = getPreferences().getString("msg_blur_radius", "disabled");
|
||||
switch (radius) {
|
||||
case "low":
|
||||
return AndroidUtils.getString("wallpapers_low");
|
||||
case "med":
|
||||
return AndroidUtils.getString("wallpapers_med");
|
||||
return getString("wallpapers_med");
|
||||
case "high":
|
||||
return AndroidUtils.getString("wallpapers_high");
|
||||
return getString("wallpapers_high");
|
||||
default:
|
||||
return AndroidUtils.getString("wallpapers_disabled");
|
||||
return getString("wallpapers_disabled");
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDimmingSummary() {
|
||||
public static String getDimmingSummary(){
|
||||
String radius = getPreferences().getString("msg_dim", "disabled");
|
||||
switch (radius) {
|
||||
switch(radius) {
|
||||
case "dim_black":
|
||||
return AndroidUtils.getString("wallpapers_dim_black");
|
||||
return getString("wallpapers_dim_black");
|
||||
case "dim_white":
|
||||
return AndroidUtils.getString("wallpapers_dim_white");
|
||||
return getString("wallpapers_dim_white");
|
||||
default:
|
||||
return AndroidUtils.getString("wallpapers_disabled");
|
||||
return getString("wallpapers_disabled");
|
||||
}
|
||||
}
|
||||
|
||||
public static String getMosaicSummary() {
|
||||
public static String getMosaicSummary(){
|
||||
String radius = getPreferences().getString("msg_mosaic", "disabled");
|
||||
switch (radius) {
|
||||
switch(radius) {
|
||||
case "low":
|
||||
return AndroidUtils.getString("wallpapers_low");
|
||||
return getString("wallpapers_low");
|
||||
case "med":
|
||||
return AndroidUtils.getString("wallpapers_med");
|
||||
return getString("wallpapers_med");
|
||||
case "high":
|
||||
return AndroidUtils.getString("wallpapers_high");
|
||||
return getString("wallpapers_high");
|
||||
default:
|
||||
return AndroidUtils.getString("wallpapers_disabled");
|
||||
return getString("wallpapers_disabled");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void removeWallpaper() {
|
||||
getWallpaperFile().delete();
|
||||
public static void removeWallpaper(){
|
||||
try {
|
||||
new File(getGlobalContext().getFilesDir(), "wallpaper.webp").delete();
|
||||
new File(getGlobalContext().getFilesDir(), "filteredwp.webp").delete();
|
||||
mWallpaperFile = null;
|
||||
} catch (Exception e) {
|
||||
Log.d("Wallpapers", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,12 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.vk.core.util.Screen;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AndroidUtils {
|
||||
|
||||
@@ -31,6 +34,10 @@ public class AndroidUtils {
|
||||
return PreferenceManager.getDefaultSharedPreferences(getGlobalContext());
|
||||
}
|
||||
|
||||
public static boolean isTablet() {
|
||||
return Screen.l(getGlobalContext());
|
||||
}
|
||||
|
||||
public static String getPrefsValue(String pref) {
|
||||
return getPreferences().getString(pref, "");
|
||||
} // Get pref value as string
|
||||
@@ -44,9 +51,9 @@ public class AndroidUtils {
|
||||
try {
|
||||
return ReflectionUtils.invokeStaticMethod("android.app.AppGlobals", "getInitialApplication");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.d("GlobalContext", "Error while fetching context via refl");
|
||||
}
|
||||
return null;
|
||||
return Objects.requireNonNull(LifecycleUtils.getCurrentActivity());
|
||||
} // Getting the global context through reflection to use context on application initialization
|
||||
|
||||
public static Resources getResources() {
|
||||
|
||||
@@ -13,19 +13,14 @@ import com.vk.im.ui.providers.audiomsg.ImAudioMsgPlayerProvider;
|
||||
import com.vk.im.ui.providers.audiomsg.PlayerActionSources;
|
||||
import com.vk.imageloader.VKImageLoader;
|
||||
import com.vk.media.player.cache.AutoPlayCacheHolder;
|
||||
import com.vk.mediastore.MediaStorage;
|
||||
import com.vk.stickers.Stickers;
|
||||
import com.vtosters.lite.im.ImEngineProvider;
|
||||
|
||||
import java.text.CharacterIterator;
|
||||
import java.text.StringCharacterIterator;
|
||||
|
||||
import b.h.g.m.FileUtils;
|
||||
|
||||
public class CacheUtils {
|
||||
private static CacheUtils sInstance = new CacheUtils();
|
||||
public long size = 0;
|
||||
public static boolean needToDelete = false;
|
||||
|
||||
public static CacheUtils getInstance() {
|
||||
if (sInstance == null)
|
||||
@@ -33,10 +28,6 @@ public class CacheUtils {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public static void deleteCache() {
|
||||
IOUtils.deleteRecursive(getGlobalContext().getCacheDir());
|
||||
}
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
public static String humanReadableByteCountBin(long bytes) {
|
||||
long absB = bytes == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(bytes);
|
||||
@@ -56,12 +47,11 @@ public class CacheUtils {
|
||||
public void autoCleaningCache() {
|
||||
size = IOUtils.getDirSize(getGlobalContext().getCacheDir());
|
||||
|
||||
if (size >= getSizeForDelete() && needToDelete) {
|
||||
if (size >= getSizeForDelete()) {
|
||||
if (dev()) sendToast(AndroidUtils.getString("cache_cleaned"));
|
||||
VKImageLoader.e();
|
||||
ImAudioMsgPlayerProvider.b().e(PlayerActionSources.a);
|
||||
ImAudioMsgPlayerProvider.b().d(PlayerActionSources.a);
|
||||
FileUtils.l();
|
||||
Stickers.l.c();
|
||||
ImEngineExt.a(ImEngine1.a());
|
||||
AutoPlayCacheHolder.d.a();
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
import static androidx.core.app.ActivityCompat.requestPermissions;
|
||||
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.getString;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.SyncResult;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.vk.auth.VKAuthUtils;
|
||||
import com.vk.contacts.ContactsSyncAdapterService;
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.core.network.Network;
|
||||
import com.vtosters.lite.auth.VKAccountManager;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class ContactsUtils{
|
||||
public static void setContactsSync(boolean enabled){
|
||||
makeRequest("https://" + getApi() + "/method/account.setInfo?" + "name=im_user_name_type&value=" + (enabled ? "contact" : "vk") + "&https=1&v=5.153&access_token=" + getUserToken(),
|
||||
response -> {
|
||||
try {
|
||||
JSONObject mainJson = new JSONObject(response);
|
||||
Log.d("ContactsUtils", "Result: " + mainJson + ", enabled sync: " + enabled);
|
||||
} catch (JSONException e) {
|
||||
Log.d("ContactsUtils", e.getMessage());
|
||||
sendToast(getString("contact_sync_error"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void uploadContacts(Activity ctx){
|
||||
try {
|
||||
if (ContextCompat.checkSelfPermission(ctx, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
|
||||
sendToast(getString("contact_permission_toast"));
|
||||
requestPermissions(LifecycleUtils.getCurrentActivity(), new String[] {Manifest.permission.READ_CONTACTS}, 11111);
|
||||
sendToast(getString("contact_permission_toast"));
|
||||
requestPermissions(ctx, new String[] {Manifest.permission.READ_CONTACTS}, 11111);
|
||||
} else {
|
||||
var account = VKAuthUtils.a.a(VKAccountManager.d().Z());
|
||||
ContactsSyncAdapterService.c(ctx, account, new Bundle(), new SyncResult());
|
||||
}
|
||||
} catch (Exception e){
|
||||
Log.d("ContactsUtils", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void getContactsStatus(Context ctx){
|
||||
final ProgressDialog progressDialog = new ProgressDialog(ctx);
|
||||
progressDialog.setMessage(getString("contact_info_loading"));
|
||||
progressDialog.show();
|
||||
|
||||
var request = new okhttp3.Request.a()
|
||||
.b("https://" + getApi() + "/method/execute?https=1&v=5.153&code=return%20API.account.getInfo().settings%5B44%5D.value%3B&access_token=" + getUserToken())
|
||||
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8"))
|
||||
.a();
|
||||
|
||||
try {
|
||||
var response = new OkHttpClient().a(request).execute().a().g();
|
||||
progressDialog.cancel();
|
||||
|
||||
try {
|
||||
String resp = new JSONObject(response).optString("response");
|
||||
|
||||
Log.d("ContactsUtils", new JSONObject(response).toString());
|
||||
|
||||
boolean enabledsync = resp.equals("contact");
|
||||
|
||||
VkAlertDialog.Builder builder = new VkAlertDialog.Builder(ctx);
|
||||
builder.setTitle(getString("contact_sync_title"));
|
||||
builder.setMessage(getString("contact_sync_state") + ": " + getString(enabledsync ? "contact_sync_enabled" : "contact_sync_disabled"));
|
||||
builder.setCancelable(true);
|
||||
builder.setPositiveButton((!enabledsync ? getString("enable") : getString("proxy_disable")), (dialog, which) -> {
|
||||
setContactsSync(!enabledsync);
|
||||
});
|
||||
// builder.setNegativeButton("Импортировать контакты", (dialog, which) -> {
|
||||
// uploadContacts(ctx);
|
||||
// });
|
||||
|
||||
builder.show();
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.d("ContactsUtils", e.getMessage());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.d("ContactsUtils", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,12 +59,12 @@ public class ExternalLinkParser {
|
||||
|
||||
if (checkVkVideo(file)) {
|
||||
if (qualities.size() == 1) {
|
||||
startExternalVideo((String) qualities.values().toArray()[0]);
|
||||
startExternalVideo((String) qualities.values().toArray()[0], context);
|
||||
} else {
|
||||
String[] titles = qualities.keySet().toArray(new String[0]);
|
||||
new AlertDialog.Builder(context)
|
||||
.setItems(titles, ((dialog, which) -> {
|
||||
startExternalVideo(qualities.get(titles[which]));
|
||||
startExternalVideo(qualities.get(titles[which]), context);
|
||||
}))
|
||||
.show();
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class ExternalLinkParser {
|
||||
return qualities.size() > 0;
|
||||
}
|
||||
|
||||
public static boolean startExternalVideo(String url) {
|
||||
public static boolean startExternalVideo(String url, Context ctx) {
|
||||
try {
|
||||
qualities.clear();
|
||||
|
||||
@@ -136,7 +136,7 @@ public class ExternalLinkParser {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
}
|
||||
getGlobalContext().startActivity(intent);
|
||||
ctx.startActivity(intent);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.os.storage.StorageVolume;
|
||||
import android.provider.DocumentsContract;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
// https://stackoverflow.com/questions/34927748/android-5-0-documentfile-from-tree-uri/36162691#36162691
|
||||
|
||||
public final class FileUriUtils {
|
||||
|
||||
private static final String PRIMARY_VOLUME_NAME = "primary";
|
||||
|
||||
@Nullable
|
||||
public static String getFullPathFromTreeUri(@Nullable final Uri treeUri, Context con) {
|
||||
if (treeUri == null) return null;
|
||||
String volumePath = getVolumePath(getVolumeIdFromTreeUri(treeUri),con);
|
||||
if (volumePath == null) return File.separator;
|
||||
if (volumePath.endsWith(File.separator))
|
||||
volumePath = volumePath.substring(0, volumePath.length() - 1);
|
||||
|
||||
String documentPath = getDocumentPathFromTreeUri(treeUri);
|
||||
if (documentPath.endsWith(File.separator))
|
||||
documentPath = documentPath.substring(0, documentPath.length() - 1);
|
||||
|
||||
if (documentPath.length() > 0) {
|
||||
if (documentPath.startsWith(File.separator))
|
||||
return volumePath + documentPath;
|
||||
else
|
||||
return volumePath + File.separator + documentPath;
|
||||
}
|
||||
else return volumePath;
|
||||
}
|
||||
|
||||
|
||||
private static String getVolumePath(final String volumeId, Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||
return getVolumePathForAndroid11AndAbove(volumeId, context);
|
||||
else
|
||||
return getVolumePathBeforeAndroid11(volumeId, context);
|
||||
}
|
||||
|
||||
|
||||
private static String getVolumePathBeforeAndroid11(final String volumeId, Context context){
|
||||
try {
|
||||
StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
|
||||
Class<?> storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
|
||||
Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
|
||||
Method getUuid = storageVolumeClazz.getMethod("getUuid");
|
||||
Method getPath = storageVolumeClazz.getMethod("getPath");
|
||||
Method isPrimary = storageVolumeClazz.getMethod("isPrimary");
|
||||
Object result = getVolumeList.invoke(mStorageManager);
|
||||
|
||||
final int length = Array.getLength(result);
|
||||
for (int i = 0; i < length; i++) {
|
||||
Object storageVolumeElement = Array.get(result, i);
|
||||
String uuid = (String) getUuid.invoke(storageVolumeElement);
|
||||
Boolean primary = (Boolean) isPrimary.invoke(storageVolumeElement);
|
||||
|
||||
if (primary && PRIMARY_VOLUME_NAME.equals(volumeId)) // primary volume?
|
||||
return (String) getPath.invoke(storageVolumeElement);
|
||||
|
||||
if (uuid != null && uuid.equals(volumeId)) // other volumes?
|
||||
return (String) getPath.invoke(storageVolumeElement);
|
||||
}
|
||||
// not found.
|
||||
return null;
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.R)
|
||||
private static String getVolumePathForAndroid11AndAbove(final String volumeId, Context context) {
|
||||
try {
|
||||
StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
|
||||
List<StorageVolume> storageVolumes = mStorageManager.getStorageVolumes();
|
||||
for (StorageVolume storageVolume : storageVolumes) {
|
||||
// primary volume?
|
||||
if (storageVolume.isPrimary() && PRIMARY_VOLUME_NAME.equals(volumeId))
|
||||
return storageVolume.getDirectory().getPath();
|
||||
|
||||
// other volumes?
|
||||
String uuid = storageVolume.getUuid();
|
||||
if (uuid != null && uuid.equals(volumeId))
|
||||
return storageVolume.getDirectory().getPath();
|
||||
|
||||
}
|
||||
// not found.
|
||||
return null;
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getVolumeIdFromTreeUri(final Uri treeUri) {
|
||||
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
|
||||
final String[] split = docId.split(":");
|
||||
if (split.length > 0) return split[0];
|
||||
else return null;
|
||||
}
|
||||
|
||||
private static String getDocumentPathFromTreeUri(final Uri treeUri) {
|
||||
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
|
||||
final String[] split = docId.split(":");
|
||||
if ((split.length >= 2) && (split[1] != null)) return split[1];
|
||||
else return File.separator;
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,10 @@ public class IOUtils {
|
||||
|
||||
public static byte[] decodeStream(InputStream encIs, String keyURL) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IOException {
|
||||
CipherInputStream cip = new CipherInputStream(encIs, getCipher(keyURL));
|
||||
return readAllBytes(cip);
|
||||
var bytes = readAllBytes(cip);
|
||||
cip.close();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static Cipher getCipher(String key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException {
|
||||
@@ -46,7 +49,11 @@ public class IOUtils {
|
||||
}
|
||||
|
||||
public static String readAllLines(File file) throws IOException {
|
||||
return readAllLines(new FileInputStream(file));
|
||||
var is = new FileInputStream(file);
|
||||
var bytes = readAllBytes(is);
|
||||
is.close();
|
||||
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static String readAllLines(InputStream is) throws IOException {
|
||||
@@ -54,7 +61,11 @@ public class IOUtils {
|
||||
}
|
||||
|
||||
public static byte[] readAllBytes(File file) throws IOException {
|
||||
return readAllBytes(new FileInputStream(file));
|
||||
var is = new FileInputStream(file);
|
||||
var bytes = readAllBytes(is);
|
||||
is.close();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] readAllBytes(InputStream is) throws IOException {
|
||||
@@ -63,7 +74,11 @@ public class IOUtils {
|
||||
int len;
|
||||
while ((len = is.read(buffer)) > 0)
|
||||
bos.write(buffer, 0, len);
|
||||
return bos.toByteArray();
|
||||
|
||||
var bytes = bos.toByteArray();
|
||||
bos.close();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static void writeToFile(File file, String content) throws IOException {
|
||||
@@ -73,6 +88,7 @@ public class IOUtils {
|
||||
public static void writeToFile(File file, byte[] content) throws IOException {
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(content);
|
||||
fos.close();
|
||||
}
|
||||
|
||||
public static void deleteRecursive(File f) {
|
||||
@@ -101,4 +117,8 @@ public class IOUtils {
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
public static String getValidFileName(String fileName) {
|
||||
return fileName.replaceAll("[\\\\/:*?\"<>|]", "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.RectF;
|
||||
|
||||
@@ -43,9 +43,7 @@ public class LifecycleUtils {
|
||||
|
||||
@Override // android.app.Application.ActivityLifecycleCallbacks
|
||||
public void onActivityCreated(Activity activity, Bundle bundle) {
|
||||
if (activity instanceof VKActivity) {
|
||||
activities.add(activity);
|
||||
}
|
||||
activities.add(activity);
|
||||
}
|
||||
|
||||
@Override // android.app.Application.ActivityLifecycleCallbacks
|
||||
@@ -56,7 +54,7 @@ public class LifecycleUtils {
|
||||
}
|
||||
|
||||
public static Activity getCurrentActivity() {
|
||||
return activities.size() > 0 ? activities.get(0) : null;
|
||||
return activities.size() > 0 ? activities.get(activities.size() - 1) : null;
|
||||
}
|
||||
|
||||
public static void restartApplication() {
|
||||
|
||||
@@ -23,14 +23,14 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import ru.vtosters.lite.hooks.JsonInjectors;
|
||||
import ru.vtosters.lite.hooks.AdBlockHook;
|
||||
|
||||
public class NewsFeedFiltersUtils {
|
||||
public class NewsFeedFiltersUtils{
|
||||
public static List<String> mFilters;
|
||||
public static List<String> mFiltersNames;
|
||||
public static List<String> mFiltersLinks;
|
||||
|
||||
public static void setupFilters() {
|
||||
public static void setupFilters(){
|
||||
mFilters = new ArrayList<>();
|
||||
mFiltersNames = new ArrayList<>();
|
||||
mFiltersLinks = new ArrayList<>();
|
||||
@@ -57,43 +57,53 @@ public class NewsFeedFiltersUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void getFilter(String boolname, String filename, List<String> list) {
|
||||
if (getBoolValue(boolname, true)) {
|
||||
public static void getFilter(String boolname, String filename, List<String> list){
|
||||
var ctx = getGlobalContext();
|
||||
|
||||
if (getBoolValue(boolname, false)) {
|
||||
try {
|
||||
var scanner = new Scanner(getGlobalContext().getAssets().open(filename));
|
||||
while (scanner.hasNextLine()) {
|
||||
var line = scanner.nextLine();
|
||||
if (!line.isEmpty())
|
||||
list.add(line.toLowerCase());
|
||||
Scanner scanner;
|
||||
if (ctx != null) {
|
||||
scanner = new Scanner(ctx.getAssets().open(filename));
|
||||
|
||||
while(scanner.hasNextLine()) {
|
||||
var line = scanner.nextLine();
|
||||
if (!line.isEmpty())
|
||||
list.add(line.toLowerCase());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.d("NewsFeedFiltersUtils", e.getMessage());
|
||||
}
|
||||
}
|
||||
} // Get needed filter list from assets
|
||||
|
||||
public static boolean injectFiltersReposts(JSONObject obj) throws JSONException {
|
||||
public static boolean injectFiltersReposts(JSONObject obj) throws JSONException{
|
||||
if (getBoolValue("cringerepost", false) && obj.has("copy_history")) {
|
||||
var copyHistoryNode = obj.optJSONArray("copy_history");
|
||||
for (int i = 0; i < copyHistoryNode.length(); i++) {
|
||||
var item = copyHistoryNode.optJSONObject(i);
|
||||
var text = item.optString("text");
|
||||
if (copyHistoryNode != null && copyHistoryNode.length() != 0) {
|
||||
for (int i = 0; i < copyHistoryNode.length(); i++) {
|
||||
var item = copyHistoryNode.optJSONObject(i);
|
||||
var text = item.optString("text");
|
||||
|
||||
if (isBadNews(text)) {
|
||||
if (dev())
|
||||
Log.d("RepostFilter", "Fetched repost ad (isBadNews), owner id " + item.optString("owner_id") + ", text: " + text);
|
||||
return true;
|
||||
} else if (JsonInjectors.isAds(item, item.optString("post_type"))) {
|
||||
if (dev())
|
||||
Log.d("RepostFilter", "Fetched repost ad (ads), owner id " + item.optString("owner_id") + ", text: " + text);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String filter : mFiltersLinks) {
|
||||
if (text.contains(filter)) {
|
||||
if (isBadNews(text)) {
|
||||
if (dev())
|
||||
Log.d("RepostFilter", "Fetched repost ad, owner id " + item.optString("owner_id") + ", text: " + text);
|
||||
Log.d("RepostFilter", "Fetched repost ad (isBadNews), owner id " + item.optString("owner_id") + ", text: " + text);
|
||||
return true;
|
||||
} else if (AdBlockHook.isAds(item, item.optString("post_type"))) {
|
||||
if (dev())
|
||||
Log.d("RepostFilter", "Fetched repost ad (ads), owner id " + item.optString("owner_id") + ", text: " + text);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mFiltersLinks != null) {
|
||||
for (String filter : mFiltersLinks) {
|
||||
if (text.contains(filter)) {
|
||||
if (dev())
|
||||
Log.d("RepostFilter", "Fetched repost ad, owner id " + item.optString("owner_id") + ", text: " + text);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,65 +111,89 @@ public class NewsFeedFiltersUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean checkCopyright(JSONObject json) throws JSONException {
|
||||
public static boolean checkCopyright(JSONObject json) throws JSONException{
|
||||
if (json.has("copyright")) {
|
||||
if (copyright_post()) return true;
|
||||
|
||||
var copyright = json.optJSONObject("copyright");
|
||||
var copyrightName = copyright.getString("name").toLowerCase();
|
||||
var copyrightLink = copyright.getString("link").toLowerCase();
|
||||
|
||||
for (String filter : mFiltersNames) {
|
||||
if (copyrightName.contains(filter)) return true;
|
||||
|
||||
String copyrightName = null;
|
||||
|
||||
if (copyright != null) {
|
||||
copyrightName = copyright.getString("name").toLowerCase();
|
||||
}
|
||||
|
||||
for (String filter : mFiltersLinks) {
|
||||
if (copyrightLink.contains(filter)) return true;
|
||||
String copyrightLink = null;
|
||||
|
||||
if (copyright != null) {
|
||||
copyrightLink = copyright.getString("link").toLowerCase();
|
||||
}
|
||||
|
||||
if (mFiltersNames != null) {
|
||||
for (String filter : mFiltersNames) {
|
||||
if (copyrightName != null && copyrightName.contains(filter)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mFiltersLinks != null) {
|
||||
for (String filter : mFiltersLinks) {
|
||||
if (copyrightLink != null && copyrightLink.contains(filter)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isRecomsGroup(String src) {
|
||||
public static boolean isRecomsGroup(String src){
|
||||
return authorsrecomm() && src.equals("recommended_groups");
|
||||
}
|
||||
|
||||
public static boolean isMusicBlock(String src) {
|
||||
public static boolean isMusicBlock(String src){
|
||||
return authorsrecomm() && (src.equals("recommended_audios") || src.equals("recommended_artists") || src.equals("recommended_playlists"));
|
||||
}
|
||||
|
||||
public static boolean isNewsBlock(String src) {
|
||||
public static boolean isNewsBlock(String src){
|
||||
return ads() && src.equals("tags_suggestions");
|
||||
}
|
||||
|
||||
public static String getAllFilters() {
|
||||
public static String getAllFilters(){
|
||||
return getPrefsValue("spamfilters");
|
||||
}
|
||||
|
||||
public static boolean isBadNews(String text) {
|
||||
public static boolean isBadNews(String text){
|
||||
var textInLowerCase = text.toLowerCase();
|
||||
for (String filter : mFilters) {
|
||||
if (textInLowerCase.contains(filter)) {
|
||||
if (dev())
|
||||
Log.d("VTLite", text);
|
||||
return true;
|
||||
|
||||
if (mFilters != null) {
|
||||
for (String filter : mFilters) {
|
||||
if (textInLowerCase.contains(filter)) {
|
||||
if (dev())
|
||||
Log.d("NewsfeedAdBlockV2", text);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean checkCaption(JSONObject postJson) {
|
||||
public static boolean checkCaption(JSONObject postJson){
|
||||
if (postJson.has("caption")) {
|
||||
if (captions()) return true;
|
||||
var caption = postJson.optJSONObject("caption");
|
||||
if (postsrecomm()) {
|
||||
try {
|
||||
var type = caption.getString("type");
|
||||
return type.equals("explorebait") || // Может быть интересно
|
||||
type.equals("shared") || // Поделился записью
|
||||
type.equals("digest") || // Рекомедации
|
||||
type.equals("commented") || // Комментирует
|
||||
type.equals("voted"); // Проголосовал в опросе
|
||||
String type;
|
||||
if (caption != null) {
|
||||
type = caption.getString("type");
|
||||
return type.equals("explorebait") || // Может быть интересно
|
||||
type.equals("shared") || // Поделился записью
|
||||
type.equals("digest") || // Рекомедации
|
||||
type.equals("commented") || // Комментирует
|
||||
type.equals("voted"); // Проголосовал в опросе
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.d("checkCaption", "Caption error");
|
||||
}
|
||||
@@ -169,29 +203,29 @@ public class NewsFeedFiltersUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isAds(String optString) {
|
||||
public static boolean isAds(String optString){
|
||||
return ads() && (optString.equals("ads_easy_promote") ||
|
||||
optString.equals("promo_button") ||
|
||||
optString.equals("app_widget") ||
|
||||
optString.equals("ads"));
|
||||
}
|
||||
|
||||
public static boolean isAuthorRecommendations(String optString) {
|
||||
public static boolean isAuthorRecommendations(String optString){
|
||||
return authorsrecomm() && optString.equals("authors_rec");
|
||||
}
|
||||
|
||||
public static boolean isPostRecommendations(String optString) {
|
||||
public static boolean isPostRecommendations(String optString){
|
||||
return postsrecomm() && (optString.equals("live_recommended") ||
|
||||
optString.equals("inline_user_rec"));
|
||||
}
|
||||
|
||||
public static boolean isFriendsRecommendations(String optString) {
|
||||
public static boolean isFriendsRecommendations(String optString){
|
||||
return friendsrecomm() && (optString.equals("user_rec") ||
|
||||
optString.equals("friends_recommendations") ||
|
||||
optString.equals("friends_recomm"));
|
||||
}
|
||||
|
||||
public static boolean isGroupAds(JSONObject obj) {
|
||||
public static boolean isGroupAds(JSONObject obj){
|
||||
return adsgroup() && obj.optInt("marked_as_ads", 0) == 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
import static java.lang.Long.MAX_VALUE;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.setProxy;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.CacheUtils.*;
|
||||
import static ru.vtosters.lite.utils.CacheUtils.getInstance;
|
||||
import static ru.vtosters.lite.utils.DeletedMessagesHandler.reloadMessagesList;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.setupFilters;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.setProxy;
|
||||
import static ru.vtosters.lite.utils.SignatureChecker.validateAppSignature;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.isDarkTheme;
|
||||
import static ru.vtosters.lite.utils.VTVerifications.isPrometheus;
|
||||
@@ -19,13 +15,12 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Environment;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.vtosters.lite.data.Users;
|
||||
import com.vtosters.lite.fragments.SettingsListFragment;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import ru.vtosters.lite.ui.fragments.VTSettings;
|
||||
@@ -35,19 +30,16 @@ public class Preferences {
|
||||
public static String VERSIONNAME = "Beta";
|
||||
|
||||
public static void init(Application application) throws Exception {
|
||||
setupFilters();
|
||||
GmsUtils.fixGapps();
|
||||
setProxy();
|
||||
reloadMessagesList();
|
||||
LifecycleUtils.registerActivities(application);
|
||||
getInstance().autoCleaningCache();
|
||||
} // VK Init
|
||||
|
||||
public static void forceOffline() {
|
||||
setupFilters();
|
||||
getInstance().autoCleaningCache();
|
||||
edit().putBoolean("isdark", isDarkTheme()).commit();
|
||||
|
||||
setupFilters();
|
||||
|
||||
if (setoffline() && offline()) {
|
||||
Users.a();
|
||||
}
|
||||
@@ -69,7 +61,7 @@ public class Preferences {
|
||||
}
|
||||
|
||||
public static boolean systemtheme() {
|
||||
return false; //getBoolValue("systemtheme", true) && VERSION.SDK_INT >= 28;
|
||||
return Build.VERSION.SDK_INT >= 28 && getBoolValue("systemtheme", true);
|
||||
}
|
||||
|
||||
public static boolean authorsrecomm() {
|
||||
@@ -112,10 +104,18 @@ public class Preferences {
|
||||
return getBoolValue("__dbg_no_slider_ads", true);
|
||||
}
|
||||
|
||||
public static boolean autocache() {
|
||||
return getBoolValue("autocache", false);
|
||||
}
|
||||
|
||||
public static boolean adsstories() {
|
||||
return getBoolValue("adsstories", true);
|
||||
}
|
||||
|
||||
public static boolean wbios() {
|
||||
return getBoolValue("wbios", false);
|
||||
}
|
||||
|
||||
public static boolean videofeed() {
|
||||
return getBoolValue("__dbg_disable_video_feed", false);
|
||||
}
|
||||
@@ -205,14 +205,6 @@ public class Preferences {
|
||||
return getBoolValue("milkshake", true);
|
||||
}
|
||||
|
||||
public static boolean musicnewcatalog() {
|
||||
return getBoolValue("musicnewcatalog", true);
|
||||
}
|
||||
|
||||
public static boolean videonewcatalog() {
|
||||
return getBoolValue("videonewcatalog", true);
|
||||
}
|
||||
|
||||
public static boolean postsredesign() {
|
||||
return getBoolValue("postsredesign", true);
|
||||
}
|
||||
@@ -332,7 +324,7 @@ public class Preferences {
|
||||
}
|
||||
|
||||
public static boolean checkupdates() {
|
||||
return getBoolValue("checkupdates", true) && isValidSignature();
|
||||
return !getBoolValue("isRoamingState", false) && isValidSignature();
|
||||
}
|
||||
|
||||
public static boolean isValidSignature() {
|
||||
@@ -363,22 +355,16 @@ public class Preferences {
|
||||
public static long getSizeForDelete() {
|
||||
switch (getPrefsValue("clearcache")) {
|
||||
case "100mb":
|
||||
needToDelete = true;
|
||||
return 104857600L;
|
||||
case "500mb":
|
||||
needToDelete = true;
|
||||
return 524288000L;
|
||||
case "1gb":
|
||||
needToDelete = true;
|
||||
return 1073741824L;
|
||||
case "2gb":
|
||||
needToDelete = true;
|
||||
return 2147483648L;
|
||||
case "5gb":
|
||||
needToDelete = true;
|
||||
return 5368709120L;
|
||||
default:
|
||||
needToDelete = false;
|
||||
return MAX_VALUE;
|
||||
}
|
||||
}
|
||||
@@ -389,28 +375,4 @@ public class Preferences {
|
||||
}
|
||||
return origquality;
|
||||
}
|
||||
|
||||
public static File getDownloadsDir() {
|
||||
return new File(getPreferences().getString(
|
||||
"downloads_directory",
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()));
|
||||
}
|
||||
|
||||
public static File getPhotosDir() {
|
||||
return new File(getPreferences().getString(
|
||||
"photos_directory",
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()));
|
||||
}
|
||||
|
||||
public static File getVideosDir() {
|
||||
return new File(getPreferences().getString(
|
||||
"videos_directory",
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath()));
|
||||
}
|
||||
|
||||
public static File getMusicDir() {
|
||||
return new File(getPreferences().getString(
|
||||
"music_directory",
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
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.proxy.ProxyUtils.isApiProxyEnabled;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.isDarkTheme;
|
||||
|
||||
public class SSFSUtils {
|
||||
@@ -39,7 +39,7 @@ public class SSFSUtils {
|
||||
}
|
||||
|
||||
public static String getUserProxy() {
|
||||
return isApiProxyEnabled() ? "1" : "0";
|
||||
return isAnyProxyEnabled() ? "1" : "0";
|
||||
}
|
||||
|
||||
public static String isVKSansEnabled() {
|
||||
|
||||
@@ -3,23 +3,21 @@ 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.edit;
|
||||
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.*;
|
||||
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.systemtheme;
|
||||
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.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
@@ -49,11 +47,22 @@ public class ThemesUtils {
|
||||
);
|
||||
|
||||
public static void applyTheme(VKTheme theme) {
|
||||
VKThemeHelper.theme(theme, LifecycleUtils.getCurrentActivity(), getCenterScreenCoords());
|
||||
var currentActivity = LifecycleUtils.getCurrentActivity();
|
||||
if (currentActivity != null) {
|
||||
try {
|
||||
VKThemeHelper.theme(theme, currentActivity, getCenterScreenCoords());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} // Apply VKTheme and ImTheme (hard applying without dynamic theme changing)
|
||||
|
||||
public static void setTheme(VKTheme theme, Activity activity) {
|
||||
if (activity == null) activity = LifecycleUtils.getCurrentActivity();
|
||||
if (activity == null) {
|
||||
activity = getCurrentActivity();
|
||||
|
||||
if (activity == null) return;
|
||||
}
|
||||
VKThemeHelper.theme(theme, activity, getCenterScreenCoords());
|
||||
ThemeTracker.a();
|
||||
isLoaded = false;
|
||||
@@ -62,7 +71,11 @@ public class ThemesUtils {
|
||||
} // apply changed theme
|
||||
|
||||
public static void setThemeFL(VKTheme theme, Activity activity, float[] fl) {
|
||||
if (activity == null) activity = LifecycleUtils.getCurrentActivity();
|
||||
if (activity == null) {
|
||||
activity = getCurrentActivity();
|
||||
|
||||
if (activity == null) return;
|
||||
}
|
||||
VKThemeHelper.theme(theme, activity, fl);
|
||||
ThemeTracker.a();
|
||||
isLoaded = false;
|
||||
@@ -329,20 +342,21 @@ public class ThemesUtils {
|
||||
}
|
||||
|
||||
public static void setNeededTheme(Activity activity) {
|
||||
var currentTheme = getCurrentTheme();
|
||||
if (milkshake()) {
|
||||
if (getCurrentTheme() == VKTheme.VKAPP_LIGHT) {
|
||||
if (currentTheme == VKTheme.VKAPP_LIGHT) {
|
||||
setTheme(VKTheme.VKAPP_MILK_LIGHT, activity);
|
||||
}
|
||||
|
||||
if (getCurrentTheme() == VKTheme.VKAPP_DARK) {
|
||||
if (currentTheme == VKTheme.VKAPP_DARK) {
|
||||
setTheme(VKTheme.VKAPP_MILK_DARK, activity);
|
||||
}
|
||||
} else {
|
||||
if (getCurrentTheme() == VKTheme.VKAPP_MILK_LIGHT) {
|
||||
if (currentTheme == VKTheme.VKAPP_MILK_LIGHT) {
|
||||
setTheme(VKTheme.VKAPP_LIGHT, activity);
|
||||
}
|
||||
|
||||
if (getCurrentTheme() == VKTheme.VKAPP_MILK_DARK) {
|
||||
if (currentTheme == VKTheme.VKAPP_MILK_DARK) {
|
||||
setTheme(VKTheme.VKAPP_DARK, activity);
|
||||
}
|
||||
}
|
||||
@@ -384,34 +398,6 @@ public class ThemesUtils {
|
||||
);
|
||||
}
|
||||
|
||||
public static void systemThemeChanger(Activity activity) { // ded
|
||||
boolean isDarkTheme = isDarkTheme();
|
||||
|
||||
if (!isDarkTheme) {
|
||||
applyTheme(getDarkTheme());
|
||||
} else {
|
||||
applyTheme(getLightTheme());
|
||||
}
|
||||
|
||||
if (!systemtheme()) {
|
||||
edit().putBoolean("isdark", isDarkTheme).commit();
|
||||
return;
|
||||
}
|
||||
|
||||
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
switch (currentNightMode) {
|
||||
case Configuration.UI_MODE_NIGHT_UNDEFINED:
|
||||
case Configuration.UI_MODE_NIGHT_NO:
|
||||
edit().putBoolean("isdark", false).commit();
|
||||
setTheme(getLightTheme(), activity);
|
||||
break;
|
||||
case Configuration.UI_MODE_NIGHT_YES:
|
||||
edit().putBoolean("isdark", true).commit();
|
||||
setTheme(getDarkTheme(), activity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void getCurrentThemeID(VKTheme paramVKTheme) {
|
||||
Preference.b("vk_theme_helper", "current_theme", paramVKTheme.getId());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
import static ru.vtosters.lite.net.Request.makeRequest;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getApi;
|
||||
import static ru.vtosters.lite.proxy.ProxyUtils.getOauth;
|
||||
import static ru.vtosters.lite.utils.AccountManagerUtils.getUserToken;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.edit;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getString;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class VKMeHandler{
|
||||
public static void getVkMeToken(String username, String password){
|
||||
makeRequest("https://" +
|
||||
getOauth() +
|
||||
"/token?" +
|
||||
"grant_type=password&client_id=6146827&client_secret=qVxWRF1CwHERuIrKBnqe&username=" +
|
||||
username +
|
||||
"&password=" +
|
||||
password +
|
||||
"&v=5.131&2fa_supported=1",
|
||||
response -> {
|
||||
try {
|
||||
JSONObject mainJson = new JSONObject(response);
|
||||
|
||||
if (mainJson.has("redirect_uri")){
|
||||
String redirect_uri = mainJson.getString("redirect_uri");
|
||||
// TODO open redirect_uri and get token
|
||||
} else if (mainJson.has("access_token")){
|
||||
setToken(mainJson.getString("access_token"));
|
||||
} else if (mainJson.has("error_description")){
|
||||
Log.d("VKMeHandler", mainJson.getString("error_description"));
|
||||
sendToast(getString("auth_error_vtl") + ": " + mainJson.getString("error_description"));
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.d("VKMeHandler", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setToken(String token){
|
||||
edit().putString("vkmetoken", token).commit();
|
||||
}
|
||||
|
||||
public static void removeToken(){
|
||||
edit().remove("vkmetoken").commit();
|
||||
}
|
||||
|
||||
public static String getToken(){
|
||||
return getPrefsValue("vkmetoken");
|
||||
}
|
||||
|
||||
public static void setPrivacyStatus(String status){
|
||||
// all, friends_and_contacts, only_me
|
||||
makeRequest("https://" + getApi() + "/method/account.setPrivacy?" + "v=5.140&key=online&value=" + status + "&https=1&access_token=" + getToken(),
|
||||
response -> {
|
||||
try {
|
||||
JSONObject mainJson = new JSONObject(response);
|
||||
} catch (JSONException e) {
|
||||
Log.d("VKMeHandler", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void getPrivacyStatus(){
|
||||
makeRequest("https://" + getApi() + "/method/execute?v=5.140&code=return API.account.getPrivacySettings().settings[22].value.category;&access_token=" + getToken(),
|
||||
response -> {
|
||||
try {
|
||||
String resp = new JSONObject(response).optString("response");
|
||||
|
||||
switch (resp){ // TODO make support for privacy
|
||||
case "all":
|
||||
case "friends_and_contacts":
|
||||
case "friends":
|
||||
case "only_me":
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.d("VKMeHandler", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class VTVerifications {
|
||||
public static void load(Context context) {
|
||||
var prefs = context.getSharedPreferences("vt_another_data", 0);
|
||||
|
||||
if (!NetworkUtils.isNetworkConnected() && prefs.contains("ids")) {
|
||||
if ((!NetworkUtils.isNetworkConnected() || getBoolValue("isRoamingState", false)) && prefs.contains("ids")) {
|
||||
parseJson(prefs.getString("ids", "[]"));
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.2.2'
|
||||
classpath 'com.android.tools.build:gradle:7.3.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
2966f42770fa9480b905416ecea04a6c4b401193
|
||||
Executable
BIN
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user