changed codestyle
This commit is contained in:
@@ -5,7 +5,7 @@ package bruhcollective.itaysonlab.libvkx;
|
||||
|
||||
// Works only with original signature of VT
|
||||
|
||||
public interface ILibVkxService extends android.os.IInterface {
|
||||
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;
|
||||
@@ -24,42 +24,42 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
/**
|
||||
* Default implementation for ILibVkxService.
|
||||
*/
|
||||
class Default implements 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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
public java.util.List<String> getCache() throws android.os.RemoteException{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.os.IBinder asBinder() {
|
||||
public android.os.IBinder asBinder(){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
/**
|
||||
* Local-side IPC implementation stub class.
|
||||
*/
|
||||
abstract class Stub extends android.os.Binder implements ILibVkxService {
|
||||
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);
|
||||
@@ -77,10 +77,11 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
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() {
|
||||
public Stub(){
|
||||
this.attachInterface(this, DESCRIPTOR);
|
||||
}
|
||||
|
||||
@@ -88,38 +89,38 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
* 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)) {
|
||||
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))) {
|
||||
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) {
|
||||
public static boolean setDefaultImpl(ILibVkxService impl){
|
||||
if(Proxy.sDefaultImpl == null && impl != null){
|
||||
Proxy.sDefaultImpl = impl;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ILibVkxService getDefaultImpl() {
|
||||
public static ILibVkxService getDefaultImpl(){
|
||||
return Proxy.sDefaultImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.os.IBinder asBinder() {
|
||||
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 {
|
||||
public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException{
|
||||
String descriptor = DESCRIPTOR;
|
||||
switch (code) {
|
||||
switch(code) {
|
||||
case INTERFACE_TRANSACTION: {
|
||||
reply.writeString(descriptor);
|
||||
return true;
|
||||
@@ -189,27 +190,27 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
}
|
||||
}
|
||||
|
||||
private static class Proxy implements ILibVkxService {
|
||||
private static class Proxy implements ILibVkxService{
|
||||
public static ILibVkxService sDefaultImpl;
|
||||
private final android.os.IBinder mRemote;
|
||||
|
||||
Proxy(android.os.IBinder remote) {
|
||||
Proxy(android.os.IBinder remote){
|
||||
mRemote = remote;
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.os.IBinder asBinder() {
|
||||
public android.os.IBinder asBinder(){
|
||||
return mRemote;
|
||||
}
|
||||
// Starts playback. playbackContext can be "other" if you don't sure what it is
|
||||
|
||||
public String getInterfaceDescriptor() {
|
||||
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 {
|
||||
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 {
|
||||
@@ -218,7 +219,7 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
_data.writeInt(index);
|
||||
_data.writeString(playbackContext);
|
||||
boolean _status = mRemote.transact(Stub.TRANSACTION_play, _data, _reply, 0);
|
||||
if (!_status && getDefaultImpl() != null) {
|
||||
if(!_status && getDefaultImpl() != null){
|
||||
getDefaultImpl().play(audio_ids, index, playbackContext);
|
||||
return;
|
||||
}
|
||||
@@ -231,14 +232,14 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
// Cache add/remove
|
||||
|
||||
@Override
|
||||
public int getUserId() throws android.os.RemoteException {
|
||||
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) {
|
||||
if(!_status && getDefaultImpl() != null){
|
||||
return getDefaultImpl().getUserId();
|
||||
}
|
||||
_reply.readException();
|
||||
@@ -251,7 +252,7 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTrackToCache(int track_id, int owner_id, String access_key) throws android.os.RemoteException {
|
||||
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 {
|
||||
@@ -260,7 +261,7 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
_data.writeInt(owner_id);
|
||||
_data.writeString(access_key);
|
||||
boolean _status = mRemote.transact(Stub.TRANSACTION_addTrackToCache, _data, _reply, 0);
|
||||
if (!_status && getDefaultImpl() != null) {
|
||||
if(!_status && getDefaultImpl() != null){
|
||||
getDefaultImpl().addTrackToCache(track_id, owner_id, access_key);
|
||||
return;
|
||||
}
|
||||
@@ -272,7 +273,7 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTrackFromCache(int track_id, int owner_id) throws android.os.RemoteException {
|
||||
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 {
|
||||
@@ -280,7 +281,7 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
_data.writeInt(track_id);
|
||||
_data.writeInt(owner_id);
|
||||
boolean _status = mRemote.transact(Stub.TRANSACTION_deleteTrackFromCache, _data, _reply, 0);
|
||||
if (!_status && getDefaultImpl() != null) {
|
||||
if(!_status && getDefaultImpl() != null){
|
||||
getDefaultImpl().deleteTrackFromCache(track_id, owner_id);
|
||||
return;
|
||||
}
|
||||
@@ -294,7 +295,7 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
// Also, the items in the list are JSON ones.
|
||||
|
||||
@Override
|
||||
public boolean isTrackCached(int track_id, int owner_id) throws android.os.RemoteException {
|
||||
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;
|
||||
@@ -303,7 +304,7 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
_data.writeInt(track_id);
|
||||
_data.writeInt(owner_id);
|
||||
boolean _status = mRemote.transact(Stub.TRANSACTION_isTrackCached, _data, _reply, 0);
|
||||
if (!_status && getDefaultImpl() != null) {
|
||||
if(!_status && getDefaultImpl() != null){
|
||||
return getDefaultImpl().isTrackCached(track_id, owner_id);
|
||||
}
|
||||
_reply.readException();
|
||||
@@ -316,14 +317,14 @@ public interface ILibVkxService extends android.os.IInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<String> getCache() throws android.os.RemoteException {
|
||||
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) {
|
||||
if(!_status && getDefaultImpl() != null){
|
||||
return getDefaultImpl().getCache();
|
||||
}
|
||||
_reply.readException();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package bruhcollective.itaysonlab.libvkx.client;
|
||||
|
||||
public class ClientConstants {
|
||||
public class ClientConstants{
|
||||
public final static String ACTION = "bruhcollective.itaysonlab.libvkx.LIBVKX_SERVICE";
|
||||
public final static String PACKAGE = "ua.itaysonlab.vkx";
|
||||
}
|
||||
|
||||
@@ -16,31 +16,31 @@ import java.util.List;
|
||||
import b.h.g.g.PackageManagerHelper;
|
||||
import bruhcollective.itaysonlab.libvkx.ILibVkxService;
|
||||
|
||||
public class LibVKXClient {
|
||||
public class LibVKXClient{
|
||||
private static LibVKXClientImpl impl;
|
||||
|
||||
public static LibVKXClientImpl getInstance(Context context) {
|
||||
if (impl == null) {
|
||||
public static LibVKXClientImpl getInstance(Context context){
|
||||
if(impl == null){
|
||||
impl = new LibVKXClientImpl(context);
|
||||
}
|
||||
return impl;
|
||||
}
|
||||
|
||||
public static LibVKXClientImpl getInstance() {
|
||||
public static LibVKXClientImpl getInstance(){
|
||||
LibVKXClientImpl libVKXClientImpl = impl;
|
||||
return libVKXClientImpl == null ? getInstance(getContext()) : libVKXClientImpl;
|
||||
}
|
||||
|
||||
public static boolean isVkxInstalled() {
|
||||
public static boolean isVkxInstalled(){
|
||||
return PackageManagerHelper.a(ClientConstants.PACKAGE, 128) != null;
|
||||
}
|
||||
|
||||
public static boolean isIntegrationEnabled() {
|
||||
public static boolean isIntegrationEnabled(){
|
||||
return getBoolValue("libvkx_integration", false) && isVkxInstalled();
|
||||
}
|
||||
|
||||
public static boolean play(MusicTrack musicTrack, List<MusicTrack> list, MusicPlaybackLaunchContext playerRefer) {
|
||||
if (!isIntegrationEnabled()) {
|
||||
public static boolean play(MusicTrack musicTrack, List<MusicTrack> list, MusicPlaybackLaunchContext playerRefer){
|
||||
if(!isIntegrationEnabled()){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -49,14 +49,14 @@ public class LibVKXClient {
|
||||
return getInstance().runOnService(action);
|
||||
}
|
||||
|
||||
public static void lambdaplay(List list, MusicTrack musicTrack, MusicPlaybackLaunchContext playerRefer, ILibVkxService iLibVkxService) {
|
||||
public static void lambdaplay(List list, MusicTrack musicTrack, MusicPlaybackLaunchContext playerRefer, ILibVkxService iLibVkxService){
|
||||
int indexOf = list.indexOf(musicTrack);
|
||||
ArrayList arrayList = new ArrayList();
|
||||
Iterator it = list.iterator();
|
||||
while (it.hasNext()) {
|
||||
while(it.hasNext()) {
|
||||
arrayList.add(asId((MusicTrack) it.next()));
|
||||
}
|
||||
if (indexOf == -1) {
|
||||
if(indexOf == -1){
|
||||
indexOf = 0;
|
||||
}
|
||||
try {
|
||||
@@ -66,9 +66,9 @@ public class LibVKXClient {
|
||||
}
|
||||
}
|
||||
|
||||
private static String asId(MusicTrack musicTrack) {
|
||||
private static String asId(MusicTrack musicTrack){
|
||||
String str = musicTrack.d + "_" + musicTrack.e;
|
||||
if (musicTrack.O == null || musicTrack.O.equals("")) {
|
||||
if(musicTrack.O == null || musicTrack.O.equals("")){
|
||||
return str;
|
||||
}
|
||||
return str + "_" + musicTrack.O;
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
|
||||
import bruhcollective.itaysonlab.libvkx.ILibVkxService;
|
||||
|
||||
public class LibVKXClientImpl {
|
||||
public class LibVKXClientImpl{
|
||||
private ILibVkxService serviceInstance;
|
||||
private PackageManager pm;
|
||||
private Context ctx;
|
||||
@@ -23,24 +23,24 @@ public class LibVKXClientImpl {
|
||||
|
||||
private boolean isBindFailed = false;
|
||||
|
||||
private LibVKXClientImpl() {
|
||||
private LibVKXClientImpl(){
|
||||
}
|
||||
|
||||
public LibVKXClientImpl(Context ctx) {
|
||||
public LibVKXClientImpl(Context ctx){
|
||||
this.ctx = ctx;
|
||||
this.pm = ctx.getPackageManager();
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
if (cn != null) {
|
||||
public void finish(){
|
||||
if(cn != null){
|
||||
ctx.unbindService(cn);
|
||||
}
|
||||
|
||||
serviceInstance = null;
|
||||
}
|
||||
|
||||
public <T> T runOnServiceSync(LibVKXActionGeneric<T> action) {
|
||||
if (serviceInstance != null) {
|
||||
public <T> T runOnServiceSync(LibVKXActionGeneric<T> action){
|
||||
if(serviceInstance != null){
|
||||
return action.run(serviceInstance);
|
||||
} else {
|
||||
return action.defaultValue();
|
||||
@@ -49,10 +49,10 @@ public class LibVKXClientImpl {
|
||||
|
||||
// true - action is ran
|
||||
// false - action is failed, should fallback to default UI/UX
|
||||
public boolean runOnService(LibVKXAction action) {
|
||||
if (serviceInstance != null) {
|
||||
public boolean runOnService(LibVKXAction action){
|
||||
if(serviceInstance != null){
|
||||
try {
|
||||
if (serviceInstance.getUserId() != getUserId()) return false;
|
||||
if(serviceInstance.getUserId() != getUserId()) return false;
|
||||
action.run(serviceInstance);
|
||||
return true;
|
||||
} catch (RemoteException e) {
|
||||
@@ -64,19 +64,19 @@ public class LibVKXClientImpl {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean requestServiceInit(LibVKXAction runAfterBind) {
|
||||
if (!verifyBindActuality()) return false;
|
||||
private boolean requestServiceInit(LibVKXAction runAfterBind){
|
||||
if(!verifyBindActuality()) return false;
|
||||
|
||||
cn = new ServiceConnection() {
|
||||
cn = new ServiceConnection(){
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
public void onServiceConnected(ComponentName name, IBinder service){
|
||||
serviceInstance = ILibVkxService.Stub.asInterface(service);
|
||||
if (serviceInstance == null) {
|
||||
if(serviceInstance == null){
|
||||
// op mycopok...
|
||||
isBindFailed = true;
|
||||
} else {
|
||||
try {
|
||||
if (serviceInstance.getUserId() != getUserId()) return;
|
||||
if(serviceInstance.getUserId() != getUserId()) return;
|
||||
runAfterBind.run(serviceInstance);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
@@ -85,7 +85,7 @@ public class LibVKXClientImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
public void onServiceDisconnected(ComponentName name){
|
||||
serviceInstance = null;
|
||||
}
|
||||
};
|
||||
@@ -94,34 +94,34 @@ public class LibVKXClientImpl {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean verifyBindActuality() {
|
||||
if (!checkIfAppExists()) return false; // no need
|
||||
private boolean verifyBindActuality(){
|
||||
if(!checkIfAppExists()) return false; // no need
|
||||
return !isBindFailed;
|
||||
}
|
||||
|
||||
private Intent getIntent() {
|
||||
private Intent getIntent(){
|
||||
return new Intent(ClientConstants.ACTION).setPackage(ClientConstants.PACKAGE);
|
||||
}
|
||||
|
||||
private boolean checkIfAppExists() {
|
||||
private boolean checkIfAppExists(){
|
||||
List<ResolveInfo> resolveInfos = pm.queryIntentServices(getIntent(), 0);
|
||||
if (resolveInfos == null || resolveInfos.isEmpty()) return false;
|
||||
if(resolveInfos == null || resolveInfos.isEmpty()) return false;
|
||||
|
||||
for (ResolveInfo rs : resolveInfos) {
|
||||
if (rs.serviceInfo.packageName.equals(ClientConstants.PACKAGE)) return true;
|
||||
for(ResolveInfo rs : resolveInfos) {
|
||||
if(rs.serviceInfo.packageName.equals(ClientConstants.PACKAGE)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public interface LibVKXAction {
|
||||
public interface LibVKXAction{
|
||||
void run(ILibVkxService service);
|
||||
}
|
||||
|
||||
public interface LibVKXActionGeneric<T> {
|
||||
public interface LibVKXActionGeneric<T>{
|
||||
T run(ILibVkxService service);
|
||||
|
||||
default T defaultValue() {
|
||||
default T defaultValue(){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,35 +3,35 @@ package com.aefyr.tsg.g2;
|
||||
/**
|
||||
* Created by Aefyr on 19.05.2018.
|
||||
*/
|
||||
public abstract class CustomStickersEventsListener implements TelegramStickersService.StickersEventsListener {
|
||||
public abstract class CustomStickersEventsListener implements TelegramStickersService.StickersEventsListener{
|
||||
|
||||
@Override
|
||||
public void onPackAdded(TelegramStickersPack pack, int atIndex) {
|
||||
public void onPackAdded(TelegramStickersPack pack, int atIndex){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackChanged(TelegramStickersPack pack, int atIndex) {
|
||||
public void onPackChanged(TelegramStickersPack pack, int atIndex){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackRemoved(TelegramStickersPack pack, int atIndex) {
|
||||
public void onPackRemoved(TelegramStickersPack pack, int atIndex){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackDownloadError(TelegramStickersPack pack, Exception error) {
|
||||
public void onPackDownloadError(TelegramStickersPack pack, Exception error){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivePacksListChanged() {
|
||||
public void onActivePacksListChanged(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInactivePacksListChanged() {
|
||||
public void onInactivePacksListChanged(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.io.File;
|
||||
/**
|
||||
* Created by Aefyr on 20.05.2018.
|
||||
*/
|
||||
public abstract class CustomStickersPack {
|
||||
public abstract class CustomStickersPack{
|
||||
|
||||
public abstract File folder();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
/**
|
||||
* Created by Aefyr on 20.05.2018.
|
||||
*/
|
||||
public class NotificationsHelper {
|
||||
public class NotificationsHelper{
|
||||
private static final int NOTIFICATION_ID_BASE = 3921337;
|
||||
private static final String NOTIFICATION_CHANNEL_ID = "tgss_chan_v5";
|
||||
private static final int MAX_UPDATE_NOTIFICATIONS_PER_SECOND = 3;
|
||||
@@ -26,23 +26,23 @@ public class NotificationsHelper {
|
||||
private final HashMap<TelegramStickersPack, Integer> downloadingPacksNotificationsIds;
|
||||
private final Context c;
|
||||
private final NotificationManagerCompat manager;
|
||||
private int currentNotificationN = 0;
|
||||
private final AtomicLong lastNotificationTime = new AtomicLong(0);
|
||||
private int currentNotificationN = 0;
|
||||
|
||||
public NotificationsHelper(Context c) {
|
||||
public NotificationsHelper(Context c){
|
||||
this.c = c;
|
||||
manager = NotificationManagerCompat.from(c);
|
||||
|
||||
|
||||
downloadingPacksNotificationsIds = new HashMap<>();
|
||||
|
||||
if (oreo()) {
|
||||
if(oreo()){
|
||||
NotificationChannel notificationChan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Сервис стикеров Telegram в VTosters", NotificationManager.IMPORTANCE_HIGH);
|
||||
((NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(notificationChan);
|
||||
}
|
||||
}
|
||||
|
||||
public void packStartedDownloading(TelegramStickersPack pack) {
|
||||
public void packStartedDownloading(TelegramStickersPack pack){
|
||||
int notificationId = NOTIFICATION_ID_BASE + currentNotificationN++;
|
||||
downloadingPacksNotificationsIds.put(pack, notificationId);
|
||||
|
||||
@@ -54,8 +54,8 @@ public class NotificationsHelper {
|
||||
manager.notify(notificationId, builder.build());
|
||||
}
|
||||
|
||||
public void packDownloadUpdated(TelegramStickersPack pack, int downloadProgress) {
|
||||
if (System.currentTimeMillis() - lastNotificationTime.get() < MIN_TIME_BETWEEN_UPDATE_NOTIFICATIONS)
|
||||
public void packDownloadUpdated(TelegramStickersPack pack, int downloadProgress){
|
||||
if(System.currentTimeMillis() - lastNotificationTime.get() < MIN_TIME_BETWEEN_UPDATE_NOTIFICATIONS)
|
||||
return;
|
||||
|
||||
lastNotificationTime.set(System.currentTimeMillis());
|
||||
@@ -67,23 +67,23 @@ public class NotificationsHelper {
|
||||
builder.setOngoing(true);
|
||||
builder.setOnlyAlertOnce(true);
|
||||
|
||||
if (downloadingPacksNotificationsIds.containsKey(pack))
|
||||
if(downloadingPacksNotificationsIds.containsKey(pack))
|
||||
manager.notify(downloadingPacksNotificationsIds.get(pack), builder.build());
|
||||
}
|
||||
|
||||
public void packDoneDownloading(TelegramStickersPack pack, boolean success, boolean wasUpdate, @Nullable Exception e) {
|
||||
public void packDoneDownloading(TelegramStickersPack pack, boolean success, boolean wasUpdate, @Nullable Exception e){
|
||||
Notification.Builder builder = commonBuilder();
|
||||
builder.setProgress(0, 0, false);
|
||||
builder.setOngoing(false);
|
||||
builder.setContentTitle("Сервис стикеров Telegram в VTosters");
|
||||
|
||||
String text;
|
||||
if (success)
|
||||
if(success)
|
||||
text = wasUpdate ? pack.title + " успешно обновлен" : pack.title + " успешно загружен";
|
||||
else
|
||||
text = wasUpdate ? pack.title + ": ошибка при обновлении" : pack.title + ": ошибка при загрузке";
|
||||
|
||||
if (e instanceof TelegramStickersGrabber.TSGException) {
|
||||
if(e instanceof TelegramStickersGrabber.TSGException){
|
||||
text = pack.title + ": " + e.getMessage();
|
||||
}
|
||||
|
||||
@@ -92,20 +92,20 @@ public class NotificationsHelper {
|
||||
manager.notify(downloadingPacksNotificationsIds.remove(pack), builder.build());
|
||||
}
|
||||
|
||||
public void removePackNotification(TelegramStickersPack pack) {
|
||||
public void removePackNotification(TelegramStickersPack pack){
|
||||
manager.cancel(downloadingPacksNotificationsIds.remove(pack));
|
||||
}
|
||||
|
||||
private Notification.Builder commonBuilder() {
|
||||
private Notification.Builder commonBuilder(){
|
||||
var builder = new Notification.Builder(c).setPriority(Notification.PRIORITY_MAX).setSmallIcon(com.vtosters.lite.R.drawable.icon_vk_104);
|
||||
if (oreo()) {
|
||||
if(oreo()){
|
||||
builder.setChannelId(NOTIFICATION_CHANNEL_ID);
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
private boolean oreo() {
|
||||
private boolean oreo(){
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,20 +8,20 @@ import java.io.File;
|
||||
/**
|
||||
* Created by Aefyr on 20.05.2018.
|
||||
*/
|
||||
class PackDeletionTask extends AsyncTask<Void, Void, Boolean> {
|
||||
class PackDeletionTask extends AsyncTask<Void, Void, Boolean>{
|
||||
private static final String TAG = "TGSSAnnihilator";
|
||||
|
||||
private final TelegramStickersPack pack;
|
||||
|
||||
PackDeletionTask(TelegramStickersPack pack) {
|
||||
PackDeletionTask(TelegramStickersPack pack){
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
protected Boolean doInBackground(Void... voids){
|
||||
boolean success = true;
|
||||
|
||||
for (File f : pack.folder.listFiles()) {
|
||||
for(File f : pack.folder.listFiles()) {
|
||||
success = success && f.delete();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class PackDeletionTask extends AsyncTask<Void, Void, Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean aBoolean) {
|
||||
protected void onPostExecute(Boolean aBoolean){
|
||||
Log.d(TAG, String.format("Attempted deleting pack %s, success?%s", pack.id, aBoolean));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by Aefyr on 18.05.2018.
|
||||
*/
|
||||
public class TelegramStickersPack extends CustomStickersPack {
|
||||
public class TelegramStickersPack extends CustomStickersPack{
|
||||
|
||||
public static final int UNKNOWN = -1;
|
||||
public static final int DOWNLOADED = 0;
|
||||
@@ -35,38 +35,38 @@ public class TelegramStickersPack extends CustomStickersPack {
|
||||
|
||||
public HashMap<String, List<Integer>> emojis = new HashMap<>();
|
||||
|
||||
public TelegramStickersPack(String id) {
|
||||
public TelegramStickersPack(String id){
|
||||
this.id = id.toLowerCase();
|
||||
title = id;
|
||||
}
|
||||
|
||||
public JSONObject encodeEmojis() throws JSONException {
|
||||
public JSONObject encodeEmojis() throws JSONException{
|
||||
JSONObject obj = new JSONObject();
|
||||
for (HashMap.Entry<String, List<Integer>> en : emojis.entrySet()) {
|
||||
for(HashMap.Entry<String, List<Integer>> en : emojis.entrySet()) {
|
||||
JSONArray arr = new JSONArray();
|
||||
for (int i : en.getValue()) arr.put(i);
|
||||
for(int i : en.getValue()) arr.put(i);
|
||||
obj.put(en.getKey(), arr);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void loadEmojis(JSONObject obj) throws JSONException {
|
||||
public void loadEmojis(JSONObject obj) throws JSONException{
|
||||
Iterator<String> it = obj.keys();
|
||||
while (it.hasNext()) {
|
||||
while(it.hasNext()) {
|
||||
String key = it.next();
|
||||
//emojis.put(key, obj.getInt(key));
|
||||
List<Integer> list = emojis.get(key);
|
||||
if (list == null) list = new ArrayList<>();
|
||||
if(list == null) list = new ArrayList<>();
|
||||
JSONArray arr = obj.getJSONArray(key);
|
||||
for (int i = 0; i < arr.length(); i++)
|
||||
for(int i = 0; i < arr.length(); i++)
|
||||
list.add(arr.getInt(i));
|
||||
emojis.put(key, list);
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap getIcon(int targetMaxSideSize) {
|
||||
if (state != DOWNLOADED && state != UPDATING)
|
||||
public Bitmap getIcon(int targetMaxSideSize){
|
||||
if(state != DOWNLOADED && state != UPDATING)
|
||||
throw new IllegalStateException("Unable to get an icon of a pack that hasn't been downloaded yet");
|
||||
|
||||
File icon = new File(folder, "001.png");
|
||||
@@ -74,7 +74,7 @@ public class TelegramStickersPack extends CustomStickersPack {
|
||||
return getScaledBitmap(icon, targetMaxSideSize);
|
||||
}
|
||||
|
||||
private Bitmap getScaledBitmap(File bitmapFile, int targetMaxSideSize) {
|
||||
private Bitmap getScaledBitmap(File bitmapFile, int targetMaxSideSize){
|
||||
BitmapFactory.Options op = new BitmapFactory.Options();
|
||||
op.inJustDecodeBounds = true;
|
||||
op.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
||||
@@ -85,7 +85,7 @@ public class TelegramStickersPack extends CustomStickersPack {
|
||||
|
||||
int maxSideSize = op.outWidth > op.outHeight ? op.outWidth : op.outHeight;
|
||||
|
||||
if (maxSideSize > targetMaxSideSize) {
|
||||
if(maxSideSize > targetMaxSideSize){
|
||||
op.inScaled = true;
|
||||
op.inDensity = maxSideSize;
|
||||
op.inTargetDensity = targetMaxSideSize;
|
||||
@@ -100,46 +100,46 @@ public class TelegramStickersPack extends CustomStickersPack {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(Object obj){
|
||||
return obj instanceof TelegramStickersPack && ((TelegramStickersPack) obj).id.equalsIgnoreCase(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
public int hashCode(){
|
||||
return id.toLowerCase().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File folder() {
|
||||
public File folder(){
|
||||
return folder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int stickersCount() {
|
||||
public int stickersCount(){
|
||||
return stickersCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public String name(){
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getIconBitmap() {
|
||||
public Bitmap getIconBitmap(){
|
||||
return getIcon(128);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getStickerBitmap(int index) {
|
||||
public Bitmap getStickerBitmap(int index){
|
||||
return BitmapFactory.decodeFile(new File(folder, String.format("%03d.png", index + 1)).getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getStickerFile(int index) {
|
||||
public File getStickerFile(int index){
|
||||
return new File(folder, String.format("%03d.png", index + 1));
|
||||
}
|
||||
|
||||
public Bitmap getStickerBitmap(int index, int maxSize) {
|
||||
public Bitmap getStickerBitmap(int index, int maxSize){
|
||||
return getScaledBitmap(new File(folder, String.format("%03d.png", index + 1)), maxSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import ru.vtosters.lite.ui.fragments.tgstickers.StickersFragment;
|
||||
/**
|
||||
* Created by Aefyr on 19.05.2018.
|
||||
*/
|
||||
public class TelegramStickersService {
|
||||
public class TelegramStickersService{
|
||||
private static final String TAG = "TGStickersService";
|
||||
private static TelegramStickersService instance;
|
||||
|
||||
@@ -41,14 +41,12 @@ public class TelegramStickersService {
|
||||
private final TelegramStickersGrabber grabber;
|
||||
|
||||
private final TelegramStickersDbHelper dbHelper;
|
||||
private boolean ready = false;
|
||||
private final ArrayList<Runnable> queuedTasks;
|
||||
|
||||
private final ThreadPoolExecutor executor;
|
||||
|
||||
private final NotificationsHelper notificationsHelper;
|
||||
private boolean ready = false;
|
||||
|
||||
private TelegramStickersService(Context context) {
|
||||
private TelegramStickersService(Context context){
|
||||
instance = this;
|
||||
|
||||
this.c = context.getApplicationContext();
|
||||
@@ -69,138 +67,138 @@ public class TelegramStickersService {
|
||||
updatePacks(true);
|
||||
}
|
||||
|
||||
public static TelegramStickersService getInstance(Context c) {
|
||||
public static TelegramStickersService getInstance(Context c){
|
||||
return instance == null ? new TelegramStickersService(c) : instance;
|
||||
}
|
||||
|
||||
private void updatePacks(final boolean notify) {
|
||||
private void updatePacks(final boolean notify){
|
||||
packs.clear();
|
||||
dbHelper.getAllPacks(new TelegramStickersDbHelper.PacksLoadingListener() {
|
||||
dbHelper.getAllPacks(new TelegramStickersDbHelper.PacksLoadingListener(){
|
||||
@Override
|
||||
public void onPackLoaded(final TelegramStickersPack pack) {
|
||||
public void onPackLoaded(final TelegramStickersPack pack){
|
||||
runOnUiThread(() -> {
|
||||
packs.add(pack);
|
||||
|
||||
if (pack.enabled)
|
||||
if(pack.enabled)
|
||||
activePacks.add(pack);
|
||||
else
|
||||
inactivePacks.add(pack);
|
||||
|
||||
if (notify) notifyPackAdded(pack, packs.size() - 1);
|
||||
if(notify) notifyPackAdded(pack, packs.size() - 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAllPacksLoaded(ArrayList<TelegramStickersPack> packs) {
|
||||
public void onAllPacksLoaded(ArrayList<TelegramStickersPack> packs){
|
||||
ready = true;
|
||||
|
||||
if (notify) {
|
||||
if(notify){
|
||||
notifyActivePacksListChanged();
|
||||
notifyInactivePacksListChanged();
|
||||
}
|
||||
|
||||
Log.d(TAG, String.format("Packs list loaded, running %d queued tasks...", queuedTasks.size()));
|
||||
while (!queuedTasks.isEmpty())
|
||||
while(!queuedTasks.isEmpty())
|
||||
queuedTasks.remove(0).run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addStickersEventsListener(StickersEventsListener listener) {
|
||||
public void addStickersEventsListener(StickersEventsListener listener){
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeStickersEventsListener(StickersEventsListener listener) {
|
||||
public void removeStickersEventsListener(StickersEventsListener listener){
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
private void notifyPackAdded(TelegramStickersPack pack, int atIndex) {
|
||||
private void notifyPackAdded(TelegramStickersPack pack, int atIndex){
|
||||
getContext().sendBroadcast(new Intent(StickersFragment.ACTION_RELOAD));
|
||||
if (listeners.isEmpty())
|
||||
if(listeners.isEmpty())
|
||||
return;
|
||||
|
||||
for (StickersEventsListener listener : listeners) {
|
||||
for(StickersEventsListener listener : listeners) {
|
||||
listener.onPackAdded(pack, atIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyPackChanged(TelegramStickersPack pack, int atIndex) {
|
||||
private void notifyPackChanged(TelegramStickersPack pack, int atIndex){
|
||||
getContext().sendBroadcast(new Intent(StickersFragment.ACTION_RELOAD));
|
||||
if (listeners.isEmpty())
|
||||
if(listeners.isEmpty())
|
||||
return;
|
||||
|
||||
for (StickersEventsListener listener : listeners) {
|
||||
for(StickersEventsListener listener : listeners) {
|
||||
listener.onPackChanged(pack, atIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyPackRemoved(TelegramStickersPack pack, int atIndex) {
|
||||
private void notifyPackRemoved(TelegramStickersPack pack, int atIndex){
|
||||
getContext().sendBroadcast(new Intent(StickersFragment.ACTION_RELOAD));
|
||||
if (listeners.isEmpty())
|
||||
if(listeners.isEmpty())
|
||||
return;
|
||||
|
||||
for (StickersEventsListener listener : listeners) {
|
||||
for(StickersEventsListener listener : listeners) {
|
||||
listener.onPackRemoved(pack, atIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyPackDownloadError(TelegramStickersPack pack, Exception error) {
|
||||
private void notifyPackDownloadError(TelegramStickersPack pack, Exception error){
|
||||
getContext().sendBroadcast(new Intent(StickersFragment.ACTION_RELOAD));
|
||||
if (listeners.isEmpty())
|
||||
if(listeners.isEmpty())
|
||||
return;
|
||||
|
||||
for (StickersEventsListener listener : listeners) {
|
||||
for(StickersEventsListener listener : listeners) {
|
||||
listener.onPackDownloadError(pack, error);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyActivePacksListChanged() {
|
||||
private void notifyActivePacksListChanged(){
|
||||
getContext().sendBroadcast(new Intent(StickersFragment.ACTION_RELOAD));
|
||||
if (listeners.isEmpty())
|
||||
if(listeners.isEmpty())
|
||||
return;
|
||||
|
||||
for (StickersEventsListener listener : listeners) {
|
||||
for(StickersEventsListener listener : listeners) {
|
||||
listener.onActivePacksListChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyInactivePacksListChanged() {
|
||||
private void notifyInactivePacksListChanged(){
|
||||
getContext().sendBroadcast(new Intent(StickersFragment.ACTION_RELOAD));
|
||||
if (listeners.isEmpty())
|
||||
if(listeners.isEmpty())
|
||||
return;
|
||||
|
||||
for (StickersEventsListener listener : listeners) {
|
||||
for(StickersEventsListener listener : listeners) {
|
||||
listener.onInactivePacksListChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void setBotKey(String botKey) {
|
||||
public void setBotKey(String botKey){
|
||||
grabber.setBotApiKey(botKey);
|
||||
}
|
||||
|
||||
public ArrayList<TelegramStickersPack> getPacksListReference() {
|
||||
public ArrayList<TelegramStickersPack> getPacksListReference(){
|
||||
return packs;
|
||||
}
|
||||
|
||||
public ArrayList<TelegramStickersPack> getActivePacksListReference() {
|
||||
public ArrayList<TelegramStickersPack> getActivePacksListReference(){
|
||||
return activePacks;
|
||||
}
|
||||
|
||||
public ArrayList<TelegramStickersPack> getInactivePacksListReference() {
|
||||
public ArrayList<TelegramStickersPack> getInactivePacksListReference(){
|
||||
return inactivePacks;
|
||||
}
|
||||
|
||||
public boolean isDoneLoading() {
|
||||
public boolean isDoneLoading(){
|
||||
return ready;
|
||||
}
|
||||
|
||||
public boolean requestPackDownload(final String id, File packFolder) {
|
||||
if (currentlyDownloading.contains(id)) {
|
||||
public boolean requestPackDownload(final String id, File packFolder){
|
||||
if(currentlyDownloading.contains(id)){
|
||||
Log.e(TAG, String.format("Got request to download pack %s which is already downloading", id));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ready) {
|
||||
if(!ready){
|
||||
final File folder = packFolder;
|
||||
queuedTasks.add(() -> requestPackDownload(id, folder));
|
||||
return true;
|
||||
@@ -210,7 +208,7 @@ public class TelegramStickersService {
|
||||
boolean update = false;
|
||||
|
||||
int index = packs.indexOf(pack);
|
||||
if (index != -1) {
|
||||
if(index != -1){
|
||||
pack = packs.get(index);
|
||||
pack.state = TelegramStickersPack.UPDATING;
|
||||
update = true;
|
||||
@@ -230,9 +228,9 @@ public class TelegramStickersService {
|
||||
notificationsHelper.packStartedDownloading(newPack);
|
||||
|
||||
grabber.enableProxy();
|
||||
grabber.grabPack(id, packFolder, pack.version, new TelegramStickersGrabber.PackDownloadListener() {
|
||||
grabber.grabPack(id, packFolder, pack.version, new TelegramStickersGrabber.PackDownloadListener(){
|
||||
@Override
|
||||
public void onPackDownloaded(TelegramStickersPackInfo packInfo, boolean newVersionFound) {
|
||||
public void onPackDownloaded(TelegramStickersPackInfo packInfo, boolean newVersionFound){
|
||||
|
||||
runOnUiThread(() -> {
|
||||
newPack.state = TelegramStickersPack.DOWNLOADED;
|
||||
@@ -240,8 +238,8 @@ public class TelegramStickersService {
|
||||
currentlyDownloading.remove(newPack.id.toLowerCase());
|
||||
syncPack(newPack);
|
||||
|
||||
if (isUpdate) {
|
||||
if (newPack.enabled)
|
||||
if(isUpdate){
|
||||
if(newPack.enabled)
|
||||
notifyActivePacksListChanged();
|
||||
} else {
|
||||
activePacks.add(newPack);
|
||||
@@ -252,12 +250,12 @@ public class TelegramStickersService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackDownloadError(final Exception e) {
|
||||
public void onPackDownloadError(final Exception e){
|
||||
runOnUiThread(() -> {
|
||||
Log.e(TAG, "Error while downloading pack " + newPack.id);
|
||||
e.printStackTrace();
|
||||
|
||||
if (!isUpdate) {
|
||||
if(!isUpdate){
|
||||
int index = packs.indexOf(newPack);
|
||||
packs.remove(index);
|
||||
notifyPackRemoved(newPack, index);
|
||||
@@ -273,7 +271,7 @@ public class TelegramStickersService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGotPackInfo(final TelegramStickersPackInfo packInfo) {
|
||||
public void onGotPackInfo(final TelegramStickersPackInfo packInfo){
|
||||
runOnUiThread(() -> {
|
||||
newPack.title = packInfo.title;
|
||||
newPack.stickersCount = packInfo.stickersCount;
|
||||
@@ -285,11 +283,11 @@ public class TelegramStickersService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStickerDownloaded(String pack, File sticker, String boundEmoji, int stickerIndex, int downloadedStickersCount, int totalStickersCount) {
|
||||
public void onStickerDownloaded(String pack, File sticker, String boundEmoji, int stickerIndex, int downloadedStickersCount, int totalStickersCount){
|
||||
stickerIndex--;
|
||||
|
||||
List<Integer> list = newPack.emojis.get(boundEmoji);
|
||||
if (list == null) list = new ArrayList<>();
|
||||
if(list == null) list = new ArrayList<>();
|
||||
list.add(stickerIndex);
|
||||
newPack.emojis.put(boundEmoji, list);
|
||||
|
||||
@@ -300,34 +298,34 @@ public class TelegramStickersService {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setPackEnabled(final TelegramStickersPack pack, final boolean enabled, final boolean notify) {
|
||||
if (!ready) {
|
||||
public void setPackEnabled(final TelegramStickersPack pack, final boolean enabled, final boolean notify){
|
||||
if(!ready){
|
||||
queuedTasks.add(() -> setPackEnabled(pack, enabled, notify));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pack.enabled == enabled)
|
||||
if(pack.enabled == enabled)
|
||||
return;
|
||||
|
||||
pack.enabled = enabled;
|
||||
syncPack(pack);
|
||||
if (notify) notifyPackChanged(pack, packs.indexOf(pack));
|
||||
if(notify) notifyPackChanged(pack, packs.indexOf(pack));
|
||||
|
||||
if (pack.enabled) {
|
||||
if(pack.enabled){
|
||||
inactivePacks.remove(pack);
|
||||
activePacks.add(pack);
|
||||
} else {
|
||||
activePacks.remove(pack);
|
||||
inactivePacks.add(pack);
|
||||
}
|
||||
if (notify) {
|
||||
if(notify){
|
||||
notifyActivePacksListChanged();
|
||||
notifyInactivePacksListChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void deletePack(final TelegramStickersPack pack) {
|
||||
if (!ready) {
|
||||
public void deletePack(final TelegramStickersPack pack){
|
||||
if(!ready){
|
||||
queuedTasks.add(() -> deletePack(pack));
|
||||
return;
|
||||
}
|
||||
@@ -340,7 +338,7 @@ public class TelegramStickersService {
|
||||
packs.remove(index);
|
||||
notifyPackRemoved(pack, index);
|
||||
|
||||
if (pack.enabled) {
|
||||
if(pack.enabled){
|
||||
activePacks.remove(pack);
|
||||
notifyActivePacksListChanged();
|
||||
} else {
|
||||
@@ -348,16 +346,16 @@ public class TelegramStickersService {
|
||||
notifyInactivePacksListChanged();
|
||||
}
|
||||
|
||||
if (d)
|
||||
if(d)
|
||||
new PackDeletionTask(pack).executeOnExecutor(executor);
|
||||
}
|
||||
|
||||
private void runOnUiThread(Runnable r) {
|
||||
private void runOnUiThread(Runnable r){
|
||||
uiThreadHandler.post(r);
|
||||
}
|
||||
|
||||
private void syncPack(final TelegramStickersPack pack) {
|
||||
if (!ready) {
|
||||
private void syncPack(final TelegramStickersPack pack){
|
||||
if(!ready){
|
||||
queuedTasks.add(() -> syncPack(pack));
|
||||
return;
|
||||
}
|
||||
@@ -365,7 +363,7 @@ public class TelegramStickersService {
|
||||
Log.d(TAG, "Sync=" + dbHelper.syncPack(pack));
|
||||
}
|
||||
|
||||
public void swap(TelegramStickersPack p1, TelegramStickersPack p2) {
|
||||
public void swap(TelegramStickersPack p1, TelegramStickersPack p2){
|
||||
int i1 = p1.index;
|
||||
int i2 = p2.index;
|
||||
p1.index = i2;
|
||||
@@ -373,7 +371,7 @@ public class TelegramStickersService {
|
||||
syncPack(p1);
|
||||
syncPack(p2);
|
||||
|
||||
if (getActivePacksListReference().contains(p1) && getActivePacksListReference().contains(p2) || getInactivePacksListReference().contains(p1) && getInactivePacksListReference().contains(p2)) {
|
||||
if(getActivePacksListReference().contains(p1) && getActivePacksListReference().contains(p2) || getInactivePacksListReference().contains(p1) && getInactivePacksListReference().contains(p2)){
|
||||
int li1 = getActivePacksListReference().indexOf(p1);
|
||||
int li2 = getActivePacksListReference().indexOf(p2);
|
||||
getActivePacksListReference().set(li2, p1);
|
||||
@@ -385,7 +383,7 @@ public class TelegramStickersService {
|
||||
getPacksListReference().set(li1, p2);
|
||||
}
|
||||
|
||||
interface StickersEventsListener {
|
||||
interface StickersEventsListener{
|
||||
void onPackAdded(TelegramStickersPack pack, int atIndex);
|
||||
|
||||
void onPackRemoved(TelegramStickersPack pack, int atIndex);
|
||||
|
||||
@@ -5,16 +5,16 @@ import android.provider.BaseColumns;
|
||||
/**
|
||||
* Created by Aefyr on 19.05.2018.
|
||||
*/
|
||||
public final class TelegramStickersContract {
|
||||
public final class TelegramStickersContract{
|
||||
|
||||
public static final String SQL_CREATE_ENTRIES = String.format("CREATE TABLE %s (%s INTEGER PRIMARY KEY, %s INTEGER AUTO_INCREMENT, %s TEXT, %s TEXT, %s TEXT, %s INTEGER, %s INTEGER, %s TEXT, %s TEXT)",
|
||||
StickersTableEntry.TABLE_NAME, StickersTableEntry._ID, StickersTableEntry.COLUMN_NAME_INDEX, StickersTableEntry.COLUMN_NAME_ID, StickersTableEntry.COLUMN_NAME_NAME,
|
||||
StickersTableEntry.COLUMN_NAME_FOLDER, StickersTableEntry.COLUMN_NAME_STICKERS_COUNT, StickersTableEntry.COLUMN_NAME_ENABLED, StickersTableEntry.COLUMN_NAME_VERSION, StickersTableEntry.COLUMN_NAME_EMOJIS);
|
||||
|
||||
private TelegramStickersContract() {
|
||||
private TelegramStickersContract(){
|
||||
}
|
||||
|
||||
public static class StickersTableEntry implements BaseColumns {
|
||||
public static class StickersTableEntry implements BaseColumns{
|
||||
public static final String TABLE_NAME = "packs";
|
||||
|
||||
public static final String COLUMN_NAME_ID = "id";
|
||||
|
||||
@@ -20,35 +20,35 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* Created by Aefyr on 19.05.2018.
|
||||
*/
|
||||
public class TelegramStickersDbHelper extends SQLiteOpenHelper {
|
||||
public class TelegramStickersDbHelper extends SQLiteOpenHelper{
|
||||
private static final int DB_VERSION = 2;
|
||||
private static final String DB_NAME = "TelegramStickers.db";
|
||||
|
||||
private SQLiteDatabase writableDb;
|
||||
private SQLiteDatabase readableDb;
|
||||
|
||||
public TelegramStickersDbHelper(Context context) {
|
||||
public TelegramStickersDbHelper(Context context){
|
||||
super(context, DB_NAME, null, DB_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
public void onCreate(SQLiteDatabase db){
|
||||
db.execSQL(TelegramStickersContract.SQL_CREATE_ENTRIES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
if (oldVersion == 1 && newVersion == 2) {
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
|
||||
if(oldVersion == 1 && newVersion == 2){
|
||||
db.execSQL(String.format("ALTER TABLE %s ADD COLUMN %s TEXT", TelegramStickersContract.StickersTableEntry.TABLE_NAME, TelegramStickersContract.StickersTableEntry.COLUMN_NAME_EMOJIS));
|
||||
}
|
||||
}
|
||||
|
||||
public void loadDatabases() {
|
||||
public void loadDatabases(){
|
||||
writableDb = getWritableDatabase();
|
||||
readableDb = getReadableDatabase();
|
||||
}
|
||||
|
||||
public boolean syncPack(TelegramStickersPack pack) {
|
||||
public boolean syncPack(TelegramStickersPack pack){
|
||||
ContentValues sqlPack = new ContentValues();
|
||||
sqlPack.put(TelegramStickersContract.StickersTableEntry.COLUMN_NAME_ID, pack.id);
|
||||
sqlPack.put(TelegramStickersContract.StickersTableEntry.COLUMN_NAME_NAME, pack.title);
|
||||
@@ -61,12 +61,12 @@ public class TelegramStickersDbHelper extends SQLiteOpenHelper {
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (pack.index == -1) pack.index = getNewIndex();
|
||||
if(pack.index == -1) pack.index = getNewIndex();
|
||||
sqlPack.put(TelegramStickersContract.StickersTableEntry.COLUMN_NAME_INDEX, pack.index);
|
||||
|
||||
int s = writableDb.updateWithOnConflict(TelegramStickersContract.StickersTableEntry.TABLE_NAME, sqlPack, TelegramStickersContract.StickersTableEntry.COLUMN_NAME_ID + "='" + pack.id + "'", null, SQLiteDatabase.CONFLICT_IGNORE);
|
||||
|
||||
if (s == 0) {
|
||||
if(s == 0){
|
||||
sqlPack.put(TelegramStickersContract.StickersTableEntry.COLUMN_NAME_INDEX, getNewIndex());
|
||||
Log.d("DB", "INSERTED!");
|
||||
return writableDb.insert(TelegramStickersContract.StickersTableEntry.TABLE_NAME, null, sqlPack) != -1;
|
||||
@@ -77,7 +77,7 @@ public class TelegramStickersDbHelper extends SQLiteOpenHelper {
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getNewIndex() {
|
||||
private int getNewIndex(){
|
||||
Cursor c = readableDb.rawQuery("SELECT MAX(" + TelegramStickersContract.StickersTableEntry.COLUMN_NAME_INDEX + ") FROM " + TelegramStickersContract.StickersTableEntry.TABLE_NAME, new String[0]);
|
||||
c.moveToLast();
|
||||
int max;
|
||||
@@ -91,31 +91,31 @@ public class TelegramStickersDbHelper extends SQLiteOpenHelper {
|
||||
return max + 1;
|
||||
}
|
||||
|
||||
public boolean deletePack(TelegramStickersPack pack) {
|
||||
public boolean deletePack(TelegramStickersPack pack){
|
||||
return writableDb.delete(TelegramStickersContract.StickersTableEntry.TABLE_NAME, TelegramStickersContract.StickersTableEntry.COLUMN_NAME_ID + "='" + pack.id + "'", null) == 1;
|
||||
}
|
||||
|
||||
public void getAllPacks(PacksLoadingListener listener) {
|
||||
public void getAllPacks(PacksLoadingListener listener){
|
||||
new PacksLoadingTask(listener).execute();
|
||||
}
|
||||
|
||||
public interface PacksLoadingListener {
|
||||
public interface PacksLoadingListener{
|
||||
void onPackLoaded(TelegramStickersPack pack);
|
||||
|
||||
void onAllPacksLoaded(ArrayList<TelegramStickersPack> packs);
|
||||
}
|
||||
|
||||
private class PacksLoadingTask extends AsyncTask<Void, Void, ArrayList<TelegramStickersPack>> {
|
||||
private class PacksLoadingTask extends AsyncTask<Void, Void, ArrayList<TelegramStickersPack>>{
|
||||
|
||||
PacksLoadingListener listener;
|
||||
|
||||
PacksLoadingTask(PacksLoadingListener listener) {
|
||||
PacksLoadingTask(PacksLoadingListener listener){
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ArrayList<TelegramStickersPack> doInBackground(Void... voids) {
|
||||
if (readableDb == null)
|
||||
protected ArrayList<TelegramStickersPack> doInBackground(Void... voids){
|
||||
if(readableDb == null)
|
||||
loadDatabases();
|
||||
|
||||
String sortOrder = TelegramStickersContract.StickersTableEntry.COLUMN_NAME_INDEX + " ASC";
|
||||
@@ -125,7 +125,7 @@ public class TelegramStickersDbHelper extends SQLiteOpenHelper {
|
||||
|
||||
ArrayList<TelegramStickersPack> packs = new ArrayList<>(cursor.getCount() + 8);
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
while(cursor.moveToNext()) {
|
||||
Log.d("DB", "PACK LOADED");
|
||||
String id = cursor.getString(cursor.getColumnIndexOrThrow(TelegramStickersContract.StickersTableEntry.COLUMN_NAME_ID));
|
||||
String name = cursor.getString(cursor.getColumnIndexOrThrow(TelegramStickersContract.StickersTableEntry.COLUMN_NAME_NAME));
|
||||
@@ -145,7 +145,7 @@ public class TelegramStickersDbHelper extends SQLiteOpenHelper {
|
||||
pack.version = version;
|
||||
pack.index = index;
|
||||
try {
|
||||
if (emojisEncoded != null) pack.loadEmojis(new JSONObject(emojisEncoded));
|
||||
if(emojisEncoded != null) pack.loadEmojis(new JSONObject(emojisEncoded));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public class TelegramStickersDbHelper extends SQLiteOpenHelper {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ArrayList<TelegramStickersPack> packs) {
|
||||
protected void onPostExecute(ArrayList<TelegramStickersPack> packs){
|
||||
listener.onAllPacksLoaded(packs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import ru.vtosters.lite.net.NetResponse;
|
||||
/**
|
||||
* Created by Aefyr on 11.05.2018.
|
||||
*/
|
||||
public class TelegramStickersGrabber {
|
||||
public class TelegramStickersGrabber{
|
||||
private static final String TAG = "TSG";
|
||||
public static String REAL_TG_IP = null;
|
||||
public static String PROXY_IP = null;
|
||||
@@ -51,7 +51,7 @@ public class TelegramStickersGrabber {
|
||||
private static String GET_FILE_URL;
|
||||
private static String BOT_API_BASE_FILE_URL;
|
||||
|
||||
static {
|
||||
static{
|
||||
updateURLs();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,8 @@ public class TelegramStickersGrabber {
|
||||
private final Handler uiThreadHandler;
|
||||
private String botApiKey = "";
|
||||
private NetClient httpClient;
|
||||
public TelegramStickersGrabber(String botApiKey) {
|
||||
|
||||
public TelegramStickersGrabber(String botApiKey){
|
||||
this.botApiKey = botApiKey;
|
||||
httpClient = new NetClient.Builder().connectTimeout(5, TimeUnit.SECONDS).build();
|
||||
uiThreadHandler = new Handler(Looper.getMainLooper());
|
||||
@@ -72,7 +73,7 @@ public class TelegramStickersGrabber {
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateURLs() {
|
||||
public static void updateURLs(){
|
||||
BOT_API_BASE_FILE_URL = "https://api.telegram.org/file/bot%s/%s";
|
||||
|
||||
|
||||
@@ -81,14 +82,14 @@ public class TelegramStickersGrabber {
|
||||
GET_FILE_URL = BOT_API_BASE_URL + "getFile?file_id=%s";
|
||||
}
|
||||
|
||||
public static boolean isTelegramBlocked() {
|
||||
public static boolean isTelegramBlocked(){
|
||||
NetClient client = new NetClient.Builder().connectTimeout(5, TimeUnit.SECONDS).build();
|
||||
try {
|
||||
if (PROXY_IP != null) {
|
||||
if(PROXY_IP != null){
|
||||
Socket socket = new Socket(PROXY_IP, PROXY_PORT);
|
||||
Proxy proxy = new Proxy(Proxy.Type.SOCKS, socket.getRemoteSocketAddress());
|
||||
NetClient.Builder b = new NetClient.Builder().proxy(proxy);
|
||||
if (PROXY_USER != null) {
|
||||
if(PROXY_USER != null){
|
||||
b = b.proxyAuthenticator(new PasswordAuthentication(PROXY_USER, PROXY_PASS.toCharArray()));
|
||||
}
|
||||
client = b.build();
|
||||
@@ -103,7 +104,7 @@ public class TelegramStickersGrabber {
|
||||
NetResponse res = client.newCall(req).execute();
|
||||
String s = res.getDataString();
|
||||
|
||||
if (!s.equals("{\"ok\":false,\"error_code\":404,\"description\":\"Not Found\"}"))
|
||||
if(!s.equals("{\"ok\":false,\"error_code\":404,\"description\":\"Not Found\"}"))
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return true;
|
||||
@@ -111,21 +112,21 @@ public class TelegramStickersGrabber {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void resetProxy() {
|
||||
public void resetProxy(){
|
||||
httpClient = new NetClient.Builder().connectTimeout(5, TimeUnit.SECONDS).build();
|
||||
}
|
||||
|
||||
public void enableProxy() {
|
||||
Thread kostil = new Thread() {
|
||||
public void enableProxy(){
|
||||
Thread kostil = new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
public void run(){
|
||||
try {
|
||||
if (PROXY_IP != null) {
|
||||
if(PROXY_IP != null){
|
||||
Socket socket = new Socket(PROXY_IP, PROXY_PORT);
|
||||
Proxy proxy = new Proxy(Proxy.Type.SOCKS, socket.getRemoteSocketAddress());
|
||||
NetClient.Builder b = httpClient.newBuilder().proxy(proxy);
|
||||
|
||||
if (PROXY_USER != null) {
|
||||
if(PROXY_USER != null){
|
||||
httpClient = b.proxyAuthenticator(new PasswordAuthentication(PROXY_USER, PROXY_PASS.toCharArray())).build();
|
||||
}
|
||||
|
||||
@@ -149,43 +150,43 @@ public class TelegramStickersGrabber {
|
||||
}
|
||||
}
|
||||
|
||||
public void grabPack(String id, File packFolder, String installedVersion, final PackDownloadListener listener) {
|
||||
public void grabPack(String id, File packFolder, String installedVersion, final PackDownloadListener listener){
|
||||
getPackInfo(id, packFolder, installedVersion, listener);
|
||||
}
|
||||
|
||||
public void setBotApiKey(String key) {
|
||||
public void setBotApiKey(String key){
|
||||
botApiKey = key;
|
||||
}
|
||||
|
||||
public void checkKey(final KeyCheckListener listener) {
|
||||
public void checkKey(final KeyCheckListener listener){
|
||||
Log.d(TAG, "Checking key: " + botApiKey);
|
||||
NetRequest request = new NetRequest.Builder().get().url(String.format(BOT_API_BASE_URL + "getMe", botApiKey)).build();
|
||||
httpClient.newCall(request).enqueue(new NetCallback() {
|
||||
httpClient.newCall(request).enqueue(new NetCallback(){
|
||||
@Override
|
||||
public void onFailure(NetCall call, IOException e) {
|
||||
public void onFailure(NetCall call, IOException e){
|
||||
e.printStackTrace();
|
||||
runOnUiThread(listener::onNetError);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(NetCall call, final NetResponse response) throws IOException {
|
||||
public void onResponse(NetCall call, final NetResponse response) throws IOException{
|
||||
runOnUiThread(() -> listener.onKeyChecked(response.code() == 200));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getPackInfo(final String packName, final File packFolder, final String installedVersion, final PackDownloadListener listener) {
|
||||
private void getPackInfo(final String packName, final File packFolder, final String installedVersion, final PackDownloadListener listener){
|
||||
NetRequest packInfoRequest = new NetRequest.Builder().get().url(String.format(GET_STICKER_SET_URL, botApiKey, packName)).build();
|
||||
httpClient.newCall(packInfoRequest).enqueue(new NetCallback() {
|
||||
httpClient.newCall(packInfoRequest).enqueue(new NetCallback(){
|
||||
@Override
|
||||
public void onFailure(NetCall call, IOException e) {
|
||||
public void onFailure(NetCall call, IOException e){
|
||||
listener.onPackDownloadError(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(NetCall call, NetResponse response) throws IOException {
|
||||
if (!response.isSuccessful()) {
|
||||
if (response.getData() != null)
|
||||
public void onResponse(NetCall call, NetResponse response) throws IOException{
|
||||
if(!response.isSuccessful()){
|
||||
if(response.getData() != null)
|
||||
listener.onPackDownloadError(new TSGException(response.getDataString() + "\nURL: " + call.request().url()));
|
||||
else
|
||||
listener.onPackDownloadError(new TSGException("Unknown Exception, no response body"));
|
||||
@@ -198,19 +199,19 @@ public class TelegramStickersGrabber {
|
||||
JSONObject jPackInfo = new JSONObject(response.getDataString()).getJSONObject("result");
|
||||
String packVersion = new String(sha256.digest(jPackInfo.toString().getBytes(StandardCharsets.UTF_8)));
|
||||
|
||||
if (packVersion.equals(installedVersion)) {
|
||||
if(packVersion.equals(installedVersion)){
|
||||
listener.onPackDownloaded(null, false);
|
||||
return;
|
||||
}
|
||||
|
||||
JSONArray jStickers = jPackInfo.getJSONArray("stickers");
|
||||
|
||||
if (jStickers.length() == 0) {
|
||||
if(jStickers.length() == 0){
|
||||
listener.onPackDownloadError(new TSGException("No stickers in pack"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (jPackInfo.optBoolean("is_animated")) {
|
||||
if(jPackInfo.optBoolean("is_animated")){
|
||||
listener.onPackDownloadError(new TSGException("Animated stickerpacks are not supported!"));
|
||||
return;
|
||||
}
|
||||
@@ -219,7 +220,7 @@ public class TelegramStickersGrabber {
|
||||
|
||||
Log.d(TAG, String.format("Parsing stickers in pack %s", packName));
|
||||
|
||||
for (int i = 0; i < jStickers.length(); i++) {
|
||||
for(int i = 0; i < jStickers.length(); i++) {
|
||||
JSONObject jSticker = jStickers.getJSONObject(i);
|
||||
stickers.add(new Sticker(jSticker.getString("file_id"), jSticker.getString("emoji")));
|
||||
}
|
||||
@@ -231,7 +232,7 @@ public class TelegramStickersGrabber {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!packFolder.exists() && !packFolder.mkdirs()) {
|
||||
if(!packFolder.exists() && !packFolder.mkdirs()){
|
||||
listener.onPackDownloadError(new IOException("Can't create folder for the pack!"));
|
||||
return;
|
||||
}
|
||||
@@ -245,7 +246,7 @@ public class TelegramStickersGrabber {
|
||||
});
|
||||
}
|
||||
|
||||
private void getPack(final StickerSet set, final File packFolder, final TelegramStickersPackInfo packInfo, final PackDownloadListener listener) {
|
||||
private void getPack(final StickerSet set, final File packFolder, final TelegramStickersPackInfo packInfo, final PackDownloadListener listener){
|
||||
final GoalCounter downloadedStickers = new GoalCounter(set.stickers.size(), () -> {
|
||||
Log.d(TAG, String.format("Pack %s has been downloaded to %s", set.id, packFolder.getAbsolutePath()));
|
||||
|
||||
@@ -254,17 +255,17 @@ public class TelegramStickersGrabber {
|
||||
final Flag deathFlag = new Flag();
|
||||
|
||||
AtomicInteger retryed = new AtomicInteger();
|
||||
for (int i = 0; i < set.stickers.size(); i++) {
|
||||
for(int i = 0; i < set.stickers.size(); i++) {
|
||||
final Sticker sticker = set.stickers.get(i);
|
||||
NetRequest fileInfoRequest = new NetRequest.Builder().get().url(String.format(GET_FILE_URL, botApiKey, sticker.fileId)).build();
|
||||
|
||||
final int stickerIndex = i + 1;
|
||||
|
||||
AtomicBoolean sync = new AtomicBoolean();
|
||||
httpClient.newCall(fileInfoRequest).enqueue(new NetCallback() {
|
||||
httpClient.newCall(fileInfoRequest).enqueue(new NetCallback(){
|
||||
@Override
|
||||
public void onFailure(NetCall call, IOException e) {
|
||||
if (deathFlag.up())
|
||||
public void onFailure(NetCall call, IOException e){
|
||||
if(deathFlag.up())
|
||||
return;
|
||||
|
||||
deathFlag.raise();
|
||||
@@ -274,14 +275,14 @@ public class TelegramStickersGrabber {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(NetCall call, NetResponse response) throws IOException {
|
||||
if (deathFlag.up())
|
||||
public void onResponse(NetCall call, NetResponse response) throws IOException{
|
||||
if(deathFlag.up())
|
||||
return;
|
||||
|
||||
if (response.code() != 200) {
|
||||
if(response.code() != 200){
|
||||
retryed.incrementAndGet();
|
||||
|
||||
if (retryed.get() > 5)
|
||||
if(retryed.get() > 5)
|
||||
onFailure(call, new IOException());
|
||||
else httpClient.newCall(fileInfoRequest)
|
||||
.enqueue(this);
|
||||
@@ -300,14 +301,14 @@ public class TelegramStickersGrabber {
|
||||
return;
|
||||
}
|
||||
|
||||
if (botApiKey == null) botApiKey = "";
|
||||
if(botApiKey == null) botApiKey = "";
|
||||
|
||||
NetRequest fileDownloadRequest = new NetRequest.Builder().get().url(String.format(BOT_API_BASE_FILE_URL, botApiKey, filePath)).build();
|
||||
|
||||
httpClient.newCall(fileDownloadRequest).enqueue(new NetCallback() {
|
||||
httpClient.newCall(fileDownloadRequest).enqueue(new NetCallback(){
|
||||
@Override
|
||||
public void onFailure(NetCall call, IOException e) {
|
||||
if (deathFlag.up())
|
||||
public void onFailure(NetCall call, IOException e){
|
||||
if(deathFlag.up())
|
||||
return;
|
||||
|
||||
deathFlag.raise();
|
||||
@@ -317,14 +318,14 @@ public class TelegramStickersGrabber {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(NetCall call, NetResponse response) throws IOException {
|
||||
if (deathFlag.up())
|
||||
public void onResponse(NetCall call, NetResponse response) throws IOException{
|
||||
if(deathFlag.up())
|
||||
return;
|
||||
|
||||
if (response.code() != 200) {
|
||||
if(response.code() != 200){
|
||||
retryed.incrementAndGet();
|
||||
|
||||
if (retryed.get() > 5)
|
||||
if(retryed.get() > 5)
|
||||
onFailure(call, new IOException());
|
||||
else httpClient.newCall(fileDownloadRequest)
|
||||
.enqueue(this);
|
||||
@@ -332,7 +333,7 @@ public class TelegramStickersGrabber {
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.getData() == null) {
|
||||
if(response.getData() == null){
|
||||
deathFlag.raise();
|
||||
listener.onPackDownloadError(new TSGException("Response body for a sticker is null :/"));
|
||||
sync.set(true);
|
||||
@@ -354,7 +355,7 @@ public class TelegramStickersGrabber {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stickerImage == null) {
|
||||
if(stickerImage == null){
|
||||
deathFlag.raise();
|
||||
listener.onPackDownloadError(new TSGException("Unable to decode sticker image"));
|
||||
sync.set(true);
|
||||
@@ -375,7 +376,7 @@ public class TelegramStickersGrabber {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!stickerImage.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream)) {
|
||||
if(!stickerImage.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream)){
|
||||
stickerImage.recycle();
|
||||
deathFlag.raise();
|
||||
listener.onPackDownloadError(new TSGException("Unable to compress sticker to a png file at path: " + stickerFile.getAbsolutePath()));
|
||||
@@ -406,7 +407,7 @@ public class TelegramStickersGrabber {
|
||||
}
|
||||
});
|
||||
|
||||
while (!sync.get())
|
||||
while(!sync.get())
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e1) {
|
||||
@@ -414,11 +415,11 @@ public class TelegramStickersGrabber {
|
||||
}
|
||||
}
|
||||
|
||||
private void runOnUiThread(Runnable r) {
|
||||
private void runOnUiThread(Runnable r){
|
||||
uiThreadHandler.post(r);
|
||||
}
|
||||
|
||||
public interface PackDownloadListener {
|
||||
public interface PackDownloadListener{
|
||||
void onPackDownloaded(TelegramStickersPackInfo pack, boolean newVersionFound);
|
||||
|
||||
void onPackDownloadError(Exception e);
|
||||
@@ -428,27 +429,27 @@ public class TelegramStickersGrabber {
|
||||
void onStickerDownloaded(String pack, File sticker, String boundEmoji, int stickerIndex, int downloadedStickersCount, int totalStickerCount);
|
||||
}
|
||||
|
||||
public interface KeyCheckListener {
|
||||
public interface KeyCheckListener{
|
||||
void onKeyChecked(boolean ok);
|
||||
|
||||
void onNetError();
|
||||
}
|
||||
|
||||
public class TSGException extends Exception {
|
||||
public class TSGException extends Exception{
|
||||
private static final long serialVersionUID = 7866915509988422944L;
|
||||
|
||||
private TSGException(String message) {
|
||||
private TSGException(String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
private class StickerSet {
|
||||
private class StickerSet{
|
||||
String id;
|
||||
String name;
|
||||
String version;
|
||||
ArrayList<Sticker> stickers;
|
||||
|
||||
StickerSet(String id, String name, String version, ArrayList<Sticker> stickers) {
|
||||
StickerSet(String id, String name, String version, ArrayList<Sticker> stickers){
|
||||
this.name = name;
|
||||
this.stickers = stickers;
|
||||
this.id = id;
|
||||
@@ -456,22 +457,22 @@ public class TelegramStickersGrabber {
|
||||
}
|
||||
}
|
||||
|
||||
private class Sticker {
|
||||
private class Sticker{
|
||||
String emoji;
|
||||
String fileId;
|
||||
|
||||
Sticker(String fileId, String emoji) {
|
||||
Sticker(String fileId, String emoji){
|
||||
this.fileId = fileId;
|
||||
this.emoji = emoji;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(Object obj){
|
||||
return obj instanceof Sticker && ((Sticker) obj).fileId.equals(fileId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
public int hashCode(){
|
||||
return (17 * emoji.hashCode()) << 32 + fileId.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ package com.aefyr.tsg.g2.stickersgrabber;
|
||||
/**
|
||||
* Created by Aefyr on 22.05.2018.
|
||||
*/
|
||||
public class TelegramStickersPackInfo {
|
||||
public class TelegramStickersPackInfo{
|
||||
public String id;
|
||||
public String title;
|
||||
public String version;
|
||||
public int stickersCount;
|
||||
|
||||
TelegramStickersPackInfo(String id, String title, int stickersCount, String version) {
|
||||
TelegramStickersPackInfo(String id, String title, int stickersCount, String version){
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.version = version;
|
||||
|
||||
@@ -3,18 +3,18 @@ package com.aefyr.tsg.g2.stickersgrabber.util;
|
||||
/**
|
||||
* Created by Aefyr on 11.05.2018.
|
||||
*/
|
||||
public class Flag {
|
||||
public class Flag{
|
||||
private boolean up = false;
|
||||
|
||||
public synchronized boolean up() {
|
||||
public synchronized boolean up(){
|
||||
return up;
|
||||
}
|
||||
|
||||
public synchronized void raise() {
|
||||
public synchronized void raise(){
|
||||
up = true;
|
||||
}
|
||||
|
||||
public synchronized void lower() {
|
||||
public synchronized void lower(){
|
||||
up = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,34 +5,34 @@ import android.util.Log;
|
||||
/**
|
||||
* Created by Aefyr on 11.05.2018.
|
||||
*/
|
||||
public class GoalCounter {
|
||||
public class GoalCounter{
|
||||
|
||||
private final int goal;
|
||||
private int i = 0;
|
||||
private final OnGoalReachListener listener;
|
||||
private int i = 0;
|
||||
|
||||
public GoalCounter(int goal, OnGoalReachListener listener) {
|
||||
public GoalCounter(int goal, OnGoalReachListener listener){
|
||||
this.goal = goal;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public synchronized void increase() {
|
||||
if (++i == goal)
|
||||
public synchronized void increase(){
|
||||
if(++i == goal)
|
||||
listener.onGoalReached();
|
||||
|
||||
Log.d("COUNTER", "G=" + goal + ", I=" + i);
|
||||
}
|
||||
|
||||
public synchronized void increase(int delta) {
|
||||
if ((i += delta) == goal)
|
||||
public synchronized void increase(int delta){
|
||||
if((i += delta) == goal)
|
||||
listener.onGoalReached();
|
||||
}
|
||||
|
||||
public synchronized int value() {
|
||||
public synchronized int value(){
|
||||
return i;
|
||||
}
|
||||
|
||||
public interface OnGoalReachListener {
|
||||
public interface OnGoalReachListener{
|
||||
void onGoalReached();
|
||||
}
|
||||
}
|
||||
|
||||
+6174
-6174
File diff suppressed because it is too large
Load Diff
@@ -27,13 +27,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
public class GCMFix {
|
||||
public static ArrayList<String> langs = new ArrayList<>();
|
||||
public class GCMFix{
|
||||
private static final String agent = String.format("Android-GCM/1.5 (%s %s)", Build.MODEL, Build.MODEL);
|
||||
public static ArrayList<String> langs = new ArrayList<>();
|
||||
private static KeyPair pair;
|
||||
private static int rid = 0;
|
||||
|
||||
static {
|
||||
static{
|
||||
genNewKey();
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class GCMFix {
|
||||
return orig;
|
||||
}
|
||||
|
||||
public static String requestToken() {
|
||||
public static String requestToken(){
|
||||
String xappide;
|
||||
try {
|
||||
String[] aidarr = {"3974055026275073921", "4418584909973341826", "4585634953328772978"};
|
||||
@@ -63,7 +63,7 @@ public class GCMFix {
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
xappide2 = "";
|
||||
}
|
||||
if (xappide2 == null) {
|
||||
if(xappide2 == null){
|
||||
bytes[0] = (byte) (((bytes[0] & 15) + 112) & 255);
|
||||
xappide = Base64.encodeToString(bytes, 2).substring(0, 11);
|
||||
} else {
|
||||
@@ -77,11 +77,11 @@ public class GCMFix {
|
||||
Callback callback = str -> GCMFix.lambdaRequestToken(sb, wait, str);
|
||||
|
||||
doRequest("https://android.clients.google.com/c2dm/register3", "POST", params, aid, callback);
|
||||
while (!wait.get()) {
|
||||
while(!wait.get()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
String token = sb.toString();
|
||||
if (token.equals("REGISTRATION_ERROR")) {
|
||||
if(token.equals("REGISTRATION_ERROR")){
|
||||
return requestToken();
|
||||
}
|
||||
rid = 0;
|
||||
@@ -98,18 +98,18 @@ public class GCMFix {
|
||||
}
|
||||
}
|
||||
|
||||
static void lambdaRequestToken(StringBuilder sb, AtomicBoolean wait, String s) {
|
||||
static void lambdaRequestToken(StringBuilder sb, AtomicBoolean wait, String s){
|
||||
sb.append(s.substring(20));
|
||||
wait.set(true);
|
||||
}
|
||||
|
||||
static void lambda$requestToken$1(String str) {
|
||||
static void lambda$requestToken$1(String str){
|
||||
}
|
||||
|
||||
private static void fillParams(List<String> params, String sig, String pub2, String xappid, long androidId, boolean del) {
|
||||
private static void fillParams(List<String> params, String sig, String pub2, String xappid, long androidId, boolean del){
|
||||
rid++;
|
||||
params.add("X-subtype=841415684880");
|
||||
if (del) {
|
||||
if(del){
|
||||
params.add("X-delete=1");
|
||||
params.add("X-X-delete=1");
|
||||
} else {
|
||||
@@ -128,13 +128,13 @@ public class GCMFix {
|
||||
sb.append("X-appid=");
|
||||
sb.append(xappid);
|
||||
params.add(sb.toString());
|
||||
if (del) {
|
||||
if(del){
|
||||
params.add("X-scope=GCM");
|
||||
} else {
|
||||
params.add("X-scope=*");
|
||||
}
|
||||
params.add("X-subscription=841415684880");
|
||||
if (!del) {
|
||||
if(!del){
|
||||
params.add("X-gmp_app_id=1:841415684880:android:632f429381141121");
|
||||
}
|
||||
params.add("X-app_ver_name=" + "5.56.1");
|
||||
@@ -146,19 +146,19 @@ public class GCMFix {
|
||||
params.add("gcm_ver=11949470");
|
||||
}
|
||||
|
||||
private static String join(String chr, Iterable<String> arr) {
|
||||
private static String join(String chr, Iterable<String> arr){
|
||||
String str = "";
|
||||
for (String s : arr) {
|
||||
for(String s : arr) {
|
||||
str = str.isEmpty() ? s : str + chr + s;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
private static String join(String chr, String[] arr) {
|
||||
private static String join(String chr, String[] arr){
|
||||
return join(chr, Arrays.asList(arr));
|
||||
}
|
||||
|
||||
private static void doRequest(String url, String method, List<String> params, String aidlogin, Callback callback) throws IOException {
|
||||
private static void doRequest(String url, String method, List<String> params, String aidlogin, Callback callback) throws IOException{
|
||||
HttpsURLConnection con = (HttpsURLConnection) new URL(url).openConnection();
|
||||
con.setRequestMethod(method);
|
||||
con.setRequestProperty("Authorization", aidlogin);
|
||||
@@ -176,7 +176,7 @@ public class GCMFix {
|
||||
con.getInputStream().close();
|
||||
}
|
||||
|
||||
private static String genNewKey() {
|
||||
private static String genNewKey(){
|
||||
try {
|
||||
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
|
||||
gen.initialize(2048);
|
||||
@@ -187,7 +187,7 @@ public class GCMFix {
|
||||
return Base64.encodeToString(pair.getPublic().getEncoded(), 0);
|
||||
}
|
||||
|
||||
private static String getSig(String pub2) {
|
||||
private static String getSig(String pub2){
|
||||
try {
|
||||
PrivateKey key = pair.getPrivate();
|
||||
Signature sign = Signature.getInstance(key instanceof RSAPrivateKey ? "SHA256withRSA" : "SHA256withECDSA");
|
||||
@@ -200,7 +200,7 @@ public class GCMFix {
|
||||
}
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
public interface Callback{
|
||||
void doCallback(String str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.vtosters.lite.deviceinfo;
|
||||
|
||||
public class Device {
|
||||
public class Device{
|
||||
private String androidId;
|
||||
private String bluetoothMac;
|
||||
private String boardName;
|
||||
@@ -16,81 +16,81 @@ public class Device {
|
||||
private String serialId;
|
||||
private String wifiMac;
|
||||
|
||||
public Device withSerialId(String str) {
|
||||
public Device withSerialId(String str){
|
||||
this.serialId = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withAndroidId(String str) {
|
||||
public Device withAndroidId(String str){
|
||||
this.androidId = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withWifiMac(String str) {
|
||||
public Device withWifiMac(String str){
|
||||
this.wifiMac = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withBluetoothMac(String str) {
|
||||
public Device withBluetoothMac(String str){
|
||||
this.bluetoothMac = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withSdkVersion(int i) {
|
||||
public Device withSdkVersion(int i){
|
||||
this.sdkVersion = i;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withFirmwareId(String str) {
|
||||
public Device withFirmwareId(String str){
|
||||
this.firmwareId = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withFirmwareDisplay(String str) {
|
||||
public Device withFirmwareDisplay(String str){
|
||||
this.firmwareDisplay = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withProductName(String str) {
|
||||
public Device withProductName(String str){
|
||||
this.productName = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withDeviceName(String str) {
|
||||
public Device withDeviceName(String str){
|
||||
this.deviceName = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withBoardName(String str) {
|
||||
public Device withBoardName(String str){
|
||||
this.boardName = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withCpuAbi(String str) {
|
||||
public Device withCpuAbi(String str){
|
||||
this.cpuAbi = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withManufacturerName(String str) {
|
||||
public Device withManufacturerName(String str){
|
||||
this.manufacturerName = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withBrandName(String str) {
|
||||
public Device withBrandName(String str){
|
||||
this.brandName = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Device withModelName(String str) {
|
||||
public Device withModelName(String str){
|
||||
this.modelName = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
public String toString(){
|
||||
return "Device{serialId='" + this.serialId + "', androidId='" + this.androidId + "', wifiMac='" + this.wifiMac + "', bluetoothMac='" + this.bluetoothMac + "'}";
|
||||
}
|
||||
|
||||
public String toDeviceName() {
|
||||
public String toDeviceName(){
|
||||
return "Device{sdkVersion=" + this.sdkVersion + ", productName='" + this.productName + "', deviceName='" + this.deviceName + "', boardName='" + this.boardName + "', cpuAbi='" + this.cpuAbi + "', manufacturerName='" + this.manufacturerName + "', brandName='" + this.brandName + "', modelName='" + this.modelName + "'}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,67 +18,67 @@ import java.lang.reflect.Method;
|
||||
import java.net.NetworkInterface;
|
||||
import java.util.Collections;
|
||||
|
||||
public class DeviceInfoCollector {
|
||||
public class DeviceInfoCollector{
|
||||
private static final String TAG = "DeviceInfoCollector";
|
||||
|
||||
public Device collect(Context context) {
|
||||
public Device collect(Context context){
|
||||
return new Device().withSerialId(serialId()).withAndroidId(androidId(context)).withWifiMac(wifiMac(context)).withBluetoothMac(bluetoothMac(context)).withSdkVersion(Build.VERSION.SDK_INT).withFirmwareId(Build.ID).withFirmwareDisplay(Build.DISPLAY).withProductName(Build.PRODUCT).withDeviceName(Build.DEVICE).withBoardName(Build.BOARD).withCpuAbi(Build.CPU_ABI).withManufacturerName(Build.MANUFACTURER).withBrandName(Build.BRAND).withModelName(Build.MODEL);
|
||||
}
|
||||
|
||||
private String serialId() {
|
||||
private String serialId(){
|
||||
String str;
|
||||
try {
|
||||
Class<?> cls = Class.forName("android.os.SystemProperties");
|
||||
Method method = cls.getMethod("get", String.class);
|
||||
str = (String) method.invoke(cls, "gsm.sn1");
|
||||
if (isInvalidSerial(str)) {
|
||||
if(isInvalidSerial(str)){
|
||||
str = (String) method.invoke(cls, "ril.serialnumber");
|
||||
}
|
||||
if (isInvalidSerial(str)) {
|
||||
if(isInvalidSerial(str)){
|
||||
str = (String) method.invoke(cls, "ro.serialno");
|
||||
}
|
||||
if (isInvalidSerial(str)) {
|
||||
if(isInvalidSerial(str)){
|
||||
str = (String) method.invoke(cls, "sys.serialnumber");
|
||||
}
|
||||
if (isInvalidSerial(str)) {
|
||||
if(isInvalidSerial(str)){
|
||||
str = Build.SERIAL;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Serial ID obtaining failed: ", e);
|
||||
}
|
||||
str = null;
|
||||
if (str != null) {
|
||||
if(str != null){
|
||||
return str.toLowerCase();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String androidId(Context context) {
|
||||
private String androidId(Context context){
|
||||
return Settings.Secure.getString(context.getContentResolver(), "android_id").toLowerCase();
|
||||
}
|
||||
|
||||
private String wifiMac(Context context) {
|
||||
private String wifiMac(Context context){
|
||||
String wifiMacFromManager = wifiMacFromManager(context);
|
||||
if (isInvalidMac(wifiMacFromManager)) {
|
||||
if(isInvalidMac(wifiMacFromManager)){
|
||||
wifiMacFromManager = wifiMacFromNetworkInterfaces();
|
||||
}
|
||||
if (isInvalidMac(wifiMacFromManager)) {
|
||||
if(isInvalidMac(wifiMacFromManager)){
|
||||
wifiMacFromManager = wifiMacFromFileSystem();
|
||||
}
|
||||
if (isInvalidMac(wifiMacFromManager)) {
|
||||
if(isInvalidMac(wifiMacFromManager)){
|
||||
wifiMacFromManager = null;
|
||||
}
|
||||
if (wifiMacFromManager != null) {
|
||||
if(wifiMacFromManager != null){
|
||||
return wifiMacFromManager.toLowerCase();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String wifiMacFromManager(Context context) {
|
||||
private String wifiMacFromManager(Context context){
|
||||
WifiInfo connectionInfo;
|
||||
try {
|
||||
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
if (wifiManager == null || (connectionInfo = wifiManager.getConnectionInfo()) == null) {
|
||||
if(wifiManager == null || (connectionInfo = wifiManager.getConnectionInfo()) == null){
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
@@ -88,20 +88,20 @@ public class DeviceInfoCollector {
|
||||
}
|
||||
}
|
||||
|
||||
private String wifiMacFromNetworkInterfaces() {
|
||||
private String wifiMacFromNetworkInterfaces(){
|
||||
try {
|
||||
for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
|
||||
if ("wlan0".equalsIgnoreCase(networkInterface.getName())) {
|
||||
for(NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
|
||||
if("wlan0".equalsIgnoreCase(networkInterface.getName())){
|
||||
byte[] hardwareAddress = networkInterface.getHardwareAddress();
|
||||
if (hardwareAddress == null) {
|
||||
if(hardwareAddress == null){
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int length = hardwareAddress.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
for(int i = 0; i < length; i++) {
|
||||
sb.append(String.format("%02X:", Byte.valueOf(hardwareAddress[i])));
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
if(sb.length() > 0){
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
}
|
||||
return sb.toString();
|
||||
@@ -114,7 +114,7 @@ public class DeviceInfoCollector {
|
||||
}
|
||||
}
|
||||
|
||||
private String wifiMacFromFileSystem() {
|
||||
private String wifiMacFromFileSystem(){
|
||||
try {
|
||||
FileReader fileReader = new FileReader("/sys/class/net/wlan0/address");
|
||||
try {
|
||||
@@ -137,33 +137,33 @@ public class DeviceInfoCollector {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String bluetoothMac(Context context) {
|
||||
private String bluetoothMac(Context context){
|
||||
String bluetoothMacFromAdapter = bluetoothMacFromAdapter();
|
||||
if (isInvalidMac(bluetoothMacFromAdapter)) {
|
||||
if(isInvalidMac(bluetoothMacFromAdapter)){
|
||||
bluetoothMacFromAdapter = bluetoothMacFromContentResolver(context);
|
||||
}
|
||||
if (isInvalidMac(bluetoothMacFromAdapter)) {
|
||||
if(isInvalidMac(bluetoothMacFromAdapter)){
|
||||
bluetoothMacFromAdapter = null;
|
||||
}
|
||||
if (bluetoothMacFromAdapter != null) {
|
||||
if(bluetoothMacFromAdapter != null){
|
||||
return bluetoothMacFromAdapter.toLowerCase();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String bluetoothMacFromAdapter() {
|
||||
private String bluetoothMacFromAdapter(){
|
||||
try {
|
||||
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (defaultAdapter == null) {
|
||||
if(defaultAdapter == null){
|
||||
return null;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < 23) {
|
||||
if(Build.VERSION.SDK_INT < 23){
|
||||
return null;
|
||||
}
|
||||
Field declaredField = defaultAdapter.getClass().getDeclaredField("mService");
|
||||
declaredField.setAccessible(true);
|
||||
Object obj = declaredField.get(defaultAdapter);
|
||||
if (obj != null) {
|
||||
if(obj != null){
|
||||
return (String) obj.getClass().getMethod("getAddress").invoke(obj, new Object[0]);
|
||||
}
|
||||
return null;
|
||||
@@ -173,7 +173,7 @@ public class DeviceInfoCollector {
|
||||
}
|
||||
}
|
||||
|
||||
private String bluetoothMacFromContentResolver(Context context) {
|
||||
private String bluetoothMacFromContentResolver(Context context){
|
||||
try {
|
||||
return Settings.Secure.getString(context.getContentResolver(), "bluetooth_address");
|
||||
} catch (Exception e) {
|
||||
@@ -182,11 +182,11 @@ public class DeviceInfoCollector {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInvalidSerial(String str) {
|
||||
private boolean isInvalidSerial(String str){
|
||||
return TextUtils.isEmpty(str) || EnvironmentCompat.MEDIA_UNKNOWN.equalsIgnoreCase(str);
|
||||
}
|
||||
|
||||
private boolean isInvalidMac(String str) {
|
||||
private boolean isInvalidMac(String str){
|
||||
return TextUtils.isEmpty(str) || "02:00:00:00:00:00".equalsIgnoreCase(str) || "00:00:00:00:00:00".equalsIgnoreCase(str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,24 +12,24 @@ import com.vk.im.ui.components.common.DialogAction;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DNRInjector {
|
||||
public static void inject(Dialog dialog, List<DialogAction> list) {
|
||||
public class DNRInjector{
|
||||
public static void inject(Dialog dialog, List<DialogAction> list){
|
||||
int peerId = dialog.getId();
|
||||
|
||||
if (isDnrEnabledFor(peerId)) {
|
||||
if(isDnrEnabledFor(peerId)){
|
||||
list.add(DialogAction.valueOf("DNR_OFF"));
|
||||
} else {
|
||||
list.add(DialogAction.valueOf("DNR_ON"));
|
||||
}
|
||||
|
||||
if (isDntEnabledFor(peerId)) {
|
||||
if(isDntEnabledFor(peerId)){
|
||||
list.add(DialogAction.valueOf("DNT_OFF"));
|
||||
} else {
|
||||
list.add(DialogAction.valueOf("DNT_ON"));
|
||||
}
|
||||
}
|
||||
|
||||
public static LinkedHashMap<DialogAction, Integer> injectToHashMap(LinkedHashMap<DialogAction, Integer> hashMap) {
|
||||
public static LinkedHashMap<DialogAction, Integer> injectToHashMap(LinkedHashMap<DialogAction, Integer> hashMap){
|
||||
hashMap.put(DialogAction.valueOf("DNR_ON"), getIdentifier("DNR_ON", "string"));
|
||||
hashMap.put(DialogAction.valueOf("DNR_OFF"), getIdentifier("DNR_OFF", "string"));
|
||||
hashMap.put(DialogAction.valueOf("DNT_ON"), getIdentifier("DNT_ON", "string"));
|
||||
@@ -37,21 +37,21 @@ public class DNRInjector {
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
public static boolean onClick(Dialog dialog, DialogAction action) {
|
||||
public static boolean onClick(Dialog dialog, DialogAction action){
|
||||
var id = dialog.getId();
|
||||
|
||||
if (action == DialogAction.valueOf("DNR_ON")) {
|
||||
if(action == DialogAction.valueOf("DNR_ON")){
|
||||
setDnr(dialog, true);
|
||||
return true;
|
||||
} else if (action == DialogAction.valueOf("DNR_OFF")) {
|
||||
} else if(action == DialogAction.valueOf("DNR_OFF")){
|
||||
setDnr(dialog, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.valueOf("DNT_ON")) {
|
||||
if(action == DialogAction.valueOf("DNT_ON")){
|
||||
setDnt(dialog, true);
|
||||
return true;
|
||||
} else if (action == DialogAction.valueOf("DNT_OFF")) {
|
||||
} else if(action == DialogAction.valueOf("DNT_OFF")){
|
||||
setDnt(dialog, false);
|
||||
return true;
|
||||
}
|
||||
@@ -59,11 +59,11 @@ public class DNRInjector {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setDnr(Dialog dialog, boolean value) {
|
||||
public static void setDnr(Dialog dialog, boolean value){
|
||||
hookDNR(dialog.getId());
|
||||
}
|
||||
|
||||
public static void setDnt(Dialog dialog, boolean value) {
|
||||
public static void setDnt(Dialog dialog, boolean value){
|
||||
hookDNT(dialog.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,54 +13,54 @@ import java.util.List;
|
||||
import ru.vtosters.lite.dnr.helpers.DoNotReadDBHelper;
|
||||
import ru.vtosters.lite.dnr.helpers.DoNotTypeDBHelper;
|
||||
|
||||
public class DNRModule {
|
||||
public class DNRModule{
|
||||
public static DoNotReadDBHelper mDoNotReadDBHelper = new DoNotReadDBHelper();
|
||||
public static DoNotTypeDBHelper mDoNotTypeDBHelper = new DoNotTypeDBHelper();
|
||||
public static Dialog mDialog;
|
||||
|
||||
public static boolean isDnrEnabledFor(int id) {
|
||||
public static boolean isDnrEnabledFor(int id){
|
||||
var isEnabled = mDoNotReadDBHelper.isEnabledForPeerId(id);
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public static List<Integer> getDnrEnabled() {
|
||||
public static List<Integer> getDnrEnabled(){
|
||||
return mDoNotReadDBHelper.get();
|
||||
}
|
||||
|
||||
public static List<Integer> getDntEnabled() {
|
||||
public static List<Integer> getDntEnabled(){
|
||||
return mDoNotTypeDBHelper.get();
|
||||
}
|
||||
|
||||
public static boolean isDntEnabledFor(int id) {
|
||||
public static boolean isDntEnabledFor(int id){
|
||||
var isEnabled = mDoNotTypeDBHelper.isEnabledForPeerId(id);
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public static boolean isDntEnabledFor(SetUserActivityCmd cmd) {
|
||||
public static boolean isDntEnabledFor(SetUserActivityCmd cmd){
|
||||
return isDntEnabledFor(cmd.b);
|
||||
}
|
||||
|
||||
public static boolean isDnrEnabledFor(Dialog dialog) {
|
||||
if (dialog == null) return false;
|
||||
public static boolean isDnrEnabledFor(Dialog dialog){
|
||||
if(dialog == null) return false;
|
||||
return isDnrEnabledFor(dialog.getId());
|
||||
}
|
||||
|
||||
public static boolean isDntEnabledFor(Dialog dialog) {
|
||||
if (dialog == null) return false;
|
||||
public static boolean isDntEnabledFor(Dialog dialog){
|
||||
if(dialog == null) return false;
|
||||
return isDntEnabledFor(dialog.getId());
|
||||
}
|
||||
|
||||
public static void hookRead(Dialog dialog) {
|
||||
public static void hookRead(Dialog dialog){
|
||||
makeRequest("https://" + getApiCom() + "/method/messages.markAsRead?start_message_id=" + dialog.F1() + "&peer_id=" + dialog.getId() + "&v=5.91&access_token=" + getUserToken(), response -> {
|
||||
ToastUtils.a("Чат помечен как прочитанный!");
|
||||
});
|
||||
}
|
||||
|
||||
public static void hookDNR(int peerId) {
|
||||
public static void hookDNR(int peerId){
|
||||
mDoNotReadDBHelper.setEnabledForPeerId(peerId, !mDoNotReadDBHelper.isEnabledForPeerId(peerId));
|
||||
}
|
||||
|
||||
public static void hookDNT(int peerId) {
|
||||
public static void hookDNT(int peerId){
|
||||
mDoNotTypeDBHelper.setEnabledForPeerId(peerId, !mDoNotTypeDBHelper.isEnabledForPeerId(peerId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,64 +2,64 @@ package ru.vtosters.lite.dnr;
|
||||
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
public class DNRPrefs {
|
||||
public static boolean getStoriesRead() {
|
||||
public class DNRPrefs{
|
||||
public static boolean getStoriesRead(){
|
||||
return getBoolValue("read_s", false);
|
||||
}
|
||||
|
||||
public static boolean getMarkAsReadWithoutExceptions(int peerId) {
|
||||
if (readPM(peerId))
|
||||
public static boolean getMarkAsReadWithoutExceptions(int peerId){
|
||||
if(readPM(peerId))
|
||||
return true;
|
||||
if (readConversations(peerId))
|
||||
if(readConversations(peerId))
|
||||
return true;
|
||||
return readBots(peerId);
|
||||
}
|
||||
|
||||
public static boolean getMarkAsRead(int peerId) {
|
||||
public static boolean getMarkAsRead(int peerId){
|
||||
return isInDNRExceptions(peerId);
|
||||
}
|
||||
|
||||
public static boolean isInDNRExceptions(int peerId) {
|
||||
public static boolean isInDNRExceptions(int peerId){
|
||||
return DNRModule.mDoNotReadDBHelper.isEnabledForPeerId(peerId);
|
||||
}
|
||||
|
||||
public static boolean isInDNTExceptions(int peerId) {
|
||||
public static boolean isInDNTExceptions(int peerId){
|
||||
return DNRModule.mDoNotTypeDBHelper.isEnabledForPeerId(peerId);
|
||||
}
|
||||
|
||||
public static boolean readPM(int peer) {
|
||||
public static boolean readPM(int peer){
|
||||
return (peer > 0 && peer < 2000000000) && getBoolValue("read_pm", false);
|
||||
}
|
||||
|
||||
public static boolean readConversations(int peer) {
|
||||
public static boolean readConversations(int peer){
|
||||
return (peer > 2000000000) && getBoolValue("read_conversations", false);
|
||||
}
|
||||
|
||||
public static boolean readBots(int peer) {
|
||||
public static boolean readBots(int peer){
|
||||
return (peer < 0) && getBoolValue("read_bot", false);
|
||||
}
|
||||
|
||||
public static boolean writePM(int peer) {
|
||||
public static boolean writePM(int peer){
|
||||
return (peer > 0 && peer < 2000000000) && getBoolValue("write_pm", false);
|
||||
}
|
||||
|
||||
public static boolean writeConversations(int peer) {
|
||||
public static boolean writeConversations(int peer){
|
||||
return (peer > 2000000000) && getBoolValue("write_conversations", false);
|
||||
}
|
||||
|
||||
public static boolean writeBots(int peer) {
|
||||
public static boolean writeBots(int peer){
|
||||
return (peer < 0) && getBoolValue("write_bot", false);
|
||||
}
|
||||
|
||||
public static boolean getActivityWithoutExceptions(int peerId) {
|
||||
if (writePM(peerId))
|
||||
public static boolean getActivityWithoutExceptions(int peerId){
|
||||
if(writePM(peerId))
|
||||
return true;
|
||||
if (writeConversations(peerId))
|
||||
if(writeConversations(peerId))
|
||||
return true;
|
||||
return writeBots(peerId);
|
||||
}
|
||||
|
||||
public static boolean getActivity(int peerId) {
|
||||
public static boolean getActivity(int peerId){
|
||||
return isInDNTExceptions(peerId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,31 +12,31 @@ import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.dnr.DNRPrefs;
|
||||
|
||||
public class DoNotReadDBHelper extends SQLiteOpenHelper {
|
||||
public DoNotReadDBHelper() {
|
||||
public class DoNotReadDBHelper extends SQLiteOpenHelper{
|
||||
public DoNotReadDBHelper(){
|
||||
super(getContext(), "dnr", null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
public void onCreate(SQLiteDatabase db){
|
||||
db.execSQL("create table dnr (peerId integer primary key, enabled integer)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
|
||||
|
||||
}
|
||||
|
||||
public boolean isEnabledForPeerId(int peerId) {
|
||||
public boolean isEnabledForPeerId(int peerId){
|
||||
try (Cursor c = getReadableDatabase().query("dnr", null, null, null, null, null, null)) {
|
||||
if (c.moveToFirst()) {
|
||||
if(c.moveToFirst()){
|
||||
int peerIdIndex = c.getColumnIndex("peerId");
|
||||
int enabledIndex = c.getColumnIndex("enabled");
|
||||
|
||||
do {
|
||||
if (c.getInt(peerIdIndex) == peerId)
|
||||
if(c.getInt(peerIdIndex) == peerId)
|
||||
return c.getInt(enabledIndex) == 1;
|
||||
} while (c.moveToNext());
|
||||
} while(c.moveToNext());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -45,19 +45,19 @@ public class DoNotReadDBHelper extends SQLiteOpenHelper {
|
||||
return DNRPrefs.getMarkAsReadWithoutExceptions(peerId);
|
||||
}
|
||||
|
||||
public List<Integer> get() {
|
||||
public List<Integer> get(){
|
||||
ArrayList<Integer> rs = new ArrayList<>();
|
||||
|
||||
try (Cursor c = getReadableDatabase().query("dnr", null, null, null, null, null, null)) {
|
||||
if (c.moveToFirst()) {
|
||||
if(c.moveToFirst()){
|
||||
int peerIdIndex = c.getColumnIndex("peerId");
|
||||
int enabledIndex = c.getColumnIndex("enabled");
|
||||
|
||||
do {
|
||||
if (c.getInt(enabledIndex) == 1) {
|
||||
if(c.getInt(enabledIndex) == 1){
|
||||
rs.add(c.getInt(peerIdIndex));
|
||||
}
|
||||
} while (c.moveToNext());
|
||||
} while(c.moveToNext());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -66,12 +66,12 @@ public class DoNotReadDBHelper extends SQLiteOpenHelper {
|
||||
return rs;
|
||||
}
|
||||
|
||||
public void setEnabledForPeerId(int peerId, boolean enabled) {
|
||||
public void setEnabledForPeerId(int peerId, boolean enabled){
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put("enabled", enabled ? 1 : 0);
|
||||
|
||||
int i = getWritableDatabase().update("dnr", cv, "peerId = " + peerId, null);
|
||||
if (i == 0) {
|
||||
if(i == 0){
|
||||
cv.put("peerId", peerId);
|
||||
getWritableDatabase().insert("dnr", null, cv);
|
||||
}
|
||||
|
||||
@@ -12,34 +12,34 @@ import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.dnr.DNRPrefs;
|
||||
|
||||
public class DoNotTypeDBHelper extends SQLiteOpenHelper {
|
||||
public DoNotTypeDBHelper() {
|
||||
public class DoNotTypeDBHelper extends SQLiteOpenHelper{
|
||||
public DoNotTypeDBHelper(){
|
||||
super(getContext(), "dnt", null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
public void onCreate(SQLiteDatabase db){
|
||||
db.execSQL("create table dnt (peerId integer primary key, enabled integer)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
|
||||
|
||||
}
|
||||
|
||||
public List<Integer> get() {
|
||||
public List<Integer> get(){
|
||||
ArrayList<Integer> rs = new ArrayList<>();
|
||||
|
||||
try (Cursor c = getReadableDatabase().query("dnt", null, null, null, null, null, null)) {
|
||||
if (c.moveToFirst()) {
|
||||
if(c.moveToFirst()){
|
||||
int peerIdIndex = c.getColumnIndex("peerId");
|
||||
int enabledIndex = c.getColumnIndex("enabled");
|
||||
|
||||
do {
|
||||
if (c.getInt(enabledIndex) == 1) {
|
||||
if(c.getInt(enabledIndex) == 1){
|
||||
rs.add(c.getInt(peerIdIndex));
|
||||
}
|
||||
} while (c.moveToNext());
|
||||
} while(c.moveToNext());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -48,16 +48,16 @@ public class DoNotTypeDBHelper extends SQLiteOpenHelper {
|
||||
return rs;
|
||||
}
|
||||
|
||||
public boolean isEnabledForPeerId(int peerId) {
|
||||
public boolean isEnabledForPeerId(int peerId){
|
||||
try (Cursor c = getReadableDatabase().query("dnt", null, null, null, null, null, null)) {
|
||||
if (c.moveToFirst()) {
|
||||
if(c.moveToFirst()){
|
||||
int peerIdIndex = c.getColumnIndex("peerId");
|
||||
int enabledIndex = c.getColumnIndex("enabled");
|
||||
|
||||
do {
|
||||
if (c.getInt(peerIdIndex) == peerId)
|
||||
if(c.getInt(peerIdIndex) == peerId)
|
||||
return c.getInt(enabledIndex) == 1;
|
||||
} while (c.moveToNext());
|
||||
} while(c.moveToNext());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -66,12 +66,12 @@ public class DoNotTypeDBHelper extends SQLiteOpenHelper {
|
||||
return DNRPrefs.getActivityWithoutExceptions(peerId);
|
||||
}
|
||||
|
||||
public void setEnabledForPeerId(int peerId, boolean enabled) {
|
||||
public void setEnabledForPeerId(int peerId, boolean enabled){
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put("enabled", enabled ? 1 : 0);
|
||||
|
||||
int i = getWritableDatabase().update("dnt", cv, "peerId = " + peerId, null);
|
||||
if (i == 0) {
|
||||
if(i == 0){
|
||||
cv.put("peerId", peerId);
|
||||
getWritableDatabase().insert("dnt", null, cv);
|
||||
}
|
||||
|
||||
@@ -17,44 +17,45 @@ import b.h.g.m.FileUtils;
|
||||
import ru.vtosters.lite.ui.activities.APKInstallActivity;
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
|
||||
public class OTADownloader {
|
||||
public class OTADownloader{
|
||||
|
||||
private static final BroadcastReceiver callback = new BroadcastReceiver() {
|
||||
private static final BroadcastReceiver callback = new BroadcastReceiver(){
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
public void onReceive(Context context, Intent intent){
|
||||
var extras = intent.getExtras();
|
||||
if (extras == null
|
||||
|| !intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) return;
|
||||
if(extras == null
|
||||
|| !intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
|
||||
return;
|
||||
|
||||
var query = new DownloadManager.Query();
|
||||
var id = extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID);
|
||||
query.setFilterById(id);
|
||||
var manager = (DownloadManager) Globals.getContext().getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
var cursor = manager.query(query);
|
||||
if (cursor.moveToFirst()) {
|
||||
if(cursor.moveToFirst()){
|
||||
@SuppressLint("Range") var status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
|
||||
if (status == DownloadManager.STATUS_SUCCESSFUL) {
|
||||
if(status == DownloadManager.STATUS_SUCCESSFUL){
|
||||
var downloadDir = new File(Environment.getExternalStorageDirectory(), "Download");
|
||||
if (!downloadDir.exists()) return;
|
||||
if(!downloadDir.exists()) return;
|
||||
var list = downloadDir.listFiles();
|
||||
if (list == null || list.length == 0) return;
|
||||
if(list == null || list.length == 0) return;
|
||||
var maxIndex = -1;
|
||||
for (File file : list) {
|
||||
var name = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf("/") + 1);
|
||||
if (file.isFile()
|
||||
for(File file : list) {
|
||||
var name = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf("/") + 1);
|
||||
if(file.isFile()
|
||||
&& name.matches("VTLite-\\d+\\.apk"))
|
||||
maxIndex = Math.max(maxIndex, Integer.parseInt(name.replaceFirst(".+-(\\d+).+", "$1")));
|
||||
}
|
||||
File apk = maxIndex == -1 ? new File(downloadDir, "VTLite.apk") : new File(downloadDir, "VTLite-" + maxIndex + ".apk");
|
||||
APKInstallActivity.installOta(context, FileUtils.n(apk));
|
||||
} else if (status == DownloadManager.STATUS_FAILED) {
|
||||
} else if(status == DownloadManager.STATUS_FAILED){
|
||||
Globals.sendToast(getString("downloaderr"));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static void downloadBuild(String url) {
|
||||
public static void downloadBuild(String url){
|
||||
var context = Globals.getContext();
|
||||
var uri = Uri.parse(url);
|
||||
|
||||
@@ -63,7 +64,7 @@ public class OTADownloader {
|
||||
var request = new DownloadManager.Request(uri);
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
request.setTitle("VTLite.apk");
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "VTLite.apk");
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "VTLite.apk");
|
||||
|
||||
var manager = (DownloadManager) Globals.getContext().getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
manager.enqueue(request);
|
||||
|
||||
@@ -15,48 +15,48 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class VideoDownloader {
|
||||
public static void downloadVideo(VideoFile videoFile, Context context) {
|
||||
public class VideoDownloader{
|
||||
public static void downloadVideo(VideoFile videoFile, Context context){
|
||||
final List<String> list = new ArrayList<>();
|
||||
final List<String> urls = new ArrayList<>();
|
||||
|
||||
if (!Objects.equals(videoFile.e, "")) {
|
||||
if(!Objects.equals(videoFile.e, "")){
|
||||
list.add("240p");
|
||||
urls.add(videoFile.e);
|
||||
}
|
||||
if (!Objects.equals(videoFile.f, "")) {
|
||||
if(!Objects.equals(videoFile.f, "")){
|
||||
list.add("360p");
|
||||
urls.add(videoFile.f);
|
||||
}
|
||||
if (!Objects.equals(videoFile.g, "")) {
|
||||
if(!Objects.equals(videoFile.g, "")){
|
||||
list.add("480p");
|
||||
urls.add(videoFile.g);
|
||||
}
|
||||
if (!Objects.equals(videoFile.h, "")) {
|
||||
if(!Objects.equals(videoFile.h, "")){
|
||||
list.add("720p");
|
||||
urls.add(videoFile.h);
|
||||
}
|
||||
if (!Objects.equals(videoFile.B, "")) {
|
||||
if(!Objects.equals(videoFile.B, "")){
|
||||
list.add("1080p");
|
||||
urls.add(videoFile.B);
|
||||
}
|
||||
if (!Objects.equals(videoFile.C, "")) {
|
||||
if(!Objects.equals(videoFile.C, "")){
|
||||
list.add("1440p");
|
||||
urls.add(videoFile.C);
|
||||
}
|
||||
if (!Objects.equals(videoFile.D, "")) {
|
||||
if(!Objects.equals(videoFile.D, "")){
|
||||
list.add("2160p");
|
||||
urls.add(videoFile.D);
|
||||
}
|
||||
|
||||
if (list.isEmpty()) {
|
||||
if(list.isEmpty()){
|
||||
ToastUtils.a(getString("videodownloaderr"));
|
||||
return;
|
||||
}
|
||||
|
||||
var max = new String[list.size()];
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
for(int i = 0; i < list.size(); i++) {
|
||||
max[i] = list.get(i);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,36 +19,45 @@ import ru.vtosters.lite.encryption.processors.MP3InvisibleProcessor;
|
||||
import ru.vtosters.lite.encryption.processors.VTostersAESProcessor;
|
||||
import ru.vtosters.lite.encryption.processors.VTostersProcessor;
|
||||
|
||||
public class EncryptProvider {
|
||||
public class EncryptProvider{
|
||||
public static List<IMProcessor> processors = new ArrayList<>();
|
||||
|
||||
public static IMProcessor getProcessorFor(int peerId) {
|
||||
static{
|
||||
processors.add(new VTostersProcessor());
|
||||
processors.add(new VTostersAESProcessor());
|
||||
processors.add(new DefaultCoffeeProcessor());
|
||||
processors.add(new DonateCoffeeProcessor());
|
||||
processors.add(new BeeCryptProcessor());
|
||||
processors.add(new MP3InvisibleProcessor());
|
||||
}
|
||||
|
||||
public static IMProcessor getProcessorFor(int peerId){
|
||||
IMProcessor enabled = null;
|
||||
for (IMProcessor processor: EncryptProvider.processors) {
|
||||
if (processor.isUsedToEncrypt(peerId)) {
|
||||
for(IMProcessor processor : EncryptProvider.processors) {
|
||||
if(processor.isUsedToEncrypt(peerId)){
|
||||
enabled = processor;
|
||||
}
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public static String getBody(MsgFromUser msg) {
|
||||
public static String getBody(MsgFromUser msg){
|
||||
return msg.f();
|
||||
}
|
||||
|
||||
public static int getPeerId(Msg msg) {
|
||||
public static int getPeerId(Msg msg){
|
||||
return msg.v1();
|
||||
}
|
||||
|
||||
// This will run through EVERY single processor available.
|
||||
public static String decryptMessage(MsgFromUser msg) {
|
||||
public static String decryptMessage(MsgFromUser msg){
|
||||
return decryptMessage(getBody(msg), getPeerId(msg));
|
||||
}
|
||||
|
||||
public static String decryptMessage(String msgBody, int peer) {
|
||||
public static String decryptMessage(String msgBody, int peer){
|
||||
try {
|
||||
for (IMProcessor processor : processors) {
|
||||
if ((processor.isUsed() || !processor.isPublic()) && processor.isEncrypted(msgBody) && (processor.isPublic() || getKeyForProcessor(processor, peer) != null))
|
||||
for(IMProcessor processor : processors) {
|
||||
if((processor.isUsed() || !processor.isPublic()) && processor.isEncrypted(msgBody) && (processor.isPublic() || getKeyForProcessor(processor, peer) != null))
|
||||
return "\uD83D\uDD12 " + processor.decode(msgBody, getKeyForProcessor(processor, peer));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -57,10 +66,10 @@ public class EncryptProvider {
|
||||
return msgBody;
|
||||
}
|
||||
|
||||
private static byte[] getKeyForProcessor(IMProcessor processor, int peer) {
|
||||
if (processor.isPublic()) return null;
|
||||
private static byte[] getKeyForProcessor(IMProcessor processor, int peer){
|
||||
if(processor.isPublic()) return null;
|
||||
String keyString = processor.getEncryptionKeyFor(peer);
|
||||
if (keyString == null) return null;
|
||||
if(keyString == null) return null;
|
||||
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
@@ -76,7 +85,7 @@ public class EncryptProvider {
|
||||
}
|
||||
|
||||
// This will use only the processor which was chosen in chat menu [that's why ID is needed, bruh]
|
||||
public static String encryptMessage(MsgFromUser msg) {
|
||||
public static String encryptMessage(MsgFromUser msg){
|
||||
|
||||
String msgBody = getBody(msg);
|
||||
|
||||
@@ -84,9 +93,9 @@ public class EncryptProvider {
|
||||
Log.d("EncryptProvider", "encryptMessage: body = " + msgBody);
|
||||
Log.d("EncryptProvider", "encryptMessage: peerId = " + getPeerId(msg));
|
||||
|
||||
for (IMProcessor processor: processors) {
|
||||
for(IMProcessor processor : processors) {
|
||||
int peer = getPeerId(msg);
|
||||
if (processor.isUsedToEncrypt(peer)) {
|
||||
if(processor.isUsedToEncrypt(peer)){
|
||||
return processor.encode(msgBody, getKeyForProcessor(processor, peer));
|
||||
}
|
||||
}
|
||||
@@ -95,22 +104,14 @@ public class EncryptProvider {
|
||||
}
|
||||
|
||||
// For rendering UI
|
||||
public static List<Pair<String, String>> getUserVisibleEncoders() {
|
||||
public static List<Pair<String, String>> getUserVisibleEncoders(){
|
||||
List<Pair<String, String>> theList = new ArrayList<>();
|
||||
|
||||
for (IMProcessor processor: processors) {
|
||||
if (processor.isPublic()) theList.add(new Pair<>("VT_IMDecode_"+processor.getPrefKey(), processor.getUIName()));
|
||||
for(IMProcessor processor : processors) {
|
||||
if(processor.isPublic())
|
||||
theList.add(new Pair<>("VT_IMDecode_" + processor.getPrefKey(), processor.getUIName()));
|
||||
}
|
||||
|
||||
return theList;
|
||||
}
|
||||
|
||||
static {
|
||||
processors.add(new VTostersProcessor());
|
||||
processors.add(new VTostersAESProcessor());
|
||||
processors.add(new DefaultCoffeeProcessor());
|
||||
processors.add(new DonateCoffeeProcessor());
|
||||
processors.add(new BeeCryptProcessor());
|
||||
processors.add(new MP3InvisibleProcessor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,71 +7,80 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
|
||||
public abstract class IMProcessor {
|
||||
public abstract class IMProcessor{
|
||||
// By default it checks start and end tag.
|
||||
public boolean isEncrypted(String source) {
|
||||
public boolean isEncrypted(String source){
|
||||
//Log.d("IMProcessor", "Checking if encrypted: "+source+" / "+getUIName());
|
||||
return source.startsWith(startTag()) && source.endsWith(endTag());
|
||||
}
|
||||
|
||||
// Key can be null - if it's a public processor
|
||||
@NonNull protected abstract String encodeInternal(@NonNull String source, @Nullable byte[] key);
|
||||
@NonNull protected abstract String decodeInternal(@NonNull String source, @Nullable byte[] key);
|
||||
@NonNull
|
||||
protected abstract String encodeInternal(@NonNull String source, @Nullable byte[] key);
|
||||
|
||||
@NonNull
|
||||
protected abstract String decodeInternal(@NonNull String source, @Nullable byte[] key);
|
||||
|
||||
// Automatically removes tags. Magic!
|
||||
@NonNull
|
||||
public String encode(@NonNull String source, @Nullable byte[] key) {
|
||||
public String encode(@NonNull String source, @Nullable byte[] key){
|
||||
//Log.d("IMProcessor", "Encoding "+source);
|
||||
return startTag() + encodeInternal(source, key) + endTag();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String decode(@NonNull String source, @Nullable byte[] key) {
|
||||
public String decode(@NonNull String source, @Nullable byte[] key){
|
||||
//Log.d("IMProcessor", "Decoding");
|
||||
return decodeInternal(source.substring(startTag().length(), source.length() - endTag().length()), key);
|
||||
}
|
||||
|
||||
// Public - no key required.
|
||||
public boolean isPublic() {
|
||||
public boolean isPublic(){
|
||||
return true;
|
||||
}
|
||||
|
||||
// UI thing
|
||||
@NonNull abstract public String getUIName();
|
||||
@NonNull abstract public String getPrefKey();
|
||||
@NonNull
|
||||
abstract public String getUIName();
|
||||
|
||||
@NonNull public String startTag() {
|
||||
return "";
|
||||
}
|
||||
@NonNull public String endTag() {
|
||||
@NonNull
|
||||
abstract public String getPrefKey();
|
||||
|
||||
@NonNull
|
||||
public String startTag(){
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean isUsed() {
|
||||
@NonNull
|
||||
public String endTag(){
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean isUsed(){
|
||||
//Log.d("IMProcessor", "Checking if decoded with "+getUIName());
|
||||
return getBoolValue("VT_IMDecode_"+getPrefKey(), true);
|
||||
return getBoolValue("VT_IMDecode_" + getPrefKey(), true);
|
||||
}
|
||||
|
||||
public boolean isUsedToEncrypt(int id) {
|
||||
public boolean isUsedToEncrypt(int id){
|
||||
//Log.d("IMProcessor", "Checking if "+id+" is ready to be encrypted with "+getUIName());
|
||||
return getBoolValue("VT_IMEncode_"+getPrefKey()+"_"+id, false);
|
||||
return getBoolValue("VT_IMEncode_" + getPrefKey() + "_" + id, false);
|
||||
}
|
||||
|
||||
public void enableEncryptFor(int id) {
|
||||
Globals.getDefprefs().edit().putBoolean("VT_IMEncode_"+getPrefKey()+"_"+id, true).apply();
|
||||
public void enableEncryptFor(int id){
|
||||
Globals.getDefprefs().edit().putBoolean("VT_IMEncode_" + getPrefKey() + "_" + id, true).apply();
|
||||
}
|
||||
|
||||
public void disableEncryptFor(int id) {
|
||||
Globals.getDefprefs().edit().putBoolean("VT_IMEncode_"+getPrefKey()+"_"+id, false).apply();
|
||||
public void disableEncryptFor(int id){
|
||||
Globals.getDefprefs().edit().putBoolean("VT_IMEncode_" + getPrefKey() + "_" + id, false).apply();
|
||||
}
|
||||
|
||||
public void setEncryptionKeyFor(int id, @Nullable String key) {
|
||||
if (key == null || key.isEmpty()) key = "VTAesDefault";
|
||||
Globals.getDefprefs().edit().putString("VT_IMEncodeKey_"+getPrefKey()+"_"+id, key).apply();
|
||||
public void setEncryptionKeyFor(int id, @Nullable String key){
|
||||
if(key == null || key.isEmpty()) key = "VTAesDefault";
|
||||
Globals.getDefprefs().edit().putString("VT_IMEncodeKey_" + getPrefKey() + "_" + id, key).apply();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getEncryptionKeyFor(int id) {
|
||||
return Globals.getDefprefs().getString("VT_IMEncodeKey_"+getPrefKey()+"_"+id, null);
|
||||
public String getEncryptionKeyFor(int id){
|
||||
return Globals.getDefprefs().getString("VT_IMEncodeKey_" + getPrefKey() + "_" + id, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,19 +9,19 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
import ru.vtosters.lite.encryption.base.IMProcessor;
|
||||
|
||||
public class BeeCryptProcessor extends IMProcessor {
|
||||
public class BeeCryptProcessor extends IMProcessor{
|
||||
private static final String BC_CHARSET = "жъЖЪ";
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected String encodeInternal(@NonNull String source, @Nullable byte[] key) {
|
||||
protected String encodeInternal(@NonNull String source, @Nullable byte[] key){
|
||||
try {
|
||||
String a = Base64.encodeToString(source.getBytes(StandardCharsets.UTF_8), 2);
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (int i = 0; i < a.length(); i++) {
|
||||
for(int i = 0; i < a.length(); i++) {
|
||||
StringBuilder bintxt = new StringBuilder();
|
||||
int c = a.charAt(i);
|
||||
for (int j = 0; j < 4; j++) {
|
||||
for(int j = 0; j < 4; j++) {
|
||||
bintxt.insert(0, BC_CHARSET.charAt(c % 4));
|
||||
c /= 4;
|
||||
}
|
||||
@@ -35,20 +35,20 @@ public class BeeCryptProcessor extends IMProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEncrypted(String source) {
|
||||
public boolean isEncrypted(String source){
|
||||
return source.matches("[жъЖЪ]{16,}");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected String decodeInternal(@NonNull String source, @Nullable byte[] key) {
|
||||
protected String decodeInternal(@NonNull String source, @Nullable byte[] key){
|
||||
StringBuilder b64 = new StringBuilder();
|
||||
int i = 0;
|
||||
while (i < source.length() - 3) {
|
||||
while(i < source.length() - 3) {
|
||||
try {
|
||||
String bintxt = source.substring(i, i + 4);
|
||||
int c = 0;
|
||||
for (int j = 0; j < 4; j++) {
|
||||
for(int j = 0; j < 4; j++) {
|
||||
c = (c * 4) + Math.max(0, BC_CHARSET.indexOf(bintxt.charAt(j)));
|
||||
}
|
||||
b64.append((char) c);
|
||||
@@ -63,13 +63,13 @@ public class BeeCryptProcessor extends IMProcessor {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getUIName() {
|
||||
public String getUIName(){
|
||||
return "MP3 [beecrypt]";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getPrefKey() {
|
||||
public String getPrefKey(){
|
||||
return "mp3_bc";
|
||||
}
|
||||
}
|
||||
|
||||
+16
-16
@@ -10,11 +10,11 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import ru.vtosters.lite.encryption.base.IMProcessor;
|
||||
|
||||
public class DefaultCoffeeProcessor extends IMProcessor {
|
||||
public class DefaultCoffeeProcessor extends IMProcessor{
|
||||
private final static String KEY = "stupidUsersMustD";
|
||||
private static Cipher dCipher, eCipher;
|
||||
|
||||
static {
|
||||
static{
|
||||
try {
|
||||
SecretKeySpec key = new SecretKeySpec(KEY.getBytes(), "AES");
|
||||
|
||||
@@ -28,26 +28,26 @@ public class DefaultCoffeeProcessor extends IMProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private String toHex(String text) {
|
||||
private String toHex(String text){
|
||||
char[] chars = text.toCharArray();
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (char aChar : chars) {
|
||||
for(char aChar : chars) {
|
||||
String s = Integer.toHexString(aChar);
|
||||
if (s.length() < 2) s = "0" + s;
|
||||
if(s.length() < 2) s = "0" + s;
|
||||
str.append(s.toUpperCase()).append(" ");
|
||||
}
|
||||
|
||||
String string = str.toString();
|
||||
return string.substring(0, string.length()-1);
|
||||
return string.substring(0, string.length() - 1);
|
||||
}
|
||||
|
||||
private String fromHex(String text) {
|
||||
private String fromHex(String text){
|
||||
text = text.replace(" ", "");
|
||||
char[] chars = text.toCharArray();
|
||||
char[] chars2 = new char[chars.length/2];
|
||||
for (int i = 0; i < chars.length; i+=2) {
|
||||
char[] chars2 = new char[chars.length / 2];
|
||||
for(int i = 0; i < chars.length; i += 2) {
|
||||
String c = String.valueOf(chars[i]) + chars[i + 1];
|
||||
chars2[i/2] = (char) Integer.parseInt(c, 16);
|
||||
chars2[i / 2] = (char) Integer.parseInt(c, 16);
|
||||
}
|
||||
|
||||
return new String(chars2);
|
||||
@@ -55,7 +55,7 @@ public class DefaultCoffeeProcessor extends IMProcessor {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected String encodeInternal(@NonNull String source, @Nullable byte[] key) {
|
||||
protected String encodeInternal(@NonNull String source, @Nullable byte[] key){
|
||||
try {
|
||||
return toHex(Base64.encodeToString(eCipher.doFinal(source.getBytes()), 0));
|
||||
} catch (Exception e) {
|
||||
@@ -67,7 +67,7 @@ public class DefaultCoffeeProcessor extends IMProcessor {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected String decodeInternal(@NonNull String source, @Nullable byte[] key) {
|
||||
protected String decodeInternal(@NonNull String source, @Nullable byte[] key){
|
||||
try {
|
||||
return new String(dCipher.doFinal(Base64.decode(fromHex(source), 0)));
|
||||
} catch (Exception e) {
|
||||
@@ -79,25 +79,25 @@ public class DefaultCoffeeProcessor extends IMProcessor {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String startTag() {
|
||||
public String startTag(){
|
||||
return "VK CO FF EE ";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String endTag() {
|
||||
public String endTag(){
|
||||
return " VK CO FF EE";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getUIName() {
|
||||
public String getUIName(){
|
||||
return "VK Coffee [default]";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getPrefKey() {
|
||||
public String getPrefKey(){
|
||||
return "coffee_default";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,28 +2,28 @@ package ru.vtosters.lite.encryption.processors;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class DonateCoffeeProcessor extends DefaultCoffeeProcessor {
|
||||
public class DonateCoffeeProcessor extends DefaultCoffeeProcessor{
|
||||
@Override
|
||||
@NonNull
|
||||
public String startTag() {
|
||||
public String startTag(){
|
||||
return "II ";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String endTag() {
|
||||
public String endTag(){
|
||||
return " II";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getUIName() {
|
||||
public String getUIName(){
|
||||
return "VK Coffee [hidden]";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getPrefKey() {
|
||||
public String getPrefKey(){
|
||||
return "coffee_donate";
|
||||
}
|
||||
}
|
||||
|
||||
+26
-26
@@ -9,14 +9,32 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
import ru.vtosters.lite.encryption.base.IMProcessor;
|
||||
|
||||
public class MP3InvisibleProcessor extends IMProcessor {
|
||||
public class MP3InvisibleProcessor extends IMProcessor{
|
||||
private static String toStr(int a, String cc){
|
||||
StringBuilder s = new StringBuilder();
|
||||
while(a > 0) {
|
||||
s.insert(0, cc.charAt(a % cc.length()));
|
||||
a /= cc.length();
|
||||
}
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
private static int toNum(String a, String cc){
|
||||
int n = 0;
|
||||
for(int i = 0; i < a.length(); i++) {
|
||||
int start = (a.length() - i) - 1;
|
||||
n = (int) (((double) n) + (((double) cc.indexOf(a.substring(start, start + 1))) * Math.pow(cc.length(), i)));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected String encodeInternal(@NonNull String source, @Nullable byte[] key) {
|
||||
protected String encodeInternal(@NonNull String source, @Nullable byte[] key){
|
||||
try {
|
||||
byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
|
||||
java.lang.String[] plainText = new String[bytes.length];
|
||||
for (int i = 0; i < plainText.length; i++) {
|
||||
for(int i = 0; i < plainText.length; i++) {
|
||||
plainText[i] = toStr(bytes[i] & 255, " ");
|
||||
}
|
||||
return " " + TextUtils.join(" ", plainText);
|
||||
@@ -28,11 +46,11 @@ public class MP3InvisibleProcessor extends IMProcessor {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected String decodeInternal(@NonNull String source, @Nullable byte[] key) {
|
||||
protected String decodeInternal(@NonNull String source, @Nullable byte[] key){
|
||||
try {
|
||||
java.lang.String[] t = source.replaceAll("^" + " ", "").split(" ");
|
||||
byte[] plainText = new byte[t.length];
|
||||
for (int i = 0; i < plainText.length; i++) {
|
||||
for(int i = 0; i < plainText.length; i++) {
|
||||
plainText[i] = (byte) toNum(t[i], " ");
|
||||
}
|
||||
return new String(plainText, StandardCharsets.UTF_8);
|
||||
@@ -42,38 +60,20 @@ public class MP3InvisibleProcessor extends IMProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private static String toStr(int a, String cc) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
while (a > 0) {
|
||||
s.insert(0, cc.charAt(a % cc.length()));
|
||||
a /= cc.length();
|
||||
}
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
private static int toNum(String a, String cc) {
|
||||
int n = 0;
|
||||
for (int i = 0; i < a.length(); i++) {
|
||||
int start = (a.length() - i) - 1;
|
||||
n = (int) (((double) n) + (((double) cc.indexOf(a.substring(start, start + 1))) * Math.pow(cc.length(), i)));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEncrypted(String source) {
|
||||
public boolean isEncrypted(String source){
|
||||
return source.matches("^" + " " + "([" + " " + "\\s]*)");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getUIName() {
|
||||
public String getUIName(){
|
||||
return "MP3 [invisible]";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getPrefKey() {
|
||||
public String getPrefKey(){
|
||||
return "mp3";
|
||||
}
|
||||
}
|
||||
|
||||
+18
-18
@@ -19,20 +19,20 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
import ru.vtosters.lite.encryption.base.IMProcessor;
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
|
||||
public class VTostersAESProcessor extends IMProcessor {
|
||||
public class VTostersAESProcessor extends IMProcessor{
|
||||
private final static String CIPHER_INSTANCE = "AES/CBC/PKCS7Padding";
|
||||
private final static String KEY_METHOD = "AES";
|
||||
|
||||
private HashMap<byte[], Cipher> decodeMap = new HashMap<>(), encodeMap = new HashMap<>();
|
||||
|
||||
public void free(byte[] key) {
|
||||
public void free(byte[] key){
|
||||
decodeMap.remove(key);
|
||||
encodeMap.remove(key);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Cipher wrapEncoder(byte[] key) throws InvalidAlgorithmParameterException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {
|
||||
if (encodeMap.containsKey(key)) return encodeMap.get(key);
|
||||
private Cipher wrapEncoder(byte[] key) throws InvalidAlgorithmParameterException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException{
|
||||
if(encodeMap.containsKey(key)) return encodeMap.get(key);
|
||||
|
||||
Triple<Cipher, SecretKeySpec, IvParameterSpec> encodeCipher = getBaseCipher(key);
|
||||
encodeCipher.first.init(Cipher.ENCRYPT_MODE, encodeCipher.second, encodeCipher.third);
|
||||
@@ -42,8 +42,8 @@ public class VTostersAESProcessor extends IMProcessor {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Cipher wrapDecoder(byte[] key) throws InvalidAlgorithmParameterException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {
|
||||
if (decodeMap.containsKey(key)) return decodeMap.get(key);
|
||||
private Cipher wrapDecoder(byte[] key) throws InvalidAlgorithmParameterException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException{
|
||||
if(decodeMap.containsKey(key)) return decodeMap.get(key);
|
||||
|
||||
Triple<Cipher, SecretKeySpec, IvParameterSpec> decodeCipher = getBaseCipher(key);
|
||||
decodeCipher.first.init(Cipher.DECRYPT_MODE, decodeCipher.second, decodeCipher.third);
|
||||
@@ -53,7 +53,7 @@ public class VTostersAESProcessor extends IMProcessor {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Triple<Cipher, SecretKeySpec, IvParameterSpec> getBaseCipher(byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException {
|
||||
private Triple<Cipher, SecretKeySpec, IvParameterSpec> getBaseCipher(byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException{
|
||||
byte[] off = new byte[16];
|
||||
System.arraycopy(key, 0, off, 0, off.length);
|
||||
return new Triple<>(Cipher.getInstance(CIPHER_INSTANCE), new SecretKeySpec(key, KEY_METHOD), new IvParameterSpec(off));
|
||||
@@ -61,7 +61,7 @@ public class VTostersAESProcessor extends IMProcessor {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected String encodeInternal(@NonNull String source, @Nullable byte[] key) {
|
||||
protected String encodeInternal(@NonNull String source, @Nullable byte[] key){
|
||||
try {
|
||||
return Base64.encodeToString(wrapEncoder(key).doFinal(source.getBytes(StandardCharsets.UTF_8)), Base64.DEFAULT);
|
||||
} catch (Exception e) {
|
||||
@@ -72,7 +72,7 @@ public class VTostersAESProcessor extends IMProcessor {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected String decodeInternal(@NonNull String source, @Nullable byte[] key) {
|
||||
protected String decodeInternal(@NonNull String source, @Nullable byte[] key){
|
||||
try {
|
||||
return new String(wrapDecoder(key).doFinal(Base64.decode(source, Base64.DEFAULT)), StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
@@ -82,46 +82,46 @@ public class VTostersAESProcessor extends IMProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPublic() {
|
||||
public boolean isPublic(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String startTag() {
|
||||
public String startTag(){
|
||||
return "VT0ST3RS [AES] ";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String endTag() {
|
||||
public String endTag(){
|
||||
return " VT0ST3RS [AES]";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getUIName() {
|
||||
public String getUIName(){
|
||||
return "VTosters [AES]";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getPrefKey() {
|
||||
public String getPrefKey(){
|
||||
return "vtaes";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getEncryptionKeyFor(int id) {
|
||||
return Globals.getDefprefs().getString("VT_IMEncodeKey_"+getPrefKey()+"_"+id, "VTAesDefault");
|
||||
public String getEncryptionKeyFor(int id){
|
||||
return Globals.getDefprefs().getString("VT_IMEncodeKey_" + getPrefKey() + "_" + id, "VTAesDefault");
|
||||
}
|
||||
|
||||
public static class Triple<F, S, T> {
|
||||
public static class Triple<F, S, T>{
|
||||
public final F first;
|
||||
public final S second;
|
||||
public final T third;
|
||||
|
||||
public Triple(F first, S second, T third) {
|
||||
public Triple(F first, S second, T third){
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.third = third;
|
||||
|
||||
@@ -7,40 +7,40 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import ru.vtosters.lite.encryption.base.IMProcessor;
|
||||
|
||||
public class VTostersProcessor extends IMProcessor {
|
||||
public class VTostersProcessor extends IMProcessor{
|
||||
@NonNull
|
||||
@Override
|
||||
protected String encodeInternal(@NonNull String source, @Nullable byte[] key) {
|
||||
protected String encodeInternal(@NonNull String source, @Nullable byte[] key){
|
||||
return Base64.encodeToString(source.getBytes(), Base64.DEFAULT);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected String decodeInternal(@NonNull String source, @Nullable byte[] key) {
|
||||
protected String decodeInternal(@NonNull String source, @Nullable byte[] key){
|
||||
return new String(Base64.decode(source, Base64.DEFAULT));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String startTag() {
|
||||
public String startTag(){
|
||||
return "VT0ST3RS ";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String endTag() {
|
||||
public String endTag(){
|
||||
return " VT0ST3RS";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getUIName() {
|
||||
public String getUIName(){
|
||||
return "VTosters Classique [Base64]";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getPrefKey() {
|
||||
public String getPrefKey(){
|
||||
return "vt64";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,23 +22,23 @@ import java.io.StringWriter;
|
||||
|
||||
import ru.vtosters.lite.deviceinfo.DeviceInfoCollector;
|
||||
|
||||
public class Crashreporter {
|
||||
public class Crashreporter{
|
||||
protected static String logString;
|
||||
|
||||
public static String getStackTrace(Throwable th) {
|
||||
public static String getStackTrace(Throwable th){
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
th.printStackTrace(new PrintWriter(stringWriter));
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
public static void init(Activity activity) {
|
||||
public static void init(Activity activity){
|
||||
final var defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler((thread, th) -> Crashreporter.start(defaultUncaughtExceptionHandler, thread, th, activity));
|
||||
}
|
||||
|
||||
static void start(Thread.UncaughtExceptionHandler uncaughtExceptionHandler, Thread thread, Throwable th, Activity activity) {
|
||||
static void start(Thread.UncaughtExceptionHandler uncaughtExceptionHandler, Thread thread, Throwable th, Activity activity){
|
||||
logString = getStackTrace(th) + "\n\n" + new DeviceInfoCollector().collect(getContext()).toDeviceName() + ", commit: " + getBuildNumber();
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
if(Build.VERSION.SDK_INT >= 26){
|
||||
var notificationChannel = new NotificationChannel("crashes", "crash", NotificationManager.IMPORTANCE_DEFAULT);
|
||||
notificationChannel.enableVibration(true);
|
||||
notificationChannel.enableLights(true);
|
||||
@@ -48,7 +48,7 @@ public class Crashreporter {
|
||||
var foxbinIntent = new Intent("com.f0x1d.dogbin.ACTION_UPLOAD_TO_FOXBIN");
|
||||
foxbinIntent.putExtra("android.intent.extra.TEXT", logString);
|
||||
foxbinIntent.setType("text/plain");
|
||||
if (!isFoxbinInstalled()) {
|
||||
if(!isFoxbinInstalled()){
|
||||
foxbinIntent = new Intent("android.intent.action.VIEW");
|
||||
foxbinIntent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.f0x1d.dogbin"));
|
||||
foxbinIntent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
|
||||
@@ -65,14 +65,14 @@ public class Crashreporter {
|
||||
builder.setContentText(logString);
|
||||
builder.setStyle(new Notification.BigTextStyle().bigText(logString));
|
||||
builder.setAutoCancel(true);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH){
|
||||
builder.addAction(new Notification.Action(0, getString("vtl_crash_upload"), PendingIntent.getActivity(getContext(), (int) (Math.random() * 100.0d), foxbinIntent, PendingIntent.FLAG_CANCEL_CURRENT)));
|
||||
builder.addAction(new Notification.Action(0, getString("vtl_crash_save"), psaveLogIntent));
|
||||
} else {
|
||||
builder.setContentIntent(PendingIntent.getActivity(activity, 0, foxbinIntent, PendingIntent.FLAG_ONE_SHOT));
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
if(Build.VERSION.SDK_INT >= 26){
|
||||
builder.setChannelId("crashes");
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class Crashreporter {
|
||||
uncaughtExceptionHandler.uncaughtException(thread, th);
|
||||
}
|
||||
|
||||
private static boolean isFoxbinInstalled() {
|
||||
private static boolean isFoxbinInstalled(){
|
||||
var pm = getContext().getPackageManager();
|
||||
try {
|
||||
pm.getPackageInfo("com.f0x1d.dogbin", 0);
|
||||
|
||||
@@ -19,12 +19,12 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class LogWriterService extends Service {
|
||||
public LogWriterService() {
|
||||
public class LogWriterService extends Service{
|
||||
public LogWriterService(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
public int onStartCommand(Intent intent, int flags, int startId){
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
|
||||
Log.d("LogWriterService", "The service has been started");
|
||||
@@ -32,7 +32,7 @@ public class LogWriterService extends Service {
|
||||
try {
|
||||
var exists = file.createNewFile();
|
||||
|
||||
if (!exists) {
|
||||
if(!exists){
|
||||
file.delete();
|
||||
file.createNewFile();
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class LogWriterService extends Service {
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
private void writeLog(Intent intent, File file) throws IOException {
|
||||
private void writeLog(Intent intent, File file) throws IOException{
|
||||
FileOutputStream stream;
|
||||
stream = new FileOutputStream(file);
|
||||
stream.write(intent.getStringExtra("log").getBytes(StandardCharsets.UTF_8));
|
||||
@@ -60,7 +60,7 @@ public class LogWriterService extends Service {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
public IBinder onBind(Intent intent){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class VTVerifications {
|
||||
public class VTVerifications{
|
||||
public static final HashMap<Integer, Boolean> sServiceAccountsMap = new HashMap<>();
|
||||
private static final String TAG = "VTVerifications";
|
||||
private static final String DEVELOPERS_KEY = "VTNRS3";
|
||||
@@ -37,10 +37,10 @@ public class VTVerifications {
|
||||
private static final HashMap<Integer, Boolean> sDevelopersMap = new HashMap<>();
|
||||
private static final HashMap<Integer, Boolean> sPrometheusMap = new HashMap<>();
|
||||
private static final HashMap<Integer, Boolean> sVerificationsMap = new HashMap<>();
|
||||
private static SharedPreferences mVerificationsCache;
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
private static SharedPreferences mVerificationsCache;
|
||||
|
||||
public static void load(Context context) {
|
||||
public static void load(Context context){
|
||||
mVerificationsCache = context.getSharedPreferences("vt_another_data", 0);
|
||||
|
||||
try {
|
||||
@@ -58,9 +58,9 @@ public class VTVerifications {
|
||||
.a(RequestBody.a(MediaType.b("application/json; charset=UTF-8"), "{\"types\":[0,228,404,1337]}"))
|
||||
.a();
|
||||
|
||||
client.a(request).a(new Callback() {
|
||||
client.a(request).a(new Callback(){
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
public void a(Call call, IOException e){
|
||||
Log.d(TAG, "" + e);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class VTVerifications {
|
||||
});
|
||||
}
|
||||
|
||||
private static void getVerifications(String body) throws Exception {
|
||||
private static void getVerifications(String body) throws Exception{
|
||||
JSONObject jSONObject = new JSONObject(body);
|
||||
processArray(jSONObject.optJSONArray("0"), sVerificationsMap, VERIFICATIONS_KEY);
|
||||
processArray(jSONObject.optJSONArray("228"), sPrometheusMap, PROMETHEUS_KEY);
|
||||
@@ -83,92 +83,92 @@ public class VTVerifications {
|
||||
processArray(jSONObject.optJSONArray("1337"), sServiceAccountsMap, SERVICE_ACCOUNTS_KEY);
|
||||
}
|
||||
|
||||
private static void processArray(JSONArray jSONArray, Map<Integer, Boolean> map, String str) {
|
||||
if (jSONArray != null) {
|
||||
for (int i = 0; i < jSONArray.length(); i++) {
|
||||
private static void processArray(JSONArray jSONArray, Map<Integer, Boolean> map, String str){
|
||||
if(jSONArray != null){
|
||||
for(int i = 0; i < jSONArray.length(); i++) {
|
||||
map.put(jSONArray.optInt(i), true);
|
||||
}
|
||||
if (str != null) {
|
||||
if(str != null){
|
||||
setLoaded(str, jSONArray.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isVerified(int i) {
|
||||
public static boolean isVerified(int i){
|
||||
return sVerificationsMap.get(i) != null ? sVerificationsMap.get(i) : false;
|
||||
}
|
||||
|
||||
public static boolean isVerifiedMSG(int i) {
|
||||
public static boolean isVerifiedMSG(int i){
|
||||
return sVerificationsMap.get(i) != null ? sVerificationsMap.get(i) : false;
|
||||
}
|
||||
|
||||
public static boolean hasPrometheus(int i) {
|
||||
public static boolean hasPrometheus(int i){
|
||||
return sPrometheusMap.get(i) != null ? sPrometheusMap.get(i) : false;
|
||||
}
|
||||
|
||||
public static boolean isDeveloper(int i) {
|
||||
public static boolean isDeveloper(int i){
|
||||
return sDevelopersMap.get(i) != null ? sDevelopersMap.get(i) : false;
|
||||
}
|
||||
|
||||
public static boolean isServiceAccount(int i) {
|
||||
public static boolean isServiceAccount(int i){
|
||||
return sServiceAccountsMap.get(i) != null ? sServiceAccountsMap.get(i) : false;
|
||||
|
||||
}
|
||||
|
||||
private static String getLoaded(String str) {
|
||||
private static String getLoaded(String str){
|
||||
return decode(mVerificationsCache.getString(str, encode("[]")));
|
||||
}
|
||||
|
||||
public static void setLoaded(String str, String str2) {
|
||||
public static void setLoaded(String str, String str2){
|
||||
mVerificationsCache.edit().putString(str, encode(str2)).apply();
|
||||
}
|
||||
|
||||
public static String decode(String str) {
|
||||
public static String decode(String str){
|
||||
return new String(Base64.decode(str, 1), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static String encode(String str) {
|
||||
public static String encode(String str){
|
||||
return Base64.encodeToString(str.getBytes(), 1);
|
||||
}
|
||||
|
||||
|
||||
public static boolean vtverif() {
|
||||
public static boolean vtverif(){
|
||||
return getBoolValue("VT_Verification", true);
|
||||
}
|
||||
|
||||
public static boolean isVerified(JSONObject jSONObject) {
|
||||
if (jSONObject.optInt("verified", 0) == 1) {
|
||||
public static boolean isVerified(JSONObject jSONObject){
|
||||
if(jSONObject.optInt("verified", 0) == 1){
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!getBoolValue("VT_Verification", true)) {
|
||||
if(!getBoolValue("VT_Verification", true)){
|
||||
return false;
|
||||
}
|
||||
|
||||
return isVerified((jSONObject.optString(NavigatorKeys.e) == null || (!jSONObject.optString(NavigatorKeys.e).equals("group") && !jSONObject.optString(NavigatorKeys.e).equals("page"))) ? jSONObject.optInt("id", 0) : -jSONObject.optInt("id", 0));
|
||||
}
|
||||
|
||||
public static boolean hasPrometheus(JSONObject jSONObject) {
|
||||
if (jSONObject.optInt("trending", 0) == 1) {
|
||||
public static boolean hasPrometheus(JSONObject jSONObject){
|
||||
if(jSONObject.optInt("trending", 0) == 1){
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!getBoolValue("VT_Fire", true)) {
|
||||
if(!getBoolValue("VT_Fire", true)){
|
||||
return false;
|
||||
}
|
||||
|
||||
return hasPrometheus((jSONObject.optString(NavigatorKeys.e) == null || (!jSONObject.optString(NavigatorKeys.e).equals("group") && !jSONObject.optString(NavigatorKeys.e).equals("page"))) ? jSONObject.optInt("id", 0) : -jSONObject.optInt("id", 0));
|
||||
}
|
||||
|
||||
public static boolean hasDeveloper(JSONObject jSONObject) {
|
||||
if (!getBoolValue("VT_Dev", true)) {
|
||||
public static boolean hasDeveloper(JSONObject jSONObject){
|
||||
if(!getBoolValue("VT_Dev", true)){
|
||||
return false;
|
||||
}
|
||||
|
||||
return isDeveloper((jSONObject.optString(NavigatorKeys.e) == null || (!jSONObject.optString(NavigatorKeys.e).equals("group") && !jSONObject.optString(NavigatorKeys.e).equals("page"))) ? jSONObject.optInt("id", 0) : -jSONObject.optInt("id", 0));
|
||||
}
|
||||
|
||||
public static VerifyInfo VerifyInfo(JSONObject jSONObject) {
|
||||
public static VerifyInfo VerifyInfo(JSONObject jSONObject){
|
||||
return new VerifyInfo(isVerified(jSONObject), hasPrometheus(jSONObject));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import static ru.vtosters.lite.utils.Proxy.proxy;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.exifinterface.media.ExifInterface;
|
||||
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
@@ -27,31 +26,31 @@ import java.util.regex.Pattern;
|
||||
import okhttp3.OkHttpClient;
|
||||
import ru.vtosters.lite.net.Request;
|
||||
|
||||
public class FoafBase {
|
||||
public class FoafBase{
|
||||
private static final Pattern FOAF_REGEX = Pattern.compile("<ya:created dc:date=\"(.+?)\"\\/>");
|
||||
private static final Pattern FOAF_REGEX_LAST_SEEN = Pattern.compile("<ya:lastLoggedIn dc:date=\"(.*)(((\\+|-)\\d\\d):(\\d\\d))\"\\/>");
|
||||
private static final Pattern FOAF_REGEX_LOGIN = Pattern.compile("<ya:created dc:date=\"(.+?)\"\\/>");
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
public static int GetLastSeenInt(int i) throws ParseException, IOException {
|
||||
public static int GetLastSeenInt(int i) throws ParseException, IOException{
|
||||
Matcher matcher = FOAF_REGEX_LAST_SEEN.matcher(
|
||||
client.a(
|
||||
new okhttp3.Request.a().a(getLink(i)).b().a()
|
||||
).execute().a().g());
|
||||
if (!matcher.find()) {
|
||||
if(!matcher.find()){
|
||||
return 0;
|
||||
}
|
||||
return (int) (new SimpleDateFormat("yyyy-MM-dd'T'kk:mm:ss", Locale.getDefault()).parse(matcher.group(1)).getTime() / 1000);
|
||||
}
|
||||
|
||||
public static long GetLastSeenLong(int i) throws ParseException, IOException {
|
||||
public static long GetLastSeenLong(int i) throws ParseException, IOException{
|
||||
return GetLastSeenInt(i);
|
||||
}
|
||||
|
||||
private static String getLink(int i) {
|
||||
private static String getLink(int i){
|
||||
String str;
|
||||
StringBuilder sb;
|
||||
if (proxy()) {
|
||||
if(proxy()){
|
||||
sb = new StringBuilder();
|
||||
str = "https://" + getApiCom() + "/_/vk.com/foaf.php?id=";
|
||||
} else {
|
||||
@@ -63,17 +62,17 @@ public class FoafBase {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void loadAndShow(Context context, int i) {
|
||||
public static void loadAndShow(Context context, int i){
|
||||
ProgressDialog progressDialog = new ProgressDialog(context);
|
||||
progressDialog.setMessage(getString("com_facebook_loading"));
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
Request.RequestCallback callback =str -> FoafBase.lambdaLoadAndShow(progressDialog, context, i, str);
|
||||
Request.RequestCallback callback = str -> FoafBase.lambdaLoadAndShow(progressDialog, context, i, str);
|
||||
Request.makeRequest(getLink(i), callback);
|
||||
}
|
||||
|
||||
static void lambdaLoadAndShow(ProgressDialog progressDialog, Context context, int i, String str) {
|
||||
static void lambdaLoadAndShow(ProgressDialog progressDialog, Context context, int i, String str){
|
||||
try {
|
||||
progressDialog.cancel();
|
||||
Matcher matcher = FOAF_REGEX.matcher(str);
|
||||
@@ -90,7 +89,7 @@ public class FoafBase {
|
||||
}
|
||||
}
|
||||
|
||||
private static long daysPassedFromFoafDate(String str) {
|
||||
private static long daysPassedFromFoafDate(String str){
|
||||
try {
|
||||
Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(str.split(" ")[1]);
|
||||
return TimeUnit.DAYS.convert(new Date().getTime() - parse.getTime(), TimeUnit.MILLISECONDS);
|
||||
@@ -100,7 +99,7 @@ public class FoafBase {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getNormalHumanDate(String str) {
|
||||
private static String getNormalHumanDate(String str){
|
||||
String[] split = str.split(ExifInterface.GPS_DIRECTION_TRUE);
|
||||
return split[1].split("\\+")[0] + " " + split[0];
|
||||
}
|
||||
|
||||
@@ -15,45 +15,45 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public final class NetCall {
|
||||
public final class NetCall{
|
||||
private final NetRequest req;
|
||||
private final NetClient cl;
|
||||
|
||||
protected NetCall(NetClient cl, NetRequest req) {
|
||||
protected NetCall(NetClient cl, NetRequest req){
|
||||
this.req = req;
|
||||
this.cl = cl;
|
||||
}
|
||||
|
||||
private static String constructArgs(Map<String, String> args) throws UnsupportedEncodingException {
|
||||
private static String constructArgs(Map<String, String> args) throws UnsupportedEncodingException{
|
||||
args = new TreeMap<>(args);
|
||||
String str = "";
|
||||
for (Map.Entry<String, String> en : args.entrySet()) {
|
||||
if (!str.isEmpty()) str += "&";
|
||||
for(Map.Entry<String, String> en : args.entrySet()) {
|
||||
if(!str.isEmpty()) str += "&";
|
||||
str += URLEncoder.encode(en.getKey(), "UTF-8") + "=" + URLEncoder.encode(en.getValue(), "UTF-8");
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public NetRequest request() {
|
||||
public NetRequest request(){
|
||||
return req;
|
||||
}
|
||||
|
||||
public NetResponse execute() throws IOException {
|
||||
public NetResponse execute() throws IOException{
|
||||
Proxy proxy = cl.getProxy();
|
||||
PasswordAuthentication auth = cl.getAuthenticator();
|
||||
HttpURLConnection con = (HttpURLConnection) new URL(req.url()).openConnection(proxy != null ? proxy : Proxy.NO_PROXY);
|
||||
if (proxy != null && auth != null) {
|
||||
if(proxy != null && auth != null){
|
||||
String authStr = "Basic " + Base64.encodeToString((auth.getUserName() + new String(auth.getPassword())).getBytes(), Base64.NO_WRAP);
|
||||
con.setRequestProperty("Proxy-Connection", "Keep-Alive");
|
||||
con.setRequestProperty("Proxy-Authorization", authStr);
|
||||
}
|
||||
con.setConnectTimeout((int) cl.getTimeout());
|
||||
con.setRequestMethod(req.getRequestMethod());
|
||||
if (req.getRequestMethod().equals("POST")) {
|
||||
if(req.getRequestMethod().equals("POST")){
|
||||
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
}
|
||||
Map<String, String> params = req.getRequestParams();
|
||||
if (params != null) {
|
||||
if(params != null){
|
||||
String strArgs = constructArgs(params);
|
||||
con.setRequestProperty("Content-Length", String.valueOf(strArgs.getBytes(StandardCharsets.UTF_8).length));
|
||||
con.setDoOutput(true);
|
||||
@@ -62,12 +62,12 @@ public final class NetCall {
|
||||
}
|
||||
con.connect();
|
||||
InputStream in;
|
||||
if (con.getResponseCode() == 200) in = con.getInputStream();
|
||||
if(con.getResponseCode() == 200) in = con.getInputStream();
|
||||
else in = con.getErrorStream();
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024 * 1024];
|
||||
int c;
|
||||
while ((c = in.read(buffer)) != -1) bos.write(buffer, 0, c);
|
||||
while((c = in.read(buffer)) != -1) bos.write(buffer, 0, c);
|
||||
in.close();
|
||||
bos.close();
|
||||
NetResponse r = new NetResponse(bos.toByteArray());
|
||||
@@ -75,10 +75,10 @@ public final class NetCall {
|
||||
return r;
|
||||
}
|
||||
|
||||
public void enqueue(NetCallback cb) {
|
||||
new Thread() {
|
||||
public void enqueue(NetCallback cb){
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
public void run(){
|
||||
try {
|
||||
NetResponse resp = execute();
|
||||
cb.onResponse(NetCall.this, resp);
|
||||
|
||||
@@ -2,7 +2,7 @@ package ru.vtosters.lite.net;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface NetCallback {
|
||||
public interface NetCallback{
|
||||
void onFailure(NetCall netCall, IOException iOException);
|
||||
|
||||
void onResponse(NetCall netCall, NetResponse netResponse) throws IOException;
|
||||
|
||||
@@ -4,18 +4,18 @@ import java.net.PasswordAuthentication;
|
||||
import java.net.Proxy;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class NetClient {
|
||||
public class NetClient{
|
||||
private final long timeout;
|
||||
private final Proxy proxy;
|
||||
private final PasswordAuthentication authenticator;
|
||||
|
||||
protected NetClient(Builder b) {
|
||||
protected NetClient(Builder b){
|
||||
timeout = b.timeout;
|
||||
proxy = b.proxy;
|
||||
authenticator = b.auth;
|
||||
}
|
||||
|
||||
public Builder newBuilder() {
|
||||
public Builder newBuilder(){
|
||||
Builder b = new Builder();
|
||||
b.timeout = timeout;
|
||||
b.proxy = proxy;
|
||||
@@ -23,30 +23,30 @@ public class NetClient {
|
||||
return b;
|
||||
}
|
||||
|
||||
public NetCall newCall(NetRequest req) {
|
||||
public NetCall newCall(NetRequest req){
|
||||
return new NetCall(this, req);
|
||||
}
|
||||
|
||||
public PasswordAuthentication getAuthenticator() {
|
||||
public PasswordAuthentication getAuthenticator(){
|
||||
return authenticator;
|
||||
}
|
||||
|
||||
public Proxy getProxy() {
|
||||
public Proxy getProxy(){
|
||||
return proxy;
|
||||
}
|
||||
|
||||
public long getTimeout() {
|
||||
public long getTimeout(){
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
public static final class Builder{
|
||||
private long timeout;
|
||||
private Proxy proxy;
|
||||
private PasswordAuthentication auth;
|
||||
|
||||
public Builder connectTimeout(long l, TimeUnit unit) {
|
||||
public Builder connectTimeout(long l, TimeUnit unit){
|
||||
int m;
|
||||
switch (unit) {
|
||||
switch(unit) {
|
||||
case SECONDS:
|
||||
m = 1000;
|
||||
break;
|
||||
@@ -70,17 +70,17 @@ public class NetClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder proxyAuthenticator(PasswordAuthentication auth) {
|
||||
public Builder proxyAuthenticator(PasswordAuthentication auth){
|
||||
this.auth = auth;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder proxy(Proxy proxy) {
|
||||
public Builder proxy(Proxy proxy){
|
||||
this.proxy = proxy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NetClient build() {
|
||||
public NetClient build(){
|
||||
return new NetClient(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,60 +3,60 @@ package ru.vtosters.lite.net;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class NetRequest {
|
||||
public class NetRequest{
|
||||
private final String url;
|
||||
private final String requestMethod;
|
||||
private final Map<String, String> params;
|
||||
|
||||
protected NetRequest(Builder b) {
|
||||
protected NetRequest(Builder b){
|
||||
url = b.url;
|
||||
requestMethod = b.req;
|
||||
params = b.params;
|
||||
}
|
||||
|
||||
public Map<String, String> getRequestParams() {
|
||||
public Map<String, String> getRequestParams(){
|
||||
return params;
|
||||
}
|
||||
|
||||
public String url() {
|
||||
public String url(){
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getRequestMethod() {
|
||||
public String getRequestMethod(){
|
||||
return requestMethod;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
public static final class Builder{
|
||||
private String url;
|
||||
private String req = "GET";
|
||||
private Map<String, String> params;
|
||||
|
||||
public NetRequest build() {
|
||||
public NetRequest build(){
|
||||
return new NetRequest(this);
|
||||
}
|
||||
|
||||
public Builder url(String url) {
|
||||
public Builder url(String url){
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder get() {
|
||||
public Builder get(){
|
||||
req = "GET";
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder post() {
|
||||
public Builder post(){
|
||||
req = "POST";
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder params(Map<String, String> params) {
|
||||
public Builder params(Map<String, String> params){
|
||||
this.params = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder param(String param, String value) {
|
||||
if (params == null) params = new TreeMap<>();
|
||||
public Builder param(String param, String value){
|
||||
if(params == null) params = new TreeMap<>();
|
||||
params.put(param, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -4,35 +4,35 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public final class NetResponse {
|
||||
public final class NetResponse{
|
||||
private final byte[] data;
|
||||
private int code;
|
||||
|
||||
protected NetResponse(byte[] data) {
|
||||
protected NetResponse(byte[] data){
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
protected void setCode(int code) {
|
||||
protected void setCode(int code){
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public boolean isSuccessful() {
|
||||
public boolean isSuccessful(){
|
||||
return code() == 200;
|
||||
}
|
||||
|
||||
public int code() {
|
||||
public int code(){
|
||||
return code;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
public byte[] getData(){
|
||||
return data;
|
||||
}
|
||||
|
||||
public InputStream getDataStream() {
|
||||
public InputStream getDataStream(){
|
||||
return new ByteArrayInputStream(data);
|
||||
}
|
||||
|
||||
public String getDataString() {
|
||||
public String getDataString(){
|
||||
return new String(data, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,41 +11,41 @@ import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class Request {
|
||||
public static void makeRequest(byte[] bArr, RequestCallback RequestCallback) {
|
||||
public class Request{
|
||||
public static void makeRequest(byte[] bArr, RequestCallback RequestCallback){
|
||||
new MakeRequestTask(bArr, RequestCallback).execute();
|
||||
}
|
||||
|
||||
public static void makeRequest(String str, RequestCallback RequestCallback) {
|
||||
public static void makeRequest(String str, RequestCallback RequestCallback){
|
||||
new MakeRequestTask(str.getBytes(), RequestCallback).execute();
|
||||
}
|
||||
|
||||
public interface RequestCallback {
|
||||
public interface RequestCallback{
|
||||
void onResponse(String str);
|
||||
}
|
||||
|
||||
private static class MakeRequestTask extends AsyncTask<Void, Void, String> {
|
||||
private static class MakeRequestTask extends AsyncTask<Void, Void, String>{
|
||||
private final RequestCallback callback;
|
||||
private final byte[] url;
|
||||
private boolean mIsPut;
|
||||
private boolean mIsVTostersRequest;
|
||||
private final byte[] url;
|
||||
|
||||
public MakeRequestTask(byte[] bArr, RequestCallback RequestCallback) {
|
||||
public MakeRequestTask(byte[] bArr, RequestCallback RequestCallback){
|
||||
mIsVTostersRequest = false;
|
||||
mIsPut = false;
|
||||
callback = RequestCallback;
|
||||
url = bArr;
|
||||
}
|
||||
|
||||
public String doInBackground(Void... voidArr) {
|
||||
public String doInBackground(Void... voidArr){
|
||||
try {
|
||||
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(new String(url)).openConnection();
|
||||
httpURLConnection.setRequestMethod(mIsPut ? "PUT" : "GET");
|
||||
|
||||
if (mIsVTostersRequest) {
|
||||
if(mIsVTostersRequest){
|
||||
httpURLConnection.setRequestProperty("Token", getUserToken());
|
||||
}
|
||||
if (!mIsVTostersRequest) {
|
||||
if(!mIsVTostersRequest){
|
||||
httpURLConnection.setRequestProperty("User-Agent", Network.l.c().a());
|
||||
}
|
||||
|
||||
@@ -53,9 +53,9 @@ public class Request {
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
|
||||
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
while (true) {
|
||||
while(true) {
|
||||
String readLine = bufferedReader.readLine();
|
||||
if (readLine != null) {
|
||||
if(readLine != null){
|
||||
stringBuffer.append(readLine);
|
||||
} else {
|
||||
bufferedReader.close();
|
||||
@@ -68,7 +68,7 @@ public class Request {
|
||||
}
|
||||
}
|
||||
|
||||
public void onPostExecute(String str) {
|
||||
public void onPostExecute(String str){
|
||||
super.onPostExecute(str);
|
||||
callback.onResponse(str);
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package ru.vtosters.lite.provider;
|
||||
|
||||
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
public final class VKFileProvider extends FileProvider {
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import static ru.vtosters.lite.utils.Globals.getContext;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class TGPref {
|
||||
public class TGPref{
|
||||
private static final SharedPreferences Prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
|
||||
private static final String CNCT_METHOD = "VTGS:CM";
|
||||
@@ -16,55 +16,55 @@ public class TGPref {
|
||||
private static final String TG_PROXYUSER = "VTGS:PUS";
|
||||
private static final String TG_PROXYUSEPASS = "VTGS:PUsePassword";
|
||||
|
||||
public static int getTGConnectMethod() {
|
||||
public static int getTGConnectMethod(){
|
||||
return Integer.parseInt(Prefs.getString(CNCT_METHOD, "0"));
|
||||
}
|
||||
|
||||
public static void setTGConnectMethod(int method) {
|
||||
public static void setTGConnectMethod(int method){
|
||||
Prefs.edit().putString(CNCT_METHOD, String.valueOf(method)).apply();
|
||||
}
|
||||
|
||||
public static String getTGBotKey() {
|
||||
public static String getTGBotKey(){
|
||||
return Prefs.getString(TG_BOTKEY, null);
|
||||
}
|
||||
|
||||
public static void setTGBotKey(String key) {
|
||||
public static void setTGBotKey(String key){
|
||||
Prefs.edit().putString(TG_BOTKEY, key).apply();
|
||||
}
|
||||
|
||||
public static String getTGProxyIP() {
|
||||
public static String getTGProxyIP(){
|
||||
return Prefs.getString(TG_PROXYIP, null);
|
||||
}
|
||||
|
||||
public static void setTGProxyIP(String ip) {
|
||||
public static void setTGProxyIP(String ip){
|
||||
Prefs.edit().putString(TG_PROXYIP, ip).apply();
|
||||
}
|
||||
|
||||
public static int getTGProxyPort() {
|
||||
public static int getTGProxyPort(){
|
||||
return Prefs.getInt(TG_PROXYPORT, 0);
|
||||
}
|
||||
|
||||
public static void setTGProxyPort(int port) {
|
||||
public static void setTGProxyPort(int port){
|
||||
Prefs.edit().putInt(TG_PROXYPORT, port).apply();
|
||||
}
|
||||
|
||||
public static String getTGProxyPass() {
|
||||
public static String getTGProxyPass(){
|
||||
return Prefs.getString(TG_PROXYPASS, "");
|
||||
}
|
||||
|
||||
public static String getTGProxyUser() {
|
||||
public static String getTGProxyUser(){
|
||||
return Prefs.getString(TG_PROXYUSER, "");
|
||||
}
|
||||
|
||||
public static void setTGProxyUserPass(String user, String pass) {
|
||||
public static void setTGProxyUserPass(String user, String pass){
|
||||
Prefs.edit().putString(TG_PROXYUSER, user).putString(TG_PROXYPASS, pass).apply();
|
||||
}
|
||||
|
||||
public static boolean isTGProxyPassEnabled() {
|
||||
public static boolean isTGProxyPassEnabled(){
|
||||
return Prefs.getBoolean(TG_PROXYUSEPASS, false);
|
||||
}
|
||||
|
||||
public static void setTGProxyPassEnabled(boolean en) {
|
||||
public static void setTGProxyPassEnabled(boolean en){
|
||||
Prefs.edit().putBoolean(TG_PROXYUSEPASS, en).apply();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@ import org.json.JSONObject;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public class TGRoot {
|
||||
public class TGRoot{
|
||||
public static final int N = 76820000;
|
||||
public static final int X = 976820000;
|
||||
private final static Stack<Integer> pendingStickers = new Stack<>();
|
||||
private static final String TAG = "TGRoot";
|
||||
|
||||
public static String getSummary() {
|
||||
switch (TGPref.getTGConnectMethod()) {
|
||||
public static String getSummary(){
|
||||
switch(TGPref.getTGConnectMethod()) {
|
||||
case 0:
|
||||
return getString("ctypedirect");
|
||||
case 2:
|
||||
@@ -40,16 +40,16 @@ public class TGRoot {
|
||||
}
|
||||
}
|
||||
|
||||
public static Attachment processSticker(StickerItem item) {
|
||||
public static Attachment processSticker(StickerItem item){
|
||||
int id = item.getId();
|
||||
if (id < N) return null;
|
||||
if(id < N) return null;
|
||||
|
||||
int index = (id - N) / 120;
|
||||
int stickerId = (id - N) % 120;
|
||||
|
||||
TelegramStickersPack pack = null;
|
||||
for (TelegramStickersPack p : TelegramStickersService.getInstance(getContext()).getActivePacksListReference()) {
|
||||
if (p.index == index) {
|
||||
for(TelegramStickersPack p : TelegramStickersService.getInstance(getContext()).getActivePacksListReference()) {
|
||||
if(p.index == index){
|
||||
pack = p;
|
||||
break;
|
||||
}
|
||||
@@ -67,29 +67,29 @@ public class TGRoot {
|
||||
return att;
|
||||
}
|
||||
|
||||
public static void injectStickers(List<StickerStockItem> list) {
|
||||
public static void injectStickers(List<StickerStockItem> list){
|
||||
try {
|
||||
List<TelegramStickersPack> packs = TelegramStickersService.getInstance(getContext()).getActivePacksListReference();
|
||||
for (int i = packs.size() - 1; i >= 0; i--)
|
||||
for(int i = packs.size() - 1; i >= 0; i--)
|
||||
list.add(0, toStickerPack(packs.get(i)));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static StickerStockItem getPackBySticker(int stickerId) {
|
||||
if (stickerId < N) return null;
|
||||
public static StickerStockItem getPackBySticker(int stickerId){
|
||||
if(stickerId < N) return null;
|
||||
int index = (stickerId - N) / 120;
|
||||
|
||||
TelegramStickersPack p = null;
|
||||
for (TelegramStickersPack p_ : TelegramStickersService.getInstance(getContext())
|
||||
for(TelegramStickersPack p_ : TelegramStickersService.getInstance(getContext())
|
||||
.getActivePacksListReference()) {
|
||||
if (p_.index == index) {
|
||||
if(p_.index == index){
|
||||
p = p_;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p == null) return null;
|
||||
if(p == null) return null;
|
||||
|
||||
try {
|
||||
return toStickerPack(p);
|
||||
@@ -99,10 +99,10 @@ public class TGRoot {
|
||||
}
|
||||
}
|
||||
|
||||
private static StickerStockItem toStickerPack(TelegramStickersPack p) throws JSONException {
|
||||
private static StickerStockItem toStickerPack(TelegramStickersPack p) throws JSONException{
|
||||
JSONArray arr = new JSONArray();
|
||||
|
||||
for (int j = 0; j < p.stickersCount; j++)
|
||||
for(int j = 0; j < p.stickersCount; j++)
|
||||
arr.put(new JSONObject().put("sticker_id", N + p.index * 120 + j)
|
||||
.put("images", new JSONArray()
|
||||
.put(new JSONObject()
|
||||
@@ -143,8 +143,8 @@ public class TGRoot {
|
||||
.put("photo_592", photo), X + p.index);
|
||||
}
|
||||
|
||||
public static Attach modifyStickerIM(int i, StickerItem stickerItem, String str) {
|
||||
if (stickerItem.getId() < 76820000) {
|
||||
public static Attach modifyStickerIM(int i, StickerItem stickerItem, String str){
|
||||
if(stickerItem.getId() < 76820000){
|
||||
return AppAttachToImAttachConverter.a.a(i, stickerItem, str);
|
||||
}
|
||||
return AppAttachToImAttachConverter.a.a(processSticker(stickerItem));
|
||||
|
||||
@@ -29,14 +29,14 @@ import java.util.Objects;
|
||||
|
||||
import ru.vtosters.lite.utils.Themes;
|
||||
|
||||
public class PreferencesUtil {
|
||||
public class PreferencesUtil{
|
||||
|
||||
public static Drawable setTint(Context ctx, Drawable d) {
|
||||
public static Drawable setTint(Context ctx, Drawable d){
|
||||
d.setColorFilter(Themes.getAccentColor(), PorterDuff.Mode.SRC_ATOP);
|
||||
return d;
|
||||
}
|
||||
|
||||
public static void addListPreference(MaterialPreferenceToolbarFragment fragment, String key, String def, CharSequence title, CharSequence[] entries, CharSequence[] entriesValue) {
|
||||
public static void addListPreference(MaterialPreferenceToolbarFragment fragment, String key, String def, CharSequence title, CharSequence[] entries, CharSequence[] entriesValue){
|
||||
ListPreference preference = new ListPreference(getContext());
|
||||
preference.setEntries(entries);
|
||||
preference.setEntryValues(entriesValue);
|
||||
@@ -47,7 +47,7 @@ public class PreferencesUtil {
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addListPreferenceIcon(MaterialPreferenceToolbarFragment fragment, String key, String def, CharSequence title, String icon, CharSequence summary, CharSequence[] entries, CharSequence[] entriesValue) {
|
||||
public static void addListPreferenceIcon(MaterialPreferenceToolbarFragment fragment, String key, String def, CharSequence title, String icon, CharSequence summary, CharSequence[] entries, CharSequence[] entriesValue){
|
||||
ListPreference preference = new ListPreference(getContext());
|
||||
preference.setEntries(entries);
|
||||
preference.setEntryValues(entriesValue);
|
||||
@@ -56,12 +56,12 @@ public class PreferencesUtil {
|
||||
preference.setDialogTitle(title); // setDialogTitle
|
||||
preference.setKey(key); // setKey
|
||||
preference.setDefaultValue(def); // setDefaultValue
|
||||
if (icon != null)
|
||||
if(icon != null)
|
||||
preference.setIcon(setTint(getContext(), getDrawable(getContext(), icon))); // preference.setIcon
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addMaterialSwitchPreference(MaterialPreferenceToolbarFragment materialPreferenceToolbarFragment, String key, CharSequence title, CharSequence summary, boolean defValue) {
|
||||
public static void addMaterialSwitchPreference(MaterialPreferenceToolbarFragment materialPreferenceToolbarFragment, String key, CharSequence title, CharSequence summary, boolean defValue){
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getContext());
|
||||
materialSwitchPreference.setTitle(title); // setTitle
|
||||
materialSwitchPreference.setSummary(summary); // setSummary
|
||||
@@ -71,7 +71,7 @@ public class PreferencesUtil {
|
||||
materialPreferenceToolbarFragment.getPreferenceScreen().addPreference(materialSwitchPreference); // materialPreferenceToolbarFragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addMaterialSwitchPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, CharSequence summary, int icon, boolean defValue, Preference.OnPreferenceChangeListener listener) {
|
||||
public static void addMaterialSwitchPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, CharSequence summary, int icon, boolean defValue, Preference.OnPreferenceChangeListener listener){
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getContext());
|
||||
materialSwitchPreference.setTitle(title); // setTitle
|
||||
materialSwitchPreference.setSummary(summary); // setSummary
|
||||
@@ -79,13 +79,13 @@ public class PreferencesUtil {
|
||||
materialSwitchPreference.setDefaultValue(defValue); // setDefaultValue
|
||||
materialSwitchPreference.setOnPreferenceChangeListener(listener); // setOnPreferenceClickListener
|
||||
|
||||
if (icon != 1)
|
||||
if(icon != 1)
|
||||
materialSwitchPreference.setIcon(setTint(getContext(), Objects.requireNonNull(ContextCompat.getDrawable(getContext(), icon)))); // preference.setIcon
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addMaterialSwitchPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, CharSequence summary, String icon, boolean defValue, Preference.OnPreferenceChangeListener listener) {
|
||||
public static void addMaterialSwitchPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, CharSequence summary, String icon, boolean defValue, Preference.OnPreferenceChangeListener listener){
|
||||
MaterialSwitchPreference materialSwitchPreference = new MaterialSwitchPreference(getContext());
|
||||
materialSwitchPreference.setTitle(title); // setTitle
|
||||
materialSwitchPreference.setSummary(summary); // setSummary
|
||||
@@ -93,14 +93,14 @@ public class PreferencesUtil {
|
||||
materialSwitchPreference.setDefaultValue(defValue); // setDefaultValue
|
||||
fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // materialPreferenceToolbarFragment.getPreferenceScreen().addPreference(preference)
|
||||
|
||||
if (icon != null)
|
||||
if(icon != null)
|
||||
materialSwitchPreference.setIcon(setTint(getContext(), getDrawable(getContext(), icon))); // preference.setIcon
|
||||
materialSwitchPreference.setOnPreferenceChangeListener(listener); // setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(materialSwitchPreference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, CharSequence summary) {
|
||||
public static void addPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, CharSequence summary){
|
||||
Preference preference = new Preference(getContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
@@ -109,57 +109,57 @@ public class PreferencesUtil {
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreference(MaterialPreferenceToolbarFragment fragment, CharSequence title, CharSequence summary, @Nullable String icon, Preference.OnPreferenceClickListener listener) {
|
||||
public static void addPreference(MaterialPreferenceToolbarFragment fragment, CharSequence title, CharSequence summary, @Nullable String icon, Preference.OnPreferenceClickListener listener){
|
||||
Preference preference = new Preference(getContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
|
||||
if (icon != null)
|
||||
if(icon != null)
|
||||
preference.setIcon(setTint(getContext(), getDrawable(getContext(), icon))); // preference.setIcon
|
||||
preference.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, CharSequence summary, @Nullable String icon, Preference.OnPreferenceClickListener listener) {
|
||||
public static void addPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, CharSequence summary, @Nullable String icon, Preference.OnPreferenceClickListener listener){
|
||||
Preference preference = new Preference(getContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
|
||||
if (icon != null)
|
||||
if(icon != null)
|
||||
preference.setIcon(setTint(getContext(), getDrawable(getContext(), icon))); // preference.setIcon
|
||||
preference.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreferenceDrawable(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, CharSequence summary, @Nullable Drawable icon, Preference.OnPreferenceClickListener listener) {
|
||||
public static void addPreferenceDrawable(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, CharSequence summary, @Nullable Drawable icon, Preference.OnPreferenceClickListener listener){
|
||||
Preference preference = new Preference(getContext());
|
||||
preference.setSummary(summary); // setSummary
|
||||
preference.setTitle(title); // setTitle
|
||||
preference.setKey(key); // setKey
|
||||
|
||||
if (icon != null)
|
||||
if(icon != null)
|
||||
preference.setIcon(icon); // preference.setIcon
|
||||
preference.setOnPreferenceClickListener(listener); // preference.setOnPreferenceClickListener(listener)
|
||||
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreferenceCategory(MaterialPreferenceToolbarFragment fragment, CharSequence title) {
|
||||
public static void addPreferenceCategory(MaterialPreferenceToolbarFragment fragment, CharSequence title){
|
||||
PreferenceCategory preference = new PreferenceCategory(getContext(), null);
|
||||
preference.setTitle(title); // setTitle
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addPreferenceCategory(MaterialPreferenceToolbarFragment fragment, CharSequence title, int collapsedSize) {
|
||||
public static void addPreferenceCategory(MaterialPreferenceToolbarFragment fragment, CharSequence title, int collapsedSize){
|
||||
PreferenceCategory preference = new PreferenceCategory(getContext(), null);
|
||||
preference.setTitle(title); // setTitle
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static void addEditTextPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, EditTextPrefChangeListener editTextPrefChangeListener) {
|
||||
public static void addEditTextPreference(MaterialPreferenceToolbarFragment fragment, String key, CharSequence title, EditTextPrefChangeListener editTextPrefChangeListener){
|
||||
Preference preference = new Preference(getContext());
|
||||
|
||||
preference.setTitle(title); // setTitle
|
||||
@@ -172,7 +172,7 @@ public class PreferencesUtil {
|
||||
editText.setHint(title);
|
||||
editText.setHintTextColor(PreferencesUtil.getSTextColor(getContext()));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
|
||||
editText.setBackgroundTintList(ColorStateList.valueOf(PreferencesUtil.getTextColor(getContext())));
|
||||
} else {
|
||||
ViewCompat.setBackgroundTintList(editText, ColorStateList.valueOf(PreferencesUtil.getTextColor(getContext())));
|
||||
@@ -188,7 +188,7 @@ public class PreferencesUtil {
|
||||
builder.setView(linearLayout);
|
||||
builder.setPositiveButton("OK", (dialog, which) -> {
|
||||
boolean change = editTextPrefChangeListener.onChanged(preference, editText.getText().toString());
|
||||
if (!change)
|
||||
if(!change)
|
||||
return;
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext())
|
||||
@@ -203,24 +203,24 @@ public class PreferencesUtil {
|
||||
fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference)
|
||||
}
|
||||
|
||||
public static int getTextColor(Context ctx) {
|
||||
public static int getTextColor(Context ctx){
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(Themes.getTextAttr(), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
public static int getSTextColor(Context ctx) {
|
||||
public static int getSTextColor(Context ctx){
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(Themes.getSTextAttr(), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
private static Drawable getDrawable(Context ctx, String name) {
|
||||
private static Drawable getDrawable(Context ctx, String name){
|
||||
var id = ctx.getResources().getIdentifier(name, "drawable", ctx.getPackageName());
|
||||
return ContextCompat.getDrawable(ctx, id);
|
||||
}
|
||||
|
||||
public interface EditTextPrefChangeListener {
|
||||
public interface EditTextPrefChangeListener{
|
||||
boolean onChanged(Preference preference, Object obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class APKInstallActivity extends AppCompatActivity {
|
||||
public class APKInstallActivity extends AppCompatActivity{
|
||||
public static final int REQUEST_INSTALL_PERMISSION = 1;
|
||||
|
||||
public static final String EXTRA_APK_URI = "apk_uri";
|
||||
|
||||
private Uri mApkUri;
|
||||
|
||||
public static void installOta(Context context, Uri apkUri) {
|
||||
public static void installOta(Context context, Uri apkUri){
|
||||
Intent intent = new Intent(context, APKInstallActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
@@ -28,18 +28,18 @@ public class APKInstallActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
public void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent == null) {
|
||||
if(intent == null){
|
||||
Toast.makeText(this, "No intent", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
mApkUri = intent.getParcelableExtra(EXTRA_APK_URI);
|
||||
if (mApkUri == null) {
|
||||
if(mApkUri == null){
|
||||
Toast.makeText(this, "No apk uri", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
return;
|
||||
@@ -48,9 +48,9 @@ public class APKInstallActivity extends AppCompatActivity {
|
||||
installApk();
|
||||
}
|
||||
|
||||
private void installApk() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
if (!getPackageManager().canRequestPackageInstalls()) {
|
||||
private void installApk(){
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
|
||||
if(!getPackageManager().canRequestPackageInstalls()){
|
||||
Intent permIntent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, Uri.parse("package:" + getPackageName()));
|
||||
startActivityForResult(permIntent, REQUEST_INSTALL_PERMISSION);
|
||||
return;
|
||||
@@ -73,10 +73,10 @@ public class APKInstallActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data){
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == REQUEST_INSTALL_PERMISSION)
|
||||
if(requestCode == REQUEST_INSTALL_PERMISSION)
|
||||
installApk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,18 @@ import android.os.PowerManager;
|
||||
|
||||
import ru.vtosters.lite.utils.OEMDetector;
|
||||
|
||||
public class DisableBattery {
|
||||
public static void alert(Activity activity) {
|
||||
if (OEMDetector.isOEM() && Build.VERSION.SDK_INT >= 23 && getBoolValue("showDoze", true)) {
|
||||
public class DisableBattery{
|
||||
public static void alert(Activity activity){
|
||||
if(OEMDetector.isOEM() && Build.VERSION.SDK_INT >= 23 && getBoolValue("showDoze", true)){
|
||||
final Context context = getContext();
|
||||
if (!((PowerManager) context.getSystemService(Context.POWER_SERVICE)).isIgnoringBatteryOptimizations(context.getPackageName())) {
|
||||
if(!((PowerManager) context.getSystemService(Context.POWER_SERVICE)).isIgnoringBatteryOptimizations(context.getPackageName())){
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle(getString("batteryissuetitle"));
|
||||
builder.setMessage(getString("batteryissuesumm"));
|
||||
builder.setCancelable(false);
|
||||
builder.setPositiveButton(getString("batteryissuebtn1"), new DialogInterface.OnClickListener() {
|
||||
builder.setPositiveButton(getString("batteryissuebtn1"), new DialogInterface.OnClickListener(){
|
||||
@Override // android.content.DialogInterface.OnClickListener
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
public void onClick(DialogInterface dialogInterface, int i){
|
||||
Intent intent = new Intent("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("package:");
|
||||
@@ -36,9 +36,9 @@ public class DisableBattery {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
builder.setNeutralButton(getString("batteryissuebtn2"), new DialogInterface.OnClickListener() {
|
||||
builder.setNeutralButton(getString("batteryissuebtn2"), new DialogInterface.OnClickListener(){
|
||||
@Override // android.content.DialogInterface.OnClickListener
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
public void onClick(DialogInterface dialogInterface, int i){
|
||||
edit().putBoolean("showDoze", false).apply();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,31 +16,31 @@ import com.vk.navigation.Navigator;
|
||||
|
||||
import ru.vtosters.lite.ui.fragments.InstallGMSFragment;
|
||||
|
||||
public class InstallGMS {
|
||||
public static void alert(final Activity activity) {
|
||||
if (!isGmsInstalled()) {
|
||||
public class InstallGMS{
|
||||
public static void alert(final Activity activity){
|
||||
if(!isGmsInstalled()){
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle(getString("debug_warning"));
|
||||
builder.setMessage(getString("gmsissuesumm"));
|
||||
builder.setCancelable(false);
|
||||
builder.setPositiveButton(getString("gmsissuebtn1"), new DialogInterface.OnClickListener() {
|
||||
builder.setPositiveButton(getString("gmsissuebtn1"), new DialogInterface.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
public void onClick(DialogInterface dialogInterface, int i){
|
||||
edit().putBoolean("showAlertGms", false).apply();
|
||||
}
|
||||
});
|
||||
builder.setNeutralButton(getString("gmsissuebtn2"), new DialogInterface.OnClickListener() {
|
||||
builder.setNeutralButton(getString("gmsissuebtn2"), new DialogInterface.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
public void onClick(DialogInterface dialogInterface, int i){
|
||||
edit().putBoolean("showAlertGms", false).apply();
|
||||
Context context = getContext();
|
||||
Intent a2 = new Navigator(InstallGMSFragment.class).b(context);
|
||||
context.startActivity(a2);
|
||||
}
|
||||
});
|
||||
if (getBoolValue("showAlertGms", true)) {
|
||||
if(getBoolValue("showAlertGms", true)){
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,25 +8,25 @@ import ru.vtosters.lite.downloaders.OTADownloader;
|
||||
import ru.vtosters.lite.ui.vkui.ModalBottomSheetWrapper;
|
||||
import ru.vtosters.lite.utils.OTAHelper;
|
||||
|
||||
public class OTADialog implements OTAHelper.OTAListener {
|
||||
public class OTADialog implements OTAHelper.OTAListener{
|
||||
|
||||
private Activity mActivity;
|
||||
|
||||
private OTAHelper mHelper;
|
||||
|
||||
public static OTADialog checkUpdates(Activity activity) {
|
||||
return new OTADialog(activity);
|
||||
}
|
||||
|
||||
public OTADialog(Activity activity) {
|
||||
public OTADialog(Activity activity){
|
||||
mActivity = activity;
|
||||
|
||||
mHelper = new OTAHelper(this);
|
||||
mHelper.loadData();
|
||||
}
|
||||
|
||||
public static OTADialog checkUpdates(Activity activity){
|
||||
return new OTADialog(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateApplied() {
|
||||
public void onUpdateApplied(){
|
||||
mActivity.runOnUiThread(() -> {
|
||||
// Toast.makeText(mActivity, "Обновления найдены", Toast.LENGTH_SHORT).show();
|
||||
new ModalBottomSheetWrapper(mActivity)
|
||||
@@ -39,7 +39,7 @@ public class OTADialog implements OTAHelper.OTAListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateCanceled() {
|
||||
public void onUpdateCanceled(){
|
||||
mActivity.runOnUiThread(() -> {
|
||||
// Toast.makeText(mActivity, "Обновлений не найдено", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
|
||||
@@ -13,39 +13,39 @@ import android.os.Build;
|
||||
|
||||
import ru.vtosters.lite.utils.OEMDetector;
|
||||
|
||||
public class Start {
|
||||
public static void alert(final Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
public class Start{
|
||||
public static void alert(final Activity activity){
|
||||
if(Build.VERSION.SDK_INT >= 23){
|
||||
activity.requestPermissions(new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, 228);
|
||||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle(getString("debug_warning"));
|
||||
builder.setMessage(getWelcome());
|
||||
builder.setCancelable(false);
|
||||
builder.setPositiveButton(getString("startbtn2"), new DialogInterface.OnClickListener() {
|
||||
builder.setPositiveButton(getString("startbtn2"), new DialogInterface.OnClickListener(){
|
||||
|
||||
@Override // android.content.DialogInterface.OnClickListener
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
public void onClick(DialogInterface dialogInterface, int i){
|
||||
edit().putBoolean("showAlert", false).apply();
|
||||
}
|
||||
});
|
||||
builder.setNeutralButton(getString("startbtn1"), new DialogInterface.OnClickListener() {
|
||||
builder.setNeutralButton(getString("startbtn1"), new DialogInterface.OnClickListener(){
|
||||
|
||||
@Override // android.content.DialogInterface.OnClickListener
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
public void onClick(DialogInterface dialogInterface, int i){
|
||||
edit().putBoolean("showAlert", false).apply();
|
||||
activity.startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse("https://t.me/vtosters")));
|
||||
}
|
||||
});
|
||||
if (getBoolValue("showAlert", true)) {
|
||||
if(getBoolValue("showAlert", true)){
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getWelcome() {
|
||||
private static String getWelcome(){
|
||||
String Default = getString("startsumm1");
|
||||
|
||||
if (OEMDetector.isOEM()){
|
||||
if(OEMDetector.isOEM()){
|
||||
return Default + getString("startsumm2");
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ import com.vk.navigation.Navigator;
|
||||
|
||||
import ru.vtosters.lite.utils.VKUIwrapper;
|
||||
|
||||
public class VKIDProtection {
|
||||
public static void alert(final Activity activity) {
|
||||
public class VKIDProtection{
|
||||
public static void alert(final Activity activity){
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle(getString("debug_warning"));
|
||||
builder.setMessage(getString("vkidsumm"));
|
||||
@@ -27,7 +27,7 @@ public class VKIDProtection {
|
||||
Intent a2 = new Navigator(VKUIwrapper.class).b(activity);
|
||||
activity.startActivity(a2);
|
||||
});
|
||||
if (getBoolValue("showAlertVkId", true)) {
|
||||
if(getBoolValue("showAlertVkId", true)){
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@ import static ru.vtosters.lite.utils.Globals.getIdentifier;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
public class ActivityFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class ActivityFragment extends MaterialPreferenceToolbarFragment{
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(getIdentifier("preferences_activity", "xml"));
|
||||
}
|
||||
|
||||
@@ -10,27 +10,26 @@ import androidx.preference.Preference;
|
||||
|
||||
import com.vk.navigation.Navigator;
|
||||
import com.vk.newsfeed.NewsfeedSettingsFragment;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
public class openofficialsett implements Preference.OnPreferenceClickListener {
|
||||
openofficialsett() {
|
||||
public class openofficialsett implements Preference.OnPreferenceClickListener{
|
||||
openofficialsett(){
|
||||
}
|
||||
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
Context context = getContext();
|
||||
Intent a2 = new Navigator(NewsfeedSettingsFragment.class).b(context);
|
||||
context.startActivity(a2);
|
||||
|
||||
@@ -4,12 +4,11 @@ import static ru.vtosters.lite.utils.Globals.getIdentifier;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
public class InstallGMSFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class InstallGMSFragment extends MaterialPreferenceToolbarFragment{
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(getIdentifier("preferences_gms", "xml"));
|
||||
}
|
||||
|
||||
@@ -7,18 +7,17 @@ import android.os.Bundle;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
public class InterfaceFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class InterfaceFragment extends MaterialPreferenceToolbarFragment{
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(getIdentifier("preferences_interface", "xml"));
|
||||
prefs();
|
||||
}
|
||||
|
||||
private void prefs() {
|
||||
private void prefs(){
|
||||
findPreference("newfeed").setOnPreferenceClickListener(new restart());
|
||||
findPreference("dateformat").setOnPreferenceClickListener(new restart());
|
||||
findPreference("stories").setOnPreferenceClickListener(new restart());
|
||||
@@ -26,17 +25,17 @@ public class InterfaceFragment extends MaterialPreferenceToolbarFragment {
|
||||
findPreference("dockcounter").setOnPreferenceClickListener(new restart());
|
||||
}
|
||||
|
||||
public boolean restart(Preference preference) {
|
||||
public boolean restart(Preference preference){
|
||||
restartApplicationWithTimer();
|
||||
return true;
|
||||
}
|
||||
|
||||
public class restart implements Preference.OnPreferenceClickListener {
|
||||
restart() {
|
||||
public class restart implements Preference.OnPreferenceClickListener{
|
||||
restart(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
return InterfaceFragment.this.restart(preference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,18 +10,17 @@ import android.os.Bundle;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class MessagesFragment extends MaterialPreferenceToolbarFragment{
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(getIdentifier("preferences_messages", "xml"));
|
||||
prefs();
|
||||
}
|
||||
|
||||
private void prefs() {
|
||||
private void prefs(){
|
||||
findPreference("vkme").setOnPreferenceClickListener(new MessagesFragment.restart());
|
||||
findPreference("vkme_notifs").setOnPreferenceClickListener(new MessagesFragment.restart());
|
||||
findPreference("isBGStickersEnabled").setOnPreferenceClickListener(new MessagesFragment.clearCache());
|
||||
@@ -29,22 +28,12 @@ public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
findPreference("systememoji").setOnPreferenceClickListener(new MessagesFragment.restart());
|
||||
}
|
||||
|
||||
public boolean restart(Preference preference) {
|
||||
public boolean restart(Preference preference){
|
||||
restartApplicationWithTimer();
|
||||
return true;
|
||||
}
|
||||
|
||||
public class restart implements Preference.OnPreferenceClickListener {
|
||||
restart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
return MessagesFragment.this.restart(preference);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean clearCache(Preference preference, Object obj) {
|
||||
public boolean clearCache(Preference preference, Object obj){
|
||||
SharedPreferences prefs = getContext().getSharedPreferences("stickers", Context.MODE_PRIVATE);
|
||||
SharedPreferences prefs2 = getContext().getSharedPreferences("stickers_storage", Context.MODE_PRIVATE);
|
||||
prefs.edit().clear().commit();
|
||||
@@ -54,12 +43,22 @@ public class MessagesFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
|
||||
public class clearCache implements Preference.OnPreferenceClickListener {
|
||||
clearCache() {
|
||||
public class restart implements Preference.OnPreferenceClickListener{
|
||||
restart(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
return MessagesFragment.this.restart(preference);
|
||||
}
|
||||
}
|
||||
|
||||
public class clearCache implements Preference.OnPreferenceClickListener{
|
||||
clearCache(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
return MessagesFragment.this.restart(preference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@ import static ru.vtosters.lite.utils.Globals.getIdentifier;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
public class MusicFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class MusicFragment extends MaterialPreferenceToolbarFragment{
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(getIdentifier("preferences_music", "xml"));
|
||||
}
|
||||
|
||||
@@ -32,16 +32,16 @@ import com.vtosters.lite.im.ImEngineProvider;
|
||||
import b.h.g.m.FileUtils;
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
|
||||
public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class OtherFragment extends MaterialPreferenceToolbarFragment{
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(getIdentifier("preferences_other", "xml"));
|
||||
prefs();
|
||||
}
|
||||
|
||||
private void prefs() {
|
||||
private void prefs(){
|
||||
findPreference("firebasefix").setOnPreferenceClickListener(new a());
|
||||
findPreference("applicationstop").setOnPreferenceClickListener(new b());
|
||||
findPreference("tokencopy").setOnPreferenceClickListener(new c());
|
||||
@@ -54,29 +54,40 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
// a("restoreprefs").a((Preference.c) new restoreprefs());
|
||||
}
|
||||
|
||||
class c implements Preference.OnPreferenceClickListener {
|
||||
c() {
|
||||
public static class d implements Preference.OnPreferenceClickListener{
|
||||
d(){
|
||||
}
|
||||
|
||||
public void copy(Context context, String str) {
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
restartApplication();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class c implements Preference.OnPreferenceClickListener{
|
||||
c(){
|
||||
}
|
||||
|
||||
public void copy(Context context, String str){
|
||||
((ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("MBH-ST", str));
|
||||
makeText(context, Globals.getString("copybtn"), LENGTH_SHORT).show();
|
||||
ToastUtils.a(Globals.getString("tokenwarning"));
|
||||
}
|
||||
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
copy(getContext(), getUserToken());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class e implements Preference.OnPreferenceClickListener {
|
||||
e() {
|
||||
public class e implements Preference.OnPreferenceClickListener{
|
||||
e(){
|
||||
}
|
||||
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
SharedPreferences prefs = getContext().getSharedPreferences("stickers", Context.MODE_PRIVATE);
|
||||
SharedPreferences prefs2 = getContext().getSharedPreferences("stickers_storage", Context.MODE_PRIVATE);
|
||||
prefs.edit().clear().commit();
|
||||
@@ -93,34 +104,23 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
}
|
||||
|
||||
public class b implements Preference.OnPreferenceClickListener {
|
||||
b() {
|
||||
public class b implements Preference.OnPreferenceClickListener{
|
||||
b(){
|
||||
}
|
||||
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
System.exit(0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class d implements Preference.OnPreferenceClickListener {
|
||||
d() {
|
||||
public class a implements Preference.OnPreferenceClickListener{
|
||||
a(){
|
||||
}
|
||||
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
restartApplication();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class a implements Preference.OnPreferenceClickListener {
|
||||
a() {
|
||||
}
|
||||
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
VKAccount b = VKAccountManager.d();
|
||||
PushSubscriber.e.a();
|
||||
ToastUtils.a(Globals.getString("fcmtokenrem"));
|
||||
@@ -134,12 +134,12 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
}
|
||||
|
||||
public class f implements Preference.OnPreferenceClickListener {
|
||||
f() {
|
||||
public class f implements Preference.OnPreferenceClickListener{
|
||||
f(){
|
||||
}
|
||||
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
SharedPreferences prefs = getContext().getSharedPreferences("stickers", Context.MODE_PRIVATE);
|
||||
SharedPreferences prefs2 = getContext().getSharedPreferences("stickers_storage", Context.MODE_PRIVATE);
|
||||
prefs.edit().clear().commit();
|
||||
@@ -150,35 +150,35 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
}
|
||||
|
||||
public class deleteprefs implements Preference.OnPreferenceClickListener {
|
||||
deleteprefs() {
|
||||
public class deleteprefs implements Preference.OnPreferenceClickListener{
|
||||
deleteprefs(){
|
||||
}
|
||||
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
deletePrefs();
|
||||
restartApplication();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class saveprefs implements Preference.OnPreferenceClickListener {
|
||||
saveprefs() {
|
||||
public class saveprefs implements Preference.OnPreferenceClickListener{
|
||||
saveprefs(){
|
||||
}
|
||||
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
backupSettings();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class restoreprefs implements Preference.OnPreferenceClickListener {
|
||||
restoreprefs() {
|
||||
public class restoreprefs implements Preference.OnPreferenceClickListener{
|
||||
restoreprefs(){
|
||||
}
|
||||
|
||||
@Override // android.support.v7.preference.Preference.c
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
restoreBackup();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@ import static ru.vtosters.lite.utils.Globals.getIdentifier;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
public class ProxySettingsFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class ProxySettingsFragment extends MaterialPreferenceToolbarFragment{
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(getIdentifier("preferences_proxy", "xml"));
|
||||
}
|
||||
|
||||
@@ -9,23 +9,22 @@ import android.os.Bundle;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.vk.core.util.ToastUtils;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
|
||||
|
||||
public class ThemesFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class ThemesFragment extends MaterialPreferenceToolbarFragment{
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
addPreferencesFromResource(getIdentifier("preferences_themes", "xml"));
|
||||
prefs();
|
||||
}
|
||||
|
||||
public boolean apply(Preference preference, Object obj) {
|
||||
if ((Boolean) obj) {
|
||||
public boolean apply(Preference preference, Object obj){
|
||||
if((Boolean) obj){
|
||||
componentSwitcher("VTIconDefault", false);
|
||||
componentSwitcher("VTIconVK", true);
|
||||
} else {
|
||||
@@ -37,24 +36,24 @@ public class ThemesFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void prefs() {
|
||||
private void prefs(){
|
||||
findPreference("iconvk").setOnPreferenceChangeListener(new a());
|
||||
findPreference("darktheme").setOnPreferenceClickListener(new restart());
|
||||
findPreference("lighttheme").setOnPreferenceClickListener(new restart());
|
||||
findPreference("navbar").setOnPreferenceClickListener(new restart());
|
||||
}
|
||||
|
||||
public static class restart implements Preference.OnPreferenceClickListener {
|
||||
public static class restart implements Preference.OnPreferenceClickListener{
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
public boolean onPreferenceClick(Preference preference){
|
||||
restartApplicationWithTimer();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class a implements Preference.OnPreferenceChangeListener {
|
||||
public class a implements Preference.OnPreferenceChangeListener{
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object obj) {
|
||||
public boolean onPreferenceChange(Preference preference, Object obj){
|
||||
return ThemesFragment.this.apply(preference, obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,10 +60,45 @@ import ru.vtosters.lite.utils.Globals;
|
||||
import ru.vtosters.lite.utils.SSFS;
|
||||
import ru.vtosters.lite.utils.VKUIwrapper;
|
||||
|
||||
public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
public class VTSettings extends MaterialPreferenceToolbarFragment{
|
||||
|
||||
public static String getValAsString(String stringid, Boolean value){
|
||||
if(disableSettingsSumms()) return "";
|
||||
|
||||
if(value){
|
||||
return Globals.getString(stringid) + ": " + Globals.getString("vtlsettenabled");
|
||||
}
|
||||
|
||||
return Globals.getString(stringid) + ": " + Globals.getString("vtlsettdisabled");
|
||||
}
|
||||
|
||||
public static String getSSFSsumm(){
|
||||
if(disableSettingsSumms()) return "";
|
||||
|
||||
if(hasSpecialVerif())
|
||||
return Globals.getString("vtlssfssumm") + ": " + Globals.getString("vtlsettverifyes");
|
||||
|
||||
return Globals.getString("vtlssfssumm") + ": " + Globals.getString("vtlsettverifno");
|
||||
}
|
||||
|
||||
public static String getDocksumm(){
|
||||
if(disableSettingsSumms()) return "";
|
||||
|
||||
return Globals.getString("vtldocksumm") + ": " + DockBarManager.getInstance().getTabCount();
|
||||
}
|
||||
|
||||
public static String getTGSsumm(){
|
||||
if(disableSettingsSumms()) return "";
|
||||
|
||||
return Globals.getString("vtltgssumm") + ": " + TelegramStickersService.getInstance(Globals.getContext()).getPacksListReference().size();
|
||||
}
|
||||
|
||||
public static SharedPreferences getCurrentAccount(){
|
||||
return Globals.getContext().getSharedPreferences("pref_account_manager", Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
|
||||
String feedsumm = getValAsString("vtlfeedsumm", ads());
|
||||
@@ -82,7 +117,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
int vtosterXml = getIdentifier("empty", "xml");
|
||||
this.addPreferencesFromResource(vtosterXml);
|
||||
|
||||
PreferencesUtil.addPreferenceDrawable(this, "", "Аккаунты", getUsername() + (hasVerification()? Globals.getString("thanksfordonate") : Globals.getString("getdonate")), drawableFromUrl(getUserPhoto()), preference -> {
|
||||
PreferencesUtil.addPreferenceDrawable(this, "", "Аккаунты", getUsername() + (hasVerification() ? Globals.getString("thanksfordonate") : Globals.getString("getdonate")), drawableFromUrl(getUserPhoto()), preference -> {
|
||||
AuthBridge.logout();
|
||||
restartApplication();
|
||||
return false;
|
||||
@@ -90,7 +125,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
|
||||
PreferencesUtil.addPreferenceCategory(this, Globals.getString("vtsettdarktheme"));
|
||||
|
||||
PreferencesUtil.addMaterialSwitchPreference(this, "isdark", Globals.getString("vtsettdarktheme"), "", oldicons() ? "ic_palette_24" : "ic_palette_outline_28", false, (preference, o) -> {
|
||||
PreferencesUtil.addMaterialSwitchPreference(this, "isdark", Globals.getString("vtsettdarktheme"), "", oldicons() ? "ic_palette_24" : "ic_palette_outline_28", false, (preference, o) -> {
|
||||
boolean value = (boolean) o;
|
||||
|
||||
if(!value){ // inverted
|
||||
@@ -103,7 +138,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 28 && false) { // TODO refactoring systen theme
|
||||
if(Build.VERSION.SDK_INT >= 28 && false){ // TODO refactoring systen theme
|
||||
PreferencesUtil.addMaterialSwitchPreference(this, "systemtheme", Globals.getString("appearance_theme_use_system"), Globals.getString("appearance_theme_use_system_summary"), oldicons() ? "ic_recent_24" : "ic_recent_outline_28", true, (preference, o) -> {
|
||||
boolean value = (boolean) o;
|
||||
|
||||
@@ -112,7 +147,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
});
|
||||
}
|
||||
|
||||
if (!isGmsInstalled()) {
|
||||
if(!isGmsInstalled()){
|
||||
PreferencesUtil.addPreference(this, "", Globals.getString("installgms"), "", "ic_alert", preference -> {
|
||||
Context context = getContext();
|
||||
Intent a2 = new Navigator(InstallGMSFragment.class).b(context);
|
||||
@@ -201,7 +236,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
return false;
|
||||
});
|
||||
|
||||
if (VKAccountManager.d().isMusicSubs()) {
|
||||
if(VKAccountManager.d().isMusicSubs()){
|
||||
PreferencesUtil.addPreference(this, "", Globals.getString("subscription_music"), "", oldicons() ? "ic_music_24" : "ic_music_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Intent a2 = new Navigator(MusicSubscriptionControlFragment.class).b(context);
|
||||
@@ -217,9 +252,9 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
return false;
|
||||
});
|
||||
|
||||
PreferencesUtil.addPreferenceCategory(this, Globals.getString("vtsettmod"));
|
||||
PreferencesUtil.addPreferenceCategory(this, Globals.getString("vtsettmod"));
|
||||
|
||||
if (!vkme()) {
|
||||
if(!vkme()){
|
||||
PreferencesUtil.addPreference(this, "", Globals.getString("vtlfeed"), feedsumm, oldicons() ? "ic_newsfeed_24" : "ic_newsfeed_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Intent a2 = new Navigator(FeedFragment.class).b(context);
|
||||
@@ -234,7 +269,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
return false;
|
||||
});
|
||||
|
||||
if (isValidSignature())
|
||||
if(isValidSignature())
|
||||
PreferencesUtil.addPreference(this, "", Globals.getString("vtlmusic"), musicsumm, oldicons() ? "ic_music_24" : "ic_music_outline_28", preference -> {
|
||||
Context context = getContext();
|
||||
Intent a2 = new Navigator(MusicFragment.class).b(context);
|
||||
@@ -325,7 +360,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
return false;
|
||||
});
|
||||
|
||||
if (isValidSignature()) {
|
||||
if(isValidSignature()){
|
||||
PreferencesUtil.addPreferenceCategory(this, Globals.getString("updates"));
|
||||
|
||||
PreferencesUtil.addPreference(this, "", Globals.getString("checkforupdates"), "", "ic_download_24", preference -> {
|
||||
@@ -344,47 +379,12 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
public void onResume(){
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
public static String getValAsString(String stringid, Boolean value) {
|
||||
if(disableSettingsSumms()) return "";
|
||||
|
||||
if (value){
|
||||
return Globals.getString(stringid) + ": " + Globals.getString("vtlsettenabled");
|
||||
}
|
||||
|
||||
return Globals.getString(stringid) + ": " + Globals.getString("vtlsettdisabled");
|
||||
}
|
||||
|
||||
public static String getSSFSsumm() {
|
||||
if(disableSettingsSumms()) return "";
|
||||
|
||||
if(hasSpecialVerif()) return Globals.getString("vtlssfssumm") + ": " + Globals.getString("vtlsettverifyes");
|
||||
|
||||
return Globals.getString("vtlssfssumm") + ": " + Globals.getString("vtlsettverifno");
|
||||
}
|
||||
|
||||
public static String getDocksumm() {
|
||||
if(disableSettingsSumms()) return "";
|
||||
|
||||
return Globals.getString("vtldocksumm") + ": " + DockBarManager.getInstance().getTabCount();
|
||||
}
|
||||
|
||||
public static String getTGSsumm() {
|
||||
if(disableSettingsSumms()) return "";
|
||||
|
||||
return Globals.getString("vtltgssumm") + ": " + TelegramStickersService.getInstance(Globals.getContext()).getPacksListReference().size();
|
||||
}
|
||||
|
||||
public static SharedPreferences getCurrentAccount() {
|
||||
return Globals.getContext().getSharedPreferences("pref_account_manager", Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
public int T4(){
|
||||
return getIdentifier("notification_settings", "string");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
import ru.vtosters.lite.utils.Themes;
|
||||
|
||||
public class DockBarAdapter extends RecyclerView.Adapter
|
||||
implements IItemTouchHelper {
|
||||
implements IItemTouchHelper{
|
||||
|
||||
public static final int SELECTED_TAB_TYPE = 1;
|
||||
public static final int DISABLED_TAB_TYPE = 2;
|
||||
@@ -30,8 +30,8 @@ public class DockBarAdapter extends RecyclerView.Adapter
|
||||
private final DockBarManager mDockBarManager = DockBarManager.getInstance();
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == GROUP_TITLE_TYPE) {
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
|
||||
if(viewType == GROUP_TITLE_TYPE){
|
||||
return new GroupViewHolder(createGroupTitle());
|
||||
} else {
|
||||
return new DockBarEditViewHolder(createTabItem());
|
||||
@@ -39,12 +39,12 @@ public class DockBarAdapter extends RecyclerView.Adapter
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int i) {
|
||||
public int getItemViewType(int i){
|
||||
return getItemType(i);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private View createTabItem() {
|
||||
private View createTabItem(){
|
||||
LinearLayout container = new LinearLayout(getContext());
|
||||
container.setTag("tab_item_container");
|
||||
container.setGravity(Gravity.CENTER_VERTICAL);
|
||||
@@ -78,7 +78,7 @@ public class DockBarAdapter extends RecyclerView.Adapter
|
||||
return container;
|
||||
}
|
||||
|
||||
private View createGroupTitle() {
|
||||
private View createGroupTitle(){
|
||||
LinearLayout layout = new LinearLayout(getContext());
|
||||
layout.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
|
||||
|
||||
@@ -99,46 +99,46 @@ public class DockBarAdapter extends RecyclerView.Adapter
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof GroupViewHolder) {
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position){
|
||||
if(holder instanceof GroupViewHolder){
|
||||
((GroupViewHolder) holder).bind(mDockBarManager.getGroupTitle(position));
|
||||
} else {
|
||||
int viewType = getItemType(position);
|
||||
if (viewType == SELECTED_TAB_TYPE) {
|
||||
if(viewType == SELECTED_TAB_TYPE){
|
||||
((DockBarEditViewHolder) holder).bind(mDockBarManager.getSelectedTab(position));
|
||||
} else if (viewType == DISABLED_TAB_TYPE) {
|
||||
} else if(viewType == DISABLED_TAB_TYPE){
|
||||
((DockBarEditViewHolder) holder).bind(mDockBarManager.getDisabledTab(position));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
public int getItemCount(){
|
||||
return mDockBarManager.getItemCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemDismiss(int index) {
|
||||
public void onItemDismiss(int index){
|
||||
mDockBarManager.move(this, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemMove(int fromPosition, int toPosition) {
|
||||
public boolean onItemMove(int fromPosition, int toPosition){
|
||||
int fromViewType = getItemType(fromPosition);
|
||||
int toViewType = getItemType(toPosition);
|
||||
|
||||
if (fromPosition < toPosition) {
|
||||
if(fromPosition < toPosition){
|
||||
|
||||
if (fromViewType != toViewType) {
|
||||
if(fromViewType != toViewType){
|
||||
mDockBarManager.swapAndMigrate(this, fromPosition, toPosition);
|
||||
} else {
|
||||
List<DockBarTab> list = fromViewType == SELECTED_TAB_TYPE ? mDockBarManager.getSelectedTabs() : mDockBarManager.getDisabledTabs();
|
||||
mDockBarManager.swap(this, list, fromViewType, fromPosition, toPosition);
|
||||
}
|
||||
|
||||
} else if (toPosition != 0) {
|
||||
} else if(toPosition != 0){
|
||||
|
||||
if (fromViewType != toViewType) {
|
||||
if(fromViewType != toViewType){
|
||||
mDockBarManager.swapAndMigrate(this, fromPosition, toPosition);
|
||||
} else {
|
||||
List<DockBarTab> list = fromViewType == SELECTED_TAB_TYPE ? mDockBarManager.getSelectedTabs() : mDockBarManager.getDisabledTabs();
|
||||
@@ -150,43 +150,43 @@ public class DockBarAdapter extends RecyclerView.Adapter
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getIndexByViewType(int position, int viewType) {
|
||||
public int getIndexByViewType(int position, int viewType){
|
||||
return mDockBarManager.getIndexByViewType(position, viewType);
|
||||
}
|
||||
|
||||
public int getItemType(int position) {
|
||||
public int getItemType(int position){
|
||||
return mDockBarManager.getItemType(position);
|
||||
}
|
||||
|
||||
static class DockBarEditViewHolder extends RecyclerView.ViewHolder {
|
||||
static class DockBarEditViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
private final ImageView mIcon;
|
||||
private final TextView mTitle;
|
||||
|
||||
public DockBarEditViewHolder(View itemView) {
|
||||
public DockBarEditViewHolder(View itemView){
|
||||
super(itemView);
|
||||
|
||||
mIcon = itemView.findViewWithTag("icon");
|
||||
mTitle = itemView.findViewWithTag("title");
|
||||
}
|
||||
|
||||
public void bind(DockBarTab tab) {
|
||||
public void bind(DockBarTab tab){
|
||||
mIcon.setImageResource(tab.iconID);
|
||||
mTitle.setText(tab.titleID);
|
||||
}
|
||||
}
|
||||
|
||||
static class GroupViewHolder extends RecyclerView.ViewHolder {
|
||||
static class GroupViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
private final TextView mGroupTitle;
|
||||
|
||||
public GroupViewHolder(View view) {
|
||||
public GroupViewHolder(View view){
|
||||
super(view);
|
||||
|
||||
mGroupTitle = view.findViewWithTag("group_title");
|
||||
}
|
||||
|
||||
public void bind(String groupTitle) {
|
||||
public void bind(String groupTitle){
|
||||
mGroupTitle.setText(groupTitle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
public class DockBarDragItem {
|
||||
public class DockBarDragItem{
|
||||
|
||||
public boolean active;
|
||||
public int index;
|
||||
public DockBarTab dockBarTab;
|
||||
|
||||
public DockBarDragItem(boolean active, int index, DockBarTab dockBarTab) {
|
||||
public DockBarDragItem(boolean active, int index, DockBarTab dockBarTab){
|
||||
this.active = active;
|
||||
this.index = index;
|
||||
this.dockBarTab = dockBarTab;
|
||||
|
||||
@@ -16,20 +16,18 @@ import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vk.core.fragments.FragmentImpl.a;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
import me.grishka.appkit.fragments.ToolbarFragment;
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
|
||||
public class DockBarFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class DockBarFragment extends MaterialPreferenceToolbarFragment{
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
private DockBarAdapter mAdapter;
|
||||
private ItemTouchHelper mItemTouchHelper;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
|
||||
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
|
||||
LinearLayout container = new LinearLayout(getContext());
|
||||
@@ -84,7 +82,7 @@ public class DockBarFragment extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View arg0, Bundle arg1) {
|
||||
public void onViewCreated(View arg0, Bundle arg1){
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
super.onViewCreated(arg0, arg1);
|
||||
|
||||
@@ -28,18 +28,18 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DockBarInjector {
|
||||
public class DockBarInjector{
|
||||
private static final DockBarManager sManager = DockBarManager.getInstance();
|
||||
|
||||
public static Map<Class<? extends FragmentImpl>, Integer> injectMap() {
|
||||
public static Map<Class<? extends FragmentImpl>, Integer> injectMap(){
|
||||
LinkedHashMap<Class<? extends FragmentImpl>, Integer> map = new LinkedHashMap<>();
|
||||
for (DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
for(DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
map.put(tab.fragmentClass, tab.id);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void inject(BottomNavigationView navigationView) {
|
||||
public static void inject(BottomNavigationView navigationView){
|
||||
Menu menu = navigationView.getMenu();
|
||||
menu.clear();
|
||||
try {
|
||||
@@ -52,16 +52,16 @@ public class DockBarInjector {
|
||||
|
||||
Method acquire = synchronisedPoolCls.getDeclaredMethod("a");
|
||||
|
||||
if (synchronizedPool != null) {
|
||||
if(synchronizedPool != null){
|
||||
do {
|
||||
} while (acquire.invoke(synchronizedPool) != null);
|
||||
} while(acquire.invoke(synchronizedPool) != null);
|
||||
}
|
||||
|
||||
} catch (NoSuchFieldException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
for(DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
MenuItem add = menu.add(0, tab.id, 0, tab.titleID);
|
||||
Drawable drawable = getResources().getDrawable(tab.iconID);
|
||||
ColorStateList dockcolors = new ColorStateList(
|
||||
@@ -69,7 +69,7 @@ public class DockBarInjector {
|
||||
new int[]{android.R.attr.state_checked},
|
||||
new int[]{-android.R.attr.state_checked}
|
||||
},
|
||||
new int[] {
|
||||
new int[]{
|
||||
getAccentColor(),
|
||||
Color.parseColor("#ffaaaeb3")
|
||||
}
|
||||
@@ -80,31 +80,31 @@ public class DockBarInjector {
|
||||
}
|
||||
}
|
||||
|
||||
public static int injectId(String tag) {
|
||||
for (DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
if (tag.equals(tab.tag))
|
||||
public static int injectId(String tag){
|
||||
for(DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
if(tag.equals(tab.tag))
|
||||
return tab.id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void injectMenuFragment(Menu menu) {
|
||||
public static void injectMenuFragment(Menu menu){
|
||||
List<MenuItem> menuItems = new ArrayList<>();
|
||||
for (int i = 0; i < menu.size(); i++) {
|
||||
for(int i = 0; i < menu.size(); i++) {
|
||||
menuItems.add(menu.getItem(i));
|
||||
}
|
||||
menu.clear();
|
||||
|
||||
for (DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
if (tab.id != com.vtosters.lite.R.id.tab_menu) {
|
||||
for(DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
if(tab.id != com.vtosters.lite.R.id.tab_menu){
|
||||
int itemId = tab.id;
|
||||
if (tab.id == com.vtosters.lite.R.id.tab_news) {
|
||||
if(tab.id == com.vtosters.lite.R.id.tab_news){
|
||||
itemId = com.vtosters.lite.R.id.menu_newsfeed;
|
||||
} else if (tab.id == com.vtosters.lite.R.id.tab_discover) {
|
||||
} else if(tab.id == com.vtosters.lite.R.id.tab_discover){
|
||||
itemId = com.vtosters.lite.R.id.menu_search;
|
||||
} else if (tab.id == com.vtosters.lite.R.id.tab_feedback) {
|
||||
} else if(tab.id == com.vtosters.lite.R.id.tab_feedback){
|
||||
itemId = com.vtosters.lite.R.id.menu_feedback;
|
||||
} else if (tab.id == com.vtosters.lite.R.id.tab_messages) {
|
||||
} else if(tab.id == com.vtosters.lite.R.id.tab_messages){
|
||||
itemId = com.vtosters.lite.R.id.menu_messages;
|
||||
}
|
||||
|
||||
@@ -114,61 +114,61 @@ public class DockBarInjector {
|
||||
}
|
||||
}
|
||||
|
||||
for (MenuItem menuItem : menuItems) {
|
||||
for(MenuItem menuItem : menuItems) {
|
||||
MenuItem item = menu.add(menuItem.getGroupId(), menuItem.getItemId(), menuItem.getOrder(), menuItem.getTitle());
|
||||
item.setIcon(menuItem.getIcon());
|
||||
}
|
||||
menuItems.clear();
|
||||
|
||||
for (int i = 0; i < menu.size(); i++) {
|
||||
for(int i = 0; i < menu.size(); i++) {
|
||||
MenuItem menuItem = menu.getItem(i);
|
||||
for (DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
for(DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
int itemId = menuItem.getItemId();
|
||||
if (itemId == com.vtosters.lite.R.id.menu_newsfeed) {
|
||||
if(itemId == com.vtosters.lite.R.id.menu_newsfeed){
|
||||
itemId = com.vtosters.lite.R.id.tab_news;
|
||||
} else if (itemId == com.vtosters.lite.R.id.menu_search) {
|
||||
} else if(itemId == com.vtosters.lite.R.id.menu_search){
|
||||
itemId = com.vtosters.lite.R.id.tab_discover;
|
||||
} else if (itemId == com.vtosters.lite.R.id.menu_feedback) {
|
||||
} else if(itemId == com.vtosters.lite.R.id.menu_feedback){
|
||||
itemId = com.vtosters.lite.R.id.tab_feedback;
|
||||
} else if (itemId == com.vtosters.lite.R.id.menu_messages) {
|
||||
} else if(itemId == com.vtosters.lite.R.id.menu_messages){
|
||||
itemId = com.vtosters.lite.R.id.tab_messages;
|
||||
}
|
||||
if (itemId == tab.id && tab.id != com.vtosters.lite.R.id.menu_vk_pay) {
|
||||
if(itemId == tab.id && tab.id != com.vtosters.lite.R.id.menu_vk_pay){
|
||||
menuItems.add(menuItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (MenuItem menuItem : menuItems) {
|
||||
for(MenuItem menuItem : menuItems) {
|
||||
menu.removeItem(menuItem.getItemId());
|
||||
}
|
||||
}
|
||||
|
||||
public static JSONArray injectMenuJSON(JSONArray arr) {
|
||||
public static JSONArray injectMenuJSON(JSONArray arr){
|
||||
List<String> arrayList = new ArrayList(Arrays.asList(
|
||||
"news",
|
||||
"messages",
|
||||
"feedback",
|
||||
"discover"
|
||||
));
|
||||
for (DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
if (tab.id == com.vtosters.lite.R.id.tab_discover) {
|
||||
for(DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
if(tab.id == com.vtosters.lite.R.id.tab_discover){
|
||||
arrayList.remove("discover");
|
||||
} else if (tab.id == com.vtosters.lite.R.id.tab_feedback) {
|
||||
} else if(tab.id == com.vtosters.lite.R.id.tab_feedback){
|
||||
arrayList.remove("feedback");
|
||||
} else if (tab.id == com.vtosters.lite.R.id.tab_messages) {
|
||||
} else if(tab.id == com.vtosters.lite.R.id.tab_messages){
|
||||
arrayList.remove("messages");
|
||||
} else if (tab.id == com.vtosters.lite.R.id.tab_news) {
|
||||
} else if(tab.id == com.vtosters.lite.R.id.tab_news){
|
||||
arrayList.remove("news");
|
||||
}
|
||||
}
|
||||
try {
|
||||
JSONArray jSONArray = new JSONArray();
|
||||
for (int i = 0; i < arrayList.size(); i++) {
|
||||
for(int i = 0; i < arrayList.size(); i++) {
|
||||
jSONArray.put(new JSONObject().put("name", arrayList.get(i)));
|
||||
}
|
||||
for (int i2 = 0; i2 < arr.length(); i2++) {
|
||||
for(int i2 = 0; i2 < arr.length(); i2++) {
|
||||
jSONArray.put(arr.getJSONObject(i2));
|
||||
}
|
||||
return jSONArray;
|
||||
@@ -178,31 +178,31 @@ public class DockBarInjector {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getItemCount() {
|
||||
public static int getItemCount(){
|
||||
return sManager.getSelectedTabs().size();
|
||||
}
|
||||
|
||||
public static boolean isDockOpenAllowed(FragmentImpl fragment) {
|
||||
public static boolean isDockOpenAllowed(FragmentImpl fragment){
|
||||
return isDockOpenAllowed(fragment.getClass());
|
||||
}
|
||||
|
||||
public static boolean isDockOpenAllowed(Class<?> cls) {
|
||||
for (DockBarTab tab : sManager.getSelectedTabs())
|
||||
if (tab.fragmentClass == cls)
|
||||
public static boolean isDockOpenAllowed(Class<?> cls){
|
||||
for(DockBarTab tab : sManager.getSelectedTabs())
|
||||
if(tab.fragmentClass == cls)
|
||||
return true;
|
||||
for (DockBarTab tab : sManager.getDisabledTabs())
|
||||
if (tab.fragmentClass == cls)
|
||||
for(DockBarTab tab : sManager.getDisabledTabs())
|
||||
if(tab.fragmentClass == cls)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Class<?> interceptClick(int id) {
|
||||
for (DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
if (id == tab.id)
|
||||
public static Class<?> interceptClick(int id){
|
||||
for(DockBarTab tab : sManager.getSelectedTabs()) {
|
||||
if(id == tab.id)
|
||||
return tab.fragmentClass;
|
||||
}
|
||||
for (DockBarTab tab : sManager.getDisabledTabs()) {
|
||||
if (id == tab.id)
|
||||
for(DockBarTab tab : sManager.getDisabledTabs()) {
|
||||
if(id == tab.id)
|
||||
return tab.fragmentClass;
|
||||
}
|
||||
return AppsFragment.class;
|
||||
|
||||
@@ -46,7 +46,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class DockBarManager {
|
||||
public class DockBarManager{
|
||||
public static final int MIN_SELECTED_TABS_LIMIT = 3;
|
||||
public static final int MAX_SELECTED_TABS_LIMIT = 9;
|
||||
|
||||
@@ -57,40 +57,42 @@ public class DockBarManager {
|
||||
getString("dockbar_selected_items"),
|
||||
getString("dockbar_unselected_items")
|
||||
);
|
||||
public DockBarManager() {
|
||||
|
||||
public DockBarManager(){
|
||||
load();
|
||||
}
|
||||
|
||||
public static DockBarManager getInstance() {
|
||||
if (sInstance == null)
|
||||
public static DockBarManager getInstance(){
|
||||
if(sInstance == null)
|
||||
sInstance = new DockBarManager();
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private static String readFully(InputStream is) throws IOException {
|
||||
private static String readFully(InputStream is) throws IOException{
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[2048];
|
||||
int len;
|
||||
while ((len = is.read(buffer)) > 0) {
|
||||
while((len = is.read(buffer)) > 0) {
|
||||
bos.write(buffer, 0, len);
|
||||
}
|
||||
return bos.toString();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
private void load(){
|
||||
File dockbar = new File(getContext().getFilesDir(), "dockbar.json");
|
||||
|
||||
if (!dockbar.exists()) {
|
||||
if(vkme()) {
|
||||
if(!dockbar.exists()){
|
||||
if(vkme()){
|
||||
mSelectedTabs.add(new DockBarTab("tab_settings", R.drawable.ic_settings_24, R.string.menu_settings, R.id.menu_settings, useNewSettings()));
|
||||
if(vkme_notifs()) mSelectedTabs.add(new DockBarTab("tab_feedback", oldicons() ? R.drawable.ic_notification_24 : R.drawable.ic_menu_notification_outline_28, R.string.feedback, R.id.tab_feedback, NotificationsContainerFragment.class));
|
||||
if(vkme_notifs())
|
||||
mSelectedTabs.add(new DockBarTab("tab_feedback", oldicons() ? R.drawable.ic_notification_24 : R.drawable.ic_menu_notification_outline_28, R.string.feedback, R.id.tab_feedback, NotificationsContainerFragment.class));
|
||||
mSelectedTabs.add(new DockBarTab("tab_messages", oldicons() ? R.drawable.ic_message_24 : R.drawable.ic_message_outline_24, R.string.messages, R.id.tab_messages, DialogsFragment.class));
|
||||
mSelectedTabs.add(new DockBarTab("tab_profile", R.drawable.libverify_ic_account_circle_white, R.string.profile, R.id.profile, ProfileFragment.class));
|
||||
return;
|
||||
}
|
||||
|
||||
mSelectedTabs.add(new DockBarTab("tab_news", oldicons() ? R.drawable.ic_newsfeed_28 : R.drawable.ic_menu_newsfeed_outline_28, R.string.newsfeed, R.id.tab_news, newfeed() ? HomeFragment.class : NewsfeedFragment.class));
|
||||
mSelectedTabs.add(new DockBarTab("tab_discover", oldicons() ? R.drawable.ic_menu_search_28 : R.drawable.ic_menu_search_outline_28, R.string.search, R.id.tab_discover, DiscoverFragment.class ));
|
||||
mSelectedTabs.add(new DockBarTab("tab_discover", oldicons() ? R.drawable.ic_menu_search_28 : R.drawable.ic_menu_search_outline_28, R.string.search, R.id.tab_discover, DiscoverFragment.class));
|
||||
mSelectedTabs.add(new DockBarTab("tab_messages", oldicons() ? R.drawable.ic_message_24 : R.drawable.ic_message_outline_24, R.string.messages, R.id.tab_messages, DialogsFragment.class));
|
||||
mSelectedTabs.add(new DockBarTab("tab_feedback", oldicons() ? R.drawable.ic_notification_24 : R.drawable.ic_menu_notification_outline_28, R.string.feedback, R.id.tab_feedback, NotificationsContainerFragment.class));
|
||||
mSelectedTabs.add(new DockBarTab("tab_menu", oldicons() ? R.drawable.ic_menu_more_28 : R.drawable.ic_menu_more_outline_28, R.string.menu, R.id.tab_menu, MenuFragment.class));
|
||||
@@ -116,7 +118,7 @@ public class DockBarManager {
|
||||
JSONObject json = new JSONObject(readFully(new FileInputStream(dockbar)));
|
||||
|
||||
JSONArray selected = json.getJSONArray("selected");
|
||||
for (int i = 0; i < selected.length(); i++) {
|
||||
for(int i = 0; i < selected.length(); i++) {
|
||||
JSONObject item = selected.getJSONObject(i);
|
||||
DockBarTab tab = new DockBarTab(
|
||||
item.getString("tag"),
|
||||
@@ -125,16 +127,16 @@ public class DockBarManager {
|
||||
item.getInt("id"),
|
||||
Class.forName(item.getString("fragmentClass"))
|
||||
);
|
||||
if (newfeed()) {
|
||||
if (tab.fragmentClass == NewsfeedFragment.class) {
|
||||
if(newfeed()){
|
||||
if(tab.fragmentClass == NewsfeedFragment.class){
|
||||
tab.fragmentClass = HomeFragment.class;
|
||||
} else if (tab.fragmentClass == DiscoverFragment.class) {
|
||||
} else if(tab.fragmentClass == DiscoverFragment.class){
|
||||
tab.fragmentClass = DiscoverFragment.class;
|
||||
}
|
||||
} else {
|
||||
if (tab.fragmentClass == HomeFragment.class) {
|
||||
if(tab.fragmentClass == HomeFragment.class){
|
||||
tab.fragmentClass = NewsfeedFragment.class;
|
||||
} else if (tab.fragmentClass == DiscoverFragment.class) {
|
||||
} else if(tab.fragmentClass == DiscoverFragment.class){
|
||||
tab.fragmentClass = DiscoverFragment.class;
|
||||
}
|
||||
}
|
||||
@@ -142,7 +144,7 @@ public class DockBarManager {
|
||||
}
|
||||
|
||||
JSONArray disabled = json.getJSONArray("disabled");
|
||||
for (int i = 0; i < disabled.length(); i++) {
|
||||
for(int i = 0; i < disabled.length(); i++) {
|
||||
JSONObject item = disabled.getJSONObject(i);
|
||||
DockBarTab tab = new DockBarTab(
|
||||
item.getString("tag"),
|
||||
@@ -151,16 +153,16 @@ public class DockBarManager {
|
||||
item.getInt("id"),
|
||||
Class.forName(item.getString("fragmentClass"))
|
||||
);
|
||||
if (newfeed()) {
|
||||
if (tab.fragmentClass == NewsfeedFragment.class) {
|
||||
if(newfeed()){
|
||||
if(tab.fragmentClass == NewsfeedFragment.class){
|
||||
tab.fragmentClass = HomeFragment.class;
|
||||
} else if (tab.fragmentClass == DiscoverFragment.class) {
|
||||
} else if(tab.fragmentClass == DiscoverFragment.class){
|
||||
tab.fragmentClass = DiscoverFragment.class;
|
||||
}
|
||||
} else {
|
||||
if (tab.fragmentClass == HomeFragment.class) {
|
||||
if(tab.fragmentClass == HomeFragment.class){
|
||||
tab.fragmentClass = NewsfeedFragment.class;
|
||||
} else if (tab.fragmentClass == DiscoverFragment.class) {
|
||||
} else if(tab.fragmentClass == DiscoverFragment.class){
|
||||
tab.fragmentClass = DiscoverFragment.class;
|
||||
}
|
||||
}
|
||||
@@ -173,17 +175,17 @@ public class DockBarManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
public void delete(){
|
||||
File dockbar = new File(getContext().getFilesDir(), "dockbar.json");
|
||||
if (dockbar.exists()) dockbar.delete();
|
||||
if(dockbar.exists()) dockbar.delete();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
public void save(){
|
||||
try {
|
||||
File dockbar = new File(getContext().getFilesDir(), "dockbar.json");
|
||||
|
||||
JSONArray selected = new JSONArray();
|
||||
for (DockBarTab tab : mSelectedTabs) {
|
||||
for(DockBarTab tab : mSelectedTabs) {
|
||||
|
||||
JSONObject item = new JSONObject()
|
||||
.put("tag", tab.tag)
|
||||
@@ -195,7 +197,7 @@ public class DockBarManager {
|
||||
}
|
||||
|
||||
JSONArray disabled = new JSONArray();
|
||||
for (DockBarTab tab : mDisabledTabs) {
|
||||
for(DockBarTab tab : mDisabledTabs) {
|
||||
JSONObject item = new JSONObject()
|
||||
.put("tag", tab.tag)
|
||||
.put("iconID", tab.iconID)
|
||||
@@ -215,28 +217,28 @@ public class DockBarManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void swap(DockBarAdapter adapter, List<DockBarTab> list, int itemType, int fromPosition, int toPosition) {
|
||||
public void swap(DockBarAdapter adapter, List<DockBarTab> list, int itemType, int fromPosition, int toPosition){
|
||||
int curr = adapter.getIndexByViewType(fromPosition, itemType);
|
||||
int target = adapter.getIndexByViewType(toPosition, itemType);
|
||||
if (fromPosition < toPosition) {
|
||||
for (int i = curr; i < target; i++) {
|
||||
if(fromPosition < toPosition){
|
||||
for(int i = curr; i < target; i++) {
|
||||
Collections.swap(list, i, i + 1);
|
||||
}
|
||||
} else {
|
||||
for (int i = curr; i > target; i--) {
|
||||
for(int i = curr; i > target; i--) {
|
||||
Collections.swap(list, i, i - 1);
|
||||
}
|
||||
}
|
||||
adapter.notifyItemMoved(fromPosition, toPosition);// notifyItemMoved
|
||||
}
|
||||
|
||||
public void swapAndMigrate(DockBarAdapter adapter, int fromPosition, int toPosition) {
|
||||
public void swapAndMigrate(DockBarAdapter adapter, int fromPosition, int toPosition){
|
||||
int curr = adapter.getIndexByViewType(fromPosition, adapter.getItemType(fromPosition));
|
||||
int target = adapter.getIndexByViewType(toPosition, adapter.getItemType(toPosition));
|
||||
if (fromPosition < toPosition) {
|
||||
if(fromPosition < toPosition){
|
||||
|
||||
if(!vkme()){
|
||||
if (mSelectedTabs.size() <= MIN_SELECTED_TABS_LIMIT || mSelectedTabs.get(curr).tag.equals("tab_menu")){
|
||||
if(mSelectedTabs.size() <= MIN_SELECTED_TABS_LIMIT || mSelectedTabs.get(curr).tag.equals("tab_menu")){
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -245,16 +247,16 @@ public class DockBarManager {
|
||||
mSelectedTabs.remove(tab);
|
||||
mDisabledTabs.add(tab);
|
||||
|
||||
for (int i = mDisabledTabs.size() - 1; i > target; i--) {
|
||||
for(int i = mDisabledTabs.size() - 1; i > target; i--) {
|
||||
Collections.swap(mDisabledTabs, i, i - 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < target; i++) {
|
||||
for(int i = 0; i < target; i++) {
|
||||
Collections.swap(mDisabledTabs, i, i + 1);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (mSelectedTabs.size() >= MAX_SELECTED_TABS_LIMIT) return;
|
||||
if(mSelectedTabs.size() >= MAX_SELECTED_TABS_LIMIT) return;
|
||||
|
||||
DockBarTab tab = mDisabledTabs.get(curr);
|
||||
mDisabledTabs.remove(tab);
|
||||
@@ -263,15 +265,15 @@ public class DockBarManager {
|
||||
adapter.notifyItemMoved(fromPosition, toPosition);// notifyItemMoved
|
||||
}
|
||||
|
||||
public void move(DockBarAdapter adapter, int index) {
|
||||
if (getItemType(index) == 1) {
|
||||
public void move(DockBarAdapter adapter, int index){
|
||||
if(getItemType(index) == 1){
|
||||
DockBarTab item = mSelectedTabs.get(getIndexByViewType(index, 1));
|
||||
|
||||
mSelectedTabs.remove(item);
|
||||
|
||||
mDisabledTabs.add(item);
|
||||
|
||||
for (int i = mDisabledTabs.size() - 1; i > 0; i--) {
|
||||
for(int i = mDisabledTabs.size() - 1; i > 0; i--) {
|
||||
Collections.swap(mDisabledTabs, i, i - 1);
|
||||
}
|
||||
|
||||
@@ -280,52 +282,52 @@ public class DockBarManager {
|
||||
}
|
||||
}
|
||||
|
||||
public int getItemCount() {
|
||||
public int getItemCount(){
|
||||
return mSelectedTabs.size() + mDisabledTabs.size() + mGroups.size();
|
||||
}
|
||||
|
||||
public int getIndexByViewType(int position, int viewType) {
|
||||
if (viewType == DockBarAdapter.SELECTED_TAB_TYPE) {
|
||||
public int getIndexByViewType(int position, int viewType){
|
||||
if(viewType == DockBarAdapter.SELECTED_TAB_TYPE){
|
||||
return position - 1;
|
||||
} else if (viewType == DockBarAdapter.DISABLED_TAB_TYPE) {
|
||||
} else if(viewType == DockBarAdapter.DISABLED_TAB_TYPE){
|
||||
return position - mSelectedTabs.size() - mGroups.size();
|
||||
} else {
|
||||
return position != 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getItemType(int position) {
|
||||
if (position == 0 || position == mSelectedTabs.size() + 1) {
|
||||
public int getItemType(int position){
|
||||
if(position == 0 || position == mSelectedTabs.size() + 1){
|
||||
return DockBarAdapter.GROUP_TITLE_TYPE;
|
||||
} else if (position - 1 < mSelectedTabs.size()) {
|
||||
} else if(position - 1 < mSelectedTabs.size()){
|
||||
return DockBarAdapter.SELECTED_TAB_TYPE;
|
||||
} else if (position - 1 >= mSelectedTabs.size()) {
|
||||
} else if(position - 1 >= mSelectedTabs.size()){
|
||||
return DockBarAdapter.DISABLED_TAB_TYPE;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public DockBarTab getSelectedTab(int pos) {
|
||||
public DockBarTab getSelectedTab(int pos){
|
||||
return mSelectedTabs.get(getIndexByViewType(pos, 1));
|
||||
}
|
||||
|
||||
public int getTabCount() {
|
||||
public int getTabCount(){
|
||||
return mSelectedTabs.size();
|
||||
}
|
||||
|
||||
public DockBarTab getDisabledTab(int pos) {
|
||||
public DockBarTab getDisabledTab(int pos){
|
||||
return mDisabledTabs.get(getIndexByViewType(pos, 2));
|
||||
}
|
||||
|
||||
public String getGroupTitle(int pos) {
|
||||
public String getGroupTitle(int pos){
|
||||
return mGroups.get(getIndexByViewType(pos, -1));
|
||||
}
|
||||
|
||||
public List<DockBarTab> getSelectedTabs() {
|
||||
public List<DockBarTab> getSelectedTabs(){
|
||||
return mSelectedTabs;
|
||||
}
|
||||
|
||||
public List<DockBarTab> getDisabledTabs() {
|
||||
public List<DockBarTab> getDisabledTabs(){
|
||||
return mDisabledTabs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
import com.vk.core.fragments.FragmentImpl;
|
||||
|
||||
public class DockBarTab {
|
||||
public class DockBarTab{
|
||||
|
||||
public String tag;
|
||||
public int iconID;
|
||||
@@ -10,7 +10,7 @@ public class DockBarTab {
|
||||
public int id;
|
||||
public Class<? extends FragmentImpl> fragmentClass;
|
||||
|
||||
public DockBarTab(String tag, int iconID, int titleID, int resID, Class<?> fragmentClass) {
|
||||
public DockBarTab(String tag, int iconID, int titleID, int resID, Class<?> fragmentClass){
|
||||
this.tag = tag;
|
||||
this.iconID = iconID;
|
||||
this.titleID = titleID;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
public interface IItemTouchHelper {
|
||||
public interface IItemTouchHelper{
|
||||
|
||||
void onItemDismiss(int index);
|
||||
|
||||
|
||||
+8
-10
@@ -1,31 +1,29 @@
|
||||
package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
import static androidx.recyclerview.widget.ItemTouchHelper.Callback.makeMovementFlags;
|
||||
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
||||
public class ItemTouchHelperCallback extends ItemTouchHelper.Callback {
|
||||
public class ItemTouchHelperCallback extends ItemTouchHelper.Callback{
|
||||
|
||||
private final DockBarAdapter mAdapter;
|
||||
|
||||
public ItemTouchHelperCallback(DockBarAdapter mAdapter) {
|
||||
public ItemTouchHelperCallback(DockBarAdapter mAdapter){
|
||||
this.mAdapter = mAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLongPressDragEnabled() {
|
||||
public boolean isLongPressDragEnabled(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemViewSwipeEnabled() {
|
||||
public boolean isItemViewSwipeEnabled(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder){
|
||||
int pos = mAdapter.getItemType(viewHolder.getAdapterPosition());
|
||||
int dragFlags = pos != DockBarAdapter.GROUP_TITLE_TYPE ? androidx.recyclerview.widget.ItemTouchHelper.UP | androidx.recyclerview.widget.ItemTouchHelper.DOWN : 0;
|
||||
int swipeFlags = pos == 1 ? androidx.recyclerview.widget.ItemTouchHelper.START | androidx.recyclerview.widget.ItemTouchHelper.END : 0;
|
||||
@@ -33,13 +31,13 @@ public class ItemTouchHelperCallback extends ItemTouchHelper.Callback {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction){
|
||||
mAdapter.onItemDismiss(viewHolder.getItemViewType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
|
||||
if (mAdapter.getItemType(viewHolder.getPosition()) == DockBarAdapter.GROUP_TITLE_TYPE)
|
||||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target){
|
||||
if(mAdapter.getItemType(viewHolder.getPosition()) == DockBarAdapter.GROUP_TITLE_TYPE)
|
||||
return false;
|
||||
return mAdapter.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
|
||||
}
|
||||
|
||||
@@ -51,10 +51,10 @@ import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
import java.io.File;
|
||||
|
||||
import ru.vtosters.lite.tgs.TGPref;
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
import ru.vtosters.lite.ui.PreferencesUtil;
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
|
||||
public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class StickersFragment extends MaterialPreferenceToolbarFragment{
|
||||
|
||||
public final static String ACTION_RELOAD = "com.vtosters.lite.action.RELOAD_TGS_LIST";
|
||||
|
||||
@@ -68,13 +68,13 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
@SuppressWarnings("rawtypes")
|
||||
private RecyclerView.Adapter adapter;
|
||||
private boolean movePending = false;
|
||||
private final BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
private final BroadcastReceiver receiver = new BroadcastReceiver(){
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (ACTION_RELOAD.equals(intent.getAction())) {
|
||||
if (adapter != null) {
|
||||
public void onReceive(Context context, Intent intent){
|
||||
if(ACTION_RELOAD.equals(intent.getAction())){
|
||||
if(adapter != null){
|
||||
try {
|
||||
if (movePending) {
|
||||
if(movePending){
|
||||
movePending = false;
|
||||
adapter.notifyItemMoved(from, to);
|
||||
from = -1;
|
||||
@@ -92,19 +92,19 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
private int editPadding;
|
||||
private RecyclerView recycler;
|
||||
|
||||
private void initGrabber() {
|
||||
private void initGrabber(){
|
||||
int method = TGPref.getTGConnectMethod();
|
||||
switch (method) {
|
||||
switch(method) {
|
||||
case TYPE_DIRECT:
|
||||
TelegramStickersGrabber.USE_PROXY = false;
|
||||
grabber.resetProxy();
|
||||
break;
|
||||
case TYPE_SOCKS:
|
||||
if (TGPref.getTGProxyIP() != null) {
|
||||
if(TGPref.getTGProxyIP() != null){
|
||||
TelegramStickersGrabber.USE_PROXY = true;
|
||||
TelegramStickersGrabber.PROXY_IP = TGPref.getTGProxyIP();
|
||||
TelegramStickersGrabber.PROXY_PORT = TGPref.getTGProxyPort();
|
||||
if (TGPref.isTGProxyPassEnabled()) {
|
||||
if(TGPref.isTGProxyPassEnabled()){
|
||||
TelegramStickersGrabber.HAS_PASS = true;
|
||||
TelegramStickersGrabber.PROXY_USER = TGPref.getTGProxyUser();
|
||||
TelegramStickersGrabber.PROXY_PASS = TGPref.getTGProxyPass();
|
||||
@@ -116,30 +116,30 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
TelegramStickersGrabber.updateURLs();
|
||||
}
|
||||
|
||||
private void openMenu(String toast) {
|
||||
if (toast != null) {
|
||||
private void openMenu(String toast){
|
||||
if(toast != null){
|
||||
makeText(getContext(), toast, LENGTH_SHORT).show();
|
||||
}
|
||||
var intent = new Navigator(StickersPreferencesFragment.class, new Bundle()).b(getContext());
|
||||
super.getContext().startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater){
|
||||
super.onCreateOptionsMenu(menu, menuInflater);
|
||||
MenuItem add = menu.add(0, 0, 0, "");
|
||||
add.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
add.setIcon(getResources().getDrawable(getIdentifier("ic_settings_24", "drawable")));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem arg0) {
|
||||
public boolean onOptionsItemSelected(MenuItem arg0){
|
||||
openMenu(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void enterBotKey(Runnable r) {
|
||||
private void enterBotKey(Runnable r){
|
||||
LinearLayout linearLayout = new LinearLayout(getContext());
|
||||
|
||||
final EditText editText = new EditText(getContext());
|
||||
@@ -160,15 +160,15 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
.setView(linearLayout)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
TGPref.setTGBotKey(editText.getText().toString());
|
||||
if (r != null) r.run();
|
||||
if(r != null) r.run();
|
||||
}).setNegativeButton(android.R.string.cancel, null).setNeutralButton(Globals.getString("stickersapi7"), (dialog, which) -> new AlertDialog.Builder(getContext())
|
||||
.setTitle(Globals.getString("stickersapi8"))
|
||||
.setMessage(Globals.getString("stickersapi9") +
|
||||
Globals.getString("stickersapi10")).setPositiveButton(android.R.string.ok, null)
|
||||
.create().show()).create().show();
|
||||
.setTitle(Globals.getString("stickersapi8"))
|
||||
.setMessage(Globals.getString("stickersapi9") +
|
||||
Globals.getString("stickersapi10")).setPositiveButton(android.R.string.ok, null)
|
||||
.create().show()).create().show();
|
||||
}
|
||||
|
||||
private void checkApiKey(final Runnable r) {
|
||||
private void checkApiKey(final Runnable r){
|
||||
grabber.setBotApiKey(TGPref.getTGBotKey());
|
||||
|
||||
var context = getContext();
|
||||
@@ -178,21 +178,21 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
progressDialog.setMessage(Globals.getString("stickersapi1"));
|
||||
progressDialog.show();
|
||||
|
||||
grabber.checkKey(new TelegramStickersGrabber.KeyCheckListener() {
|
||||
grabber.checkKey(new TelegramStickersGrabber.KeyCheckListener(){
|
||||
@Override
|
||||
public void onKeyChecked(boolean ok) {
|
||||
public void onKeyChecked(boolean ok){
|
||||
progressDialog.dismiss();
|
||||
if (!ok) {
|
||||
if(!ok){
|
||||
makeText(context, Globals.getString("stickersapi2"), LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
stickersService.setBotKey(TGPref.getTGBotKey());
|
||||
|
||||
if (r != null) r.run();
|
||||
if(r != null) r.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetError() {
|
||||
public void onNetError(){
|
||||
progressDialog.dismiss();
|
||||
new AlertDialog.Builder(context)
|
||||
.setMessage(Globals.getString("stickersapi3"))
|
||||
@@ -205,7 +205,7 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@NonNull
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
grabber = new TelegramStickersGrabber(TGPref.getTGBotKey());
|
||||
stickersService = TelegramStickersService.getInstance(getContext());
|
||||
@@ -236,14 +236,14 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
return v;
|
||||
}
|
||||
|
||||
private void fabClick() {
|
||||
private void fabClick(){
|
||||
int method = TGPref.getTGConnectMethod();
|
||||
|
||||
Runnable r = () -> {
|
||||
initGrabber();
|
||||
switch (method) {
|
||||
switch(method) {
|
||||
case TYPE_SOCKS:
|
||||
if (TGPref.getTGProxyIP() == null) {
|
||||
if(TGPref.getTGProxyIP() == null){
|
||||
openMenu(Globals.getString("stickersproxy1"));
|
||||
return;
|
||||
}
|
||||
@@ -255,7 +255,7 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
editText.setHintTextColor(PreferencesUtil.getSTextColor(getContext()));
|
||||
|
||||
// Костыль для китката
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
|
||||
editText.setBackgroundTintList(ColorStateList.valueOf(PreferencesUtil.getTextColor(getContext())));
|
||||
} else {
|
||||
ViewCompat.setBackgroundTintList(editText, ColorStateList.valueOf(PreferencesUtil.getTextColor(getContext())));
|
||||
@@ -275,13 +275,13 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
stickersService.requestPackDownload(pack, new File(getContext().getFilesDir(), new File("VT-Stickers", pack).getAbsolutePath()));
|
||||
}).setNeutralButton(android.R.string.cancel, null).create().show();
|
||||
};
|
||||
if (TGPref.getTGBotKey() == null) enterBotKey(() -> checkApiKey(work));
|
||||
if(TGPref.getTGBotKey() == null) enterBotKey(() -> checkApiKey(work));
|
||||
else checkApiKey(work);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
if (method == -1) {
|
||||
if(method == -1){
|
||||
openMenu(Globals.getString("stickersconnection"));
|
||||
} else {
|
||||
r.run();
|
||||
@@ -289,56 +289,56 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
public void onCreate(@Nullable Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
getContext().registerReceiver(receiver, new IntentFilter(ACTION_RELOAD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View arg0, Bundle arg1) {
|
||||
public void onViewCreated(View arg0, Bundle arg1){
|
||||
setMenuVisibility(true);
|
||||
super.onViewCreated(arg0, arg1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
public void onDestroyView(){
|
||||
super.onDestroyView();
|
||||
getContext().unregisterReceiver(receiver);
|
||||
}
|
||||
|
||||
private String parsePack(String pack) {
|
||||
if (pack.startsWith("https://t.me/addstickers/")) {
|
||||
private String parsePack(String pack){
|
||||
if(pack.startsWith("https://t.me/addstickers/")){
|
||||
pack = pack.substring(25);
|
||||
} else if (pack.startsWith("https://telegram.me/addstickers/")) {
|
||||
} else if(pack.startsWith("https://telegram.me/addstickers/")){
|
||||
pack = pack.substring(32);
|
||||
}
|
||||
return pack;
|
||||
}
|
||||
|
||||
public class StickerPackAdapter extends RecyclerView.Adapter<StickerPackAdapter.StickerPackViewHolder> {
|
||||
public class StickerPackAdapter extends RecyclerView.Adapter<StickerPackAdapter.StickerPackViewHolder>{
|
||||
private final String TAG = "StickerPackAdapter";
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public StickerPackViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
public StickerPackViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
|
||||
var view = LayoutInflater.from(parent.getContext()).inflate(getIdentifier("tgs_entry", "layout"), parent, false);
|
||||
return new StickerPackViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
public int getItemViewType(int position){
|
||||
final TelegramStickersPack pack = stickersService.getPacksListReference().get(position);
|
||||
return pack.state == TelegramStickersPack.DOWNLOADED ? 0 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final StickerPackViewHolder holder, int position) {
|
||||
public void onBindViewHolder(@NonNull final StickerPackViewHolder holder, int position){
|
||||
final TelegramStickersPack pack = stickersService.getPacksListReference().get(position);
|
||||
if (pack.state != TelegramStickersPack.DOWNLOADED) return;
|
||||
if(pack.state != TelegramStickersPack.DOWNLOADED) return;
|
||||
File f = new File(pack.folder, "001.png");
|
||||
|
||||
try {
|
||||
if (f.exists()) {
|
||||
if(f.exists()){
|
||||
holder.stickerImage.setImageURI(Uri.parse("file://" + f.getAbsolutePath()));
|
||||
} else {
|
||||
holder.stickerImage.setImageDrawable(getResources().getDrawable(getIdentifier("icon_vk_104", "drawable")));
|
||||
@@ -375,11 +375,11 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
public int getItemCount(){
|
||||
return stickersService.getPacksListReference().size();
|
||||
}
|
||||
|
||||
public class StickerPackViewHolder extends RecyclerView.ViewHolder {
|
||||
public class StickerPackViewHolder extends RecyclerView.ViewHolder{
|
||||
private final SwitchCompat switchCompat;
|
||||
private final ImageView stickerImage;
|
||||
private final ImageView updateButton;
|
||||
@@ -388,7 +388,7 @@ public class StickersFragment extends MaterialPreferenceToolbarFragment {
|
||||
private final TextView count;
|
||||
private final LinearLayout layout;
|
||||
|
||||
StickerPackViewHolder(@NonNull View view) {
|
||||
StickerPackViewHolder(@NonNull View view){
|
||||
super(view);
|
||||
|
||||
switchCompat = view.findViewById(R.id.choose_btn);
|
||||
|
||||
+3
-3
@@ -13,10 +13,10 @@ import ru.vtosters.lite.tgs.TGRoot;
|
||||
import ru.vtosters.lite.ui.PreferencesUtil;
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
|
||||
public class StickersPreferencesFragment extends MaterialPreferenceToolbarFragment {
|
||||
public class StickersPreferencesFragment extends MaterialPreferenceToolbarFragment{
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
public void onCreate(Bundle bundle){
|
||||
super.onCreate(bundle);
|
||||
|
||||
int vtosterXml = getIdentifier("empty", "xml");
|
||||
@@ -84,7 +84,7 @@ public class StickersPreferencesFragment extends MaterialPreferenceToolbarFragme
|
||||
}
|
||||
|
||||
@Override
|
||||
public int T4() {
|
||||
public int T4(){
|
||||
return getIdentifier("vtltgs", "string");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,19 +13,19 @@ import com.vk.core.dialogs.bottomsheet.ModalBottomSheet;
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
import ru.vtosters.lite.utils.Themes;
|
||||
|
||||
public class ModalBottomSheetWrapper {
|
||||
public class ModalBottomSheetWrapper{
|
||||
public final ModalBottomSheet.a builder;
|
||||
|
||||
public ModalBottomSheetWrapper(Activity activity) {
|
||||
public ModalBottomSheetWrapper(Activity activity){
|
||||
builder = new ModalBottomSheet.a(activity);
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setTitle(String title) {
|
||||
public ModalBottomSheetWrapper setTitle(String title){
|
||||
builder.b(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setUpdateInfoView(String version, String changelog) {
|
||||
public ModalBottomSheetWrapper setUpdateInfoView(String version, String changelog){
|
||||
var context = Globals.getContext();
|
||||
var container = new LinearLayout(context);
|
||||
var title = new TextView(context);
|
||||
@@ -54,15 +54,16 @@ public class ModalBottomSheetWrapper {
|
||||
// try to call a true function and you will understand my pain
|
||||
public ModalBottomSheetWrapper setMessage(
|
||||
String text
|
||||
) {
|
||||
builder.a(text, listener -> {});
|
||||
){
|
||||
builder.a(text, listener -> {
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setClickableMessage(
|
||||
String text,
|
||||
Runnable callback
|
||||
) {
|
||||
){
|
||||
builder.a(text, listener -> callback.run());
|
||||
return this;
|
||||
}
|
||||
@@ -70,26 +71,26 @@ public class ModalBottomSheetWrapper {
|
||||
public ModalBottomSheetWrapper setPositiveButton(
|
||||
String text,
|
||||
Runnable callback
|
||||
) {
|
||||
){
|
||||
builder.a(text, kostil -> callback.run());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setSubtitle(String text) {
|
||||
public ModalBottomSheetWrapper setSubtitle(String text){
|
||||
builder.b((CharSequence) text);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModalBottomSheetWrapper setView(View view) {
|
||||
public ModalBottomSheetWrapper setView(View view){
|
||||
builder.a(view);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModalBottomSheet show() {
|
||||
public ModalBottomSheet show(){
|
||||
return builder.a("");
|
||||
}
|
||||
|
||||
public ModalBottomSheet show(boolean isCancellable) {
|
||||
public ModalBottomSheet show(boolean isCancellable){
|
||||
var sheet = builder.a("");
|
||||
sheet.setCancelable(isCancellable);
|
||||
return sheet;
|
||||
|
||||
@@ -16,12 +16,12 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class About {
|
||||
public static void injectAbout(List<Items2> list) {
|
||||
public class About{
|
||||
public static void injectAbout(List<Items2> list){
|
||||
list.clear();
|
||||
list.add(new Items1());
|
||||
|
||||
if (!oldabout()) {
|
||||
if(!oldabout()){
|
||||
list.add(new Items(21, getIdentifier("opencommit", "string")));
|
||||
list.add(new Items(8, getIdentifier("tgchannel", "string")));
|
||||
list.add(new Items(9, getIdentifier("tgchat", "string")));
|
||||
@@ -42,20 +42,21 @@ public class About {
|
||||
list.add(new Items(6, getIdentifier("about_app_data_protect", "string")));
|
||||
list.add(new Items(8, getIdentifier("sett_debug", "string")));
|
||||
}
|
||||
public static String getBuildNumber() {
|
||||
|
||||
public static String getBuildNumber(){
|
||||
return getBuild(getContext(), "version.properties");
|
||||
}
|
||||
|
||||
public static String getCommitLink() {
|
||||
public static String getCommitLink(){
|
||||
return "https://git.maki.su/gdlbo/lite/commit/" + getBuild(getContext(), "version.properties"); // https://github.com/vtosters/lite/commit/ github repo
|
||||
}
|
||||
|
||||
public static String getBuild(Context context, String name) {
|
||||
public static String getBuild(Context context, String name){
|
||||
try {
|
||||
Scanner scanner = new Scanner(context.getAssets().open(name));
|
||||
while (scanner.hasNextLine()) {
|
||||
while(scanner.hasNextLine()) {
|
||||
String line = scanner.findInLine("VERSION_BUILD=.+");
|
||||
if (line != null)
|
||||
if(line != null)
|
||||
return line.replace("VERSION_BUILD=", "");
|
||||
return "0000000";
|
||||
}
|
||||
@@ -65,7 +66,7 @@ public class About {
|
||||
return "0000000";
|
||||
}
|
||||
|
||||
public static String getAppVersion() throws IOException {
|
||||
public static String getAppVersion() throws IOException{
|
||||
return getApplicationName() + " " + VERSIONNAME + " | " + getBuildNumber();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,39 +12,17 @@ import java.text.CharacterIterator;
|
||||
import java.text.StringCharacterIterator;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CacheUtils {
|
||||
public class CacheUtils{
|
||||
private static CacheUtils sInstance = new CacheUtils();
|
||||
public long size = 0;
|
||||
|
||||
public static CacheUtils getInstance() {
|
||||
if (sInstance == null)
|
||||
public static CacheUtils getInstance(){
|
||||
if(sInstance == null)
|
||||
sInstance = new CacheUtils();
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void autoCleaningCache() {
|
||||
size = getDirSize(getContext().getCacheDir());
|
||||
|
||||
if(size >= getSizeForDelete()) {
|
||||
if(dev()) sendToast("Кэш очищен");
|
||||
deleteCache();
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public long getDirSize(File dir){
|
||||
long size = 0;
|
||||
for (File file : Objects.requireNonNull(dir.listFiles())) {
|
||||
if (file != null && file.isDirectory()) {
|
||||
size += getDirSize(file);
|
||||
} else if (file != null && file.isFile()) {
|
||||
size += file.length();
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public static void deleteCache() {
|
||||
public static void deleteCache(){
|
||||
try {
|
||||
File dir = getContext().getCacheDir();
|
||||
deleteDir(dir);
|
||||
@@ -53,17 +31,17 @@ public class CacheUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deleteDir(File dir) {
|
||||
if (dir != null && dir.isDirectory()) {
|
||||
public static boolean deleteDir(File dir){
|
||||
if(dir != null && dir.isDirectory()){
|
||||
String[] children = dir.list();
|
||||
for (int i=0; i < Objects.requireNonNull(children).length; i++) {
|
||||
for(int i = 0; i < Objects.requireNonNull(children).length; i++) {
|
||||
boolean success = deleteDir(new File(dir, children[i]));
|
||||
if (!success) {
|
||||
if(!success){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return dir.delete();
|
||||
} else if(dir!= null && dir.isFile()) {
|
||||
} else if(dir != null && dir.isFile()){
|
||||
return dir.delete();
|
||||
} else {
|
||||
return false;
|
||||
@@ -71,18 +49,40 @@ public class CacheUtils {
|
||||
}
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
public static String humanReadableByteCountBin(long bytes) {
|
||||
public static String humanReadableByteCountBin(long bytes){
|
||||
long absB = bytes == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(bytes);
|
||||
if (absB < 1024) {
|
||||
if(absB < 1024){
|
||||
return bytes + " B";
|
||||
}
|
||||
long value = absB;
|
||||
CharacterIterator ci = new StringCharacterIterator("KMGTPE");
|
||||
for (int i = 40; i >= 0 && absB > 0xfffccccccccccccL >> i; i -= 10) {
|
||||
for(int i = 40; i >= 0 && absB > 0xfffccccccccccccL >> i; i -= 10) {
|
||||
value >>= 10;
|
||||
ci.next();
|
||||
}
|
||||
value *= Long.signum(bytes);
|
||||
return String.format("%.1f %cB", value / 1024.0, ci.current());
|
||||
}
|
||||
|
||||
public void autoCleaningCache(){
|
||||
size = getDirSize(getContext().getCacheDir());
|
||||
|
||||
if(size >= getSizeForDelete()){
|
||||
if(dev()) sendToast("Кэш очищен");
|
||||
deleteCache();
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public long getDirSize(File dir){
|
||||
long size = 0;
|
||||
for(File file : Objects.requireNonNull(dir.listFiles())) {
|
||||
if(file != null && file.isDirectory()){
|
||||
size += getDirSize(file);
|
||||
} else if(file != null && file.isFile()){
|
||||
size += file.length();
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExternalLinkHandler {
|
||||
public class ExternalLinkHandler{
|
||||
private static final String TAG = "ExternalLinkHandler";
|
||||
|
||||
private static final List<String> filters = Arrays.asList(
|
||||
@@ -29,8 +29,8 @@ public class ExternalLinkHandler {
|
||||
);
|
||||
private static final Map<String, String> qualities = new HashMap<>();
|
||||
|
||||
public static boolean parseVideoFile(VideoFile file, Context context) {
|
||||
if (checkYoutubeLink(file)) {
|
||||
public static boolean parseVideoFile(VideoFile file, Context context){
|
||||
if(checkYoutubeLink(file)){
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(file.G));
|
||||
@@ -41,10 +41,10 @@ public class ExternalLinkHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if (!isEnableExternalOpening()) return false;
|
||||
if(!isEnableExternalOpening()) return false;
|
||||
|
||||
if (checkVkVideo(file)) {
|
||||
if (qualities.size() == 1) {
|
||||
if(checkVkVideo(file)){
|
||||
if(qualities.size() == 1){
|
||||
startExternalVideo((String) qualities.values().toArray()[0]);
|
||||
} else {
|
||||
String[] titles = qualities.keySet().toArray(new String[0]);
|
||||
@@ -58,10 +58,10 @@ public class ExternalLinkHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean checkYoutubeLink(VideoFile file) {
|
||||
if (!isEmpty(file.G)) {
|
||||
for (String filter : filters) {
|
||||
if (file.G.contains(filter))
|
||||
private static boolean checkYoutubeLink(VideoFile file){
|
||||
if(!isEmpty(file.G)){
|
||||
for(String filter : filters) {
|
||||
if(file.G.contains(filter))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -69,41 +69,41 @@ public class ExternalLinkHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* this.e = var66.optString("mp4_240", var66.optString("src"));
|
||||
* this.f = var66.optString("mp4_360");
|
||||
* this.g = var66.optString("mp4_480");
|
||||
* this.h = var66.optString("mp4_720");
|
||||
* this.B = var66.optString("mp4_1080");
|
||||
* this.C = var66.optString("mp4_1440");
|
||||
* this.D = var66.optString("mp4_2160");
|
||||
* this.e = var66.optString("mp4_240", var66.optString("src"));
|
||||
* this.f = var66.optString("mp4_360");
|
||||
* this.g = var66.optString("mp4_480");
|
||||
* this.h = var66.optString("mp4_720");
|
||||
* this.B = var66.optString("mp4_1080");
|
||||
* this.C = var66.optString("mp4_1440");
|
||||
* this.D = var66.optString("mp4_2160");
|
||||
*/
|
||||
public static boolean checkVkVideo(VideoFile videoFile) {
|
||||
if (!isEmpty(videoFile.e)) {
|
||||
public static boolean checkVkVideo(VideoFile videoFile){
|
||||
if(!isEmpty(videoFile.e)){
|
||||
qualities.put("240", videoFile.e);
|
||||
}
|
||||
if (!isEmpty(videoFile.f)) {
|
||||
if(!isEmpty(videoFile.f)){
|
||||
qualities.put("360", videoFile.f);
|
||||
}
|
||||
if (!isEmpty(videoFile.g)) {
|
||||
if(!isEmpty(videoFile.g)){
|
||||
qualities.put("480", videoFile.g);
|
||||
}
|
||||
if (!isEmpty(videoFile.h)) {
|
||||
if(!isEmpty(videoFile.h)){
|
||||
qualities.put("720", videoFile.h);
|
||||
}
|
||||
if (!isEmpty(videoFile.B)) {
|
||||
if(!isEmpty(videoFile.B)){
|
||||
qualities.put("1080", videoFile.B);
|
||||
}
|
||||
if (!isEmpty(videoFile.C)) {
|
||||
if(!isEmpty(videoFile.C)){
|
||||
qualities.put("1440", videoFile.C);
|
||||
}
|
||||
if (!isEmpty(videoFile.D)) {
|
||||
if(!isEmpty(videoFile.D)){
|
||||
qualities.put("2160", videoFile.D);
|
||||
}
|
||||
|
||||
return qualities.size() > 0;
|
||||
}
|
||||
|
||||
public static boolean startExternalVideo(String url) {
|
||||
public static boolean startExternalVideo(String url){
|
||||
try {
|
||||
qualities.clear();
|
||||
|
||||
@@ -111,7 +111,7 @@ public class ExternalLinkHandler {
|
||||
Intent intent = new Intent();
|
||||
|
||||
String packageName = getMXPlayerPackageName();
|
||||
if (!isEmpty(packageName)) {
|
||||
if(!isEmpty(packageName)){
|
||||
intent.setPackage(packageName);
|
||||
intent.setDataAndType(uri, "application/mp4");
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
@@ -119,7 +119,7 @@ public class ExternalLinkHandler {
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, "video/mp4");
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
}
|
||||
getContext().startActivity(intent);
|
||||
@@ -130,10 +130,10 @@ public class ExternalLinkHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String getMXPlayerPackageName() {
|
||||
for (ApplicationInfo info : getContext().getPackageManager().getInstalledApplications(0)) {
|
||||
private static String getMXPlayerPackageName(){
|
||||
for(ApplicationInfo info : getContext().getPackageManager().getInstalledApplications(0)) {
|
||||
String packName = info.packageName;
|
||||
if (packName.equals("com.mxtech.videoplayer.ad") || packName.equals("com.mxtech.videoplayer.pro"))
|
||||
if(packName.equals("com.mxtech.videoplayer.ad") || packName.equals("com.mxtech.videoplayer.pro"))
|
||||
return packName;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -7,7 +7,7 @@ import android.content.res.Resources;
|
||||
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
public class FragAnimationKit {
|
||||
public class FragAnimationKit{
|
||||
|
||||
// Q
|
||||
private static final int actOpenEnter = getIdentifier("q_enter", "anim");
|
||||
@@ -21,27 +21,27 @@ public class FragAnimationKit {
|
||||
private static final int SactCloseExit = getIdentifier("legacy_pop_exit", "anim");
|
||||
// System
|
||||
private static final Resources resources = Resources.getSystem();
|
||||
private static final int SSactOpenEnter = resources.getIdentifier("activity_open_enter", "anim","android");
|
||||
private static final int SSactOpenEnter = resources.getIdentifier("activity_open_enter", "anim", "android");
|
||||
private static final int SSactOpenExit = resources.getIdentifier("activity_open_exit", "anim", "android");
|
||||
private static final int SSactCloseEnter = resources.getIdentifier("activity_close_enter", "anim", "android");
|
||||
private static final int SSactCloseExit = resources.getIdentifier("activity_close_exit", "anim", "android");
|
||||
// System [task]
|
||||
private static final int SSTactOpenEnter = resources.getIdentifier("task_open_enter", "anim","android");
|
||||
private static final int SSTactOpenEnter = resources.getIdentifier("task_open_enter", "anim", "android");
|
||||
private static final int SSTactOpenExit = resources.getIdentifier("task_open_exit", "anim", "android");
|
||||
private static final int SSTactCloseEnter = resources.getIdentifier("task_close_enter", "anim", "android");
|
||||
private static final int SSTactCloseExit = resources.getIdentifier("task_close_exit", "anim", "android");
|
||||
|
||||
public static void animateOpen(FragmentTransaction transaction) {
|
||||
public static void animateOpen(FragmentTransaction transaction){
|
||||
setAnimations(transaction);
|
||||
}
|
||||
|
||||
public static void animateClose(FragmentTransaction transaction) {
|
||||
public static void animateClose(FragmentTransaction transaction){
|
||||
setAnimations(transaction);
|
||||
}
|
||||
|
||||
public static void setAnimations(FragmentTransaction transaction) {
|
||||
if (transaction != null && !getPrefsValue("anim_rtrn_type").equals("noanim")) {
|
||||
switch (getPrefsValue("anim_rtrn_type")) {
|
||||
public static void setAnimations(FragmentTransaction transaction){
|
||||
if(transaction != null && !getPrefsValue("anim_rtrn_type").equals("noanim")){
|
||||
switch(getPrefsValue("anim_rtrn_type")) {
|
||||
case "q":
|
||||
transaction.setCustomAnimations(
|
||||
actOpenEnter,
|
||||
|
||||
@@ -59,11 +59,12 @@ import ru.vtosters.lite.ui.dialogs.InstallGMS;
|
||||
import ru.vtosters.lite.ui.dialogs.OTADialog;
|
||||
import ru.vtosters.lite.ui.dialogs.Start;
|
||||
|
||||
public class Globals {
|
||||
public class Globals{
|
||||
private static final List<Activity> activities = new ArrayList<>();
|
||||
|
||||
public static SharedPreferences getDefprefs() {
|
||||
if (preferences == null) preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
public static SharedPreferences getDefprefs(){
|
||||
if(preferences == null)
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
return preferences;
|
||||
}
|
||||
|
||||
@@ -78,67 +79,67 @@ public class Globals {
|
||||
// VKIDProtection.alert(activity);
|
||||
}
|
||||
|
||||
public static void componentSwitcher(String component, Boolean enabled) {
|
||||
public static void componentSwitcher(String component, Boolean enabled){
|
||||
var packageManager = Objects.requireNonNull(getContext()).getPackageManager();
|
||||
packageManager.setComponentEnabledSetting(new ComponentName(getPackageName(), getPackageName() + "." + component), enabled? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||
packageManager.setComponentEnabledSetting(new ComponentName(getPackageName(), getPackageName() + "." + component), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||
} // Component switcher for changing app icon
|
||||
|
||||
public static String getPrefsValue(String pref) {
|
||||
public static String getPrefsValue(String pref){
|
||||
return getPreferences().getString(pref, "");
|
||||
} // Get pref value as string
|
||||
|
||||
public static int getUserId() {
|
||||
public static int getUserId(){
|
||||
return VKAccountManager.d().D0();
|
||||
} // Current UserId
|
||||
|
||||
public static String getUserSecret() {
|
||||
public static String getUserSecret(){
|
||||
return VKAccountManager.d().l0();
|
||||
}
|
||||
|
||||
public static String getUserToken() {
|
||||
public static String getUserToken(){
|
||||
return VKAccountManager.d().b();
|
||||
}
|
||||
|
||||
public static String getUsername() {
|
||||
public static String getUsername(){
|
||||
return VKAccountManager.d().Z();
|
||||
}
|
||||
|
||||
public static String getUserPhoto() {
|
||||
public static String getUserPhoto(){
|
||||
return VKAccountManager.d().d0();
|
||||
}
|
||||
|
||||
public static SharedPreferences.Editor edit() {
|
||||
public static SharedPreferences.Editor edit(){
|
||||
return PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
|
||||
} // Edit SharedPreferences
|
||||
|
||||
public static void reloadMSG() {
|
||||
public static void reloadMSG(){
|
||||
ImEngineProvider.b().a();
|
||||
ImAudioMsgPlayerProvider.b().e(PlayerActionSources.a);
|
||||
ImAudioMsgPlayerProvider.b().d(PlayerActionSources.a);
|
||||
} // Delete and reload msg cache
|
||||
|
||||
public static int getUserID(UserProfile userProfile) {
|
||||
public static int getUserID(UserProfile userProfile){
|
||||
return userProfile.b;
|
||||
} // UserId Profile via userProfile
|
||||
|
||||
public static String getUserFirstName(UserProfile userProfile) {
|
||||
public static String getUserFirstName(UserProfile userProfile){
|
||||
return userProfile.d;
|
||||
}
|
||||
|
||||
public static String getUserLastName(UserProfile userProfile) {
|
||||
public static String getUserLastName(UserProfile userProfile){
|
||||
return userProfile.c;
|
||||
}
|
||||
|
||||
public static int getUserID(ExtendedUserProfile extendedUserProfile) {
|
||||
public static int getUserID(ExtendedUserProfile extendedUserProfile){
|
||||
return getUserID(fromEup(extendedUserProfile));
|
||||
} // UserId Profile via extendedUserProfile
|
||||
|
||||
public static UserProfile fromEup(ExtendedUserProfile extendedUserProfile) {
|
||||
public static UserProfile fromEup(ExtendedUserProfile extendedUserProfile){
|
||||
return extendedUserProfile.a;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Drawable drawableFromUrl(String url) {
|
||||
public static Drawable drawableFromUrl(String url){
|
||||
try {
|
||||
URL aryURI = new URL(url);
|
||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||
@@ -154,15 +155,15 @@ public class Globals {
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap getBitmapClippedCircle(Bitmap bitmap) {
|
||||
public static Bitmap getBitmapClippedCircle(Bitmap bitmap){
|
||||
final int width = bitmap.getWidth();
|
||||
final int height = bitmap.getHeight();
|
||||
final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
|
||||
final Path path = new Path();
|
||||
path.addCircle(
|
||||
(float)(width / 2)
|
||||
, (float)(height / 2)
|
||||
(float) (width / 2)
|
||||
, (float) (height / 2)
|
||||
, (float) Math.min(width, (height / 2))
|
||||
, Path.Direction.CCW);
|
||||
|
||||
@@ -172,7 +173,7 @@ public class Globals {
|
||||
return outputBitmap;
|
||||
}
|
||||
|
||||
public static void restartApplication() {
|
||||
public static void restartApplication(){
|
||||
Context ctx = getContext();
|
||||
PackageManager pm = ctx.getPackageManager();
|
||||
|
||||
@@ -183,16 +184,16 @@ public class Globals {
|
||||
Runtime.getRuntime().exit(0);
|
||||
} // Application restart (works on sdk 29+ too)
|
||||
|
||||
public static void restartApplicationWithTimer() {
|
||||
public static void restartApplicationWithTimer(){
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
handler.postDelayed(new Runnable(){
|
||||
public void run(){
|
||||
restartApplication();
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
public static void restartApplicationInto(Class Class) {
|
||||
public static void restartApplicationInto(Class Class){
|
||||
Context ctx = getContext();
|
||||
PackageManager pm = ctx.getPackageManager();
|
||||
|
||||
@@ -204,7 +205,7 @@ public class Globals {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Context getContext() {
|
||||
public static Context getContext(){
|
||||
try {
|
||||
Class<?> appGlobalsClazz = Class.forName("android.app.AppGlobals");
|
||||
Method getInitialApplication = appGlobalsClazz.getDeclaredMethod("getInitialApplication");
|
||||
@@ -216,7 +217,7 @@ public class Globals {
|
||||
return null;
|
||||
} // Getting the global context through reflection to use context on application initialization
|
||||
|
||||
public static boolean isGmsInstalled() {
|
||||
public static boolean isGmsInstalled(){
|
||||
try {
|
||||
getContext().getPackageManager().getPackageInfo("com.google.android.gms", 0);
|
||||
return true;
|
||||
@@ -225,13 +226,13 @@ public class Globals {
|
||||
}
|
||||
} // Google Market Services check
|
||||
|
||||
public static Resources getResources() {
|
||||
public static Resources getResources(){
|
||||
return getContext().getResources();
|
||||
}
|
||||
|
||||
public static int getIdentifier(String name, String type) {
|
||||
public static int getIdentifier(String name, String type){
|
||||
try {
|
||||
return getResources().getIdentifier(name, type, getContext().getPackageName());
|
||||
return getResources().getIdentifier(name, type, getContext().getPackageName());
|
||||
} catch (Exception e) {
|
||||
Log.d("VTLite", "Not found " + name + "as type " + type);
|
||||
e.printStackTrace();
|
||||
@@ -239,111 +240,113 @@ public class Globals {
|
||||
return 0;
|
||||
} // Get res id
|
||||
|
||||
public static String getString(String resourcename) {
|
||||
public static String getString(String resourcename){
|
||||
return getContext().getString(getIdentifier(resourcename, "string"));
|
||||
} // Get string via getIdentifier
|
||||
|
||||
public static String getStringDate(@StringRes int i, Object... objArr) {
|
||||
public static String getStringDate(@StringRes int i, Object... objArr){
|
||||
return getContext().getString(i, objArr);
|
||||
}
|
||||
|
||||
public static String getPackageName() {
|
||||
public static String getPackageName(){
|
||||
return getContext().getPackageName();
|
||||
}
|
||||
|
||||
public static int convertDpToPixel(float f) {
|
||||
public static int convertDpToPixel(float f){
|
||||
return (int) (f * ((float) getResources().getDisplayMetrics().densityDpi / 160.0f));
|
||||
}
|
||||
|
||||
public static SharedPreferences getPreferences() {
|
||||
public static SharedPreferences getPreferences(){
|
||||
return PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
}
|
||||
|
||||
public static void sendToast(String text) {
|
||||
public static void sendToast(String text){
|
||||
Toast.makeText(getContext(), text, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String str) {
|
||||
public static boolean isEmpty(String str){
|
||||
return str == null || str.isEmpty();
|
||||
}
|
||||
|
||||
public static boolean isNetworkConnected() {
|
||||
public static boolean isNetworkConnected(){
|
||||
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
|
||||
return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
|
||||
} // Network check
|
||||
|
||||
public static void fixGapps() {
|
||||
public static void fixGapps(){
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
if(Build.VERSION.SDK_INT >= 26){
|
||||
NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
boolean hasMusicChannel = false;
|
||||
|
||||
try {
|
||||
if (notificationManager.getNotificationChannel("audio_playback_channel") != null) {
|
||||
if(notificationManager.getNotificationChannel("audio_playback_channel") != null){
|
||||
hasMusicChannel = true;
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
if (!hasMusicChannel) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
if(!hasMusicChannel){
|
||||
notificationManager.createNotificationChannel(new NotificationChannel("audio_playback_channel", getResources().getString(getIdentifier("audio_message_play_error", "string")), NotificationManager.IMPORTANCE_LOW));
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} // Music channels fix
|
||||
|
||||
public static void registerActivities(Application application) {
|
||||
application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
|
||||
public static void registerActivities(Application application){
|
||||
application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks(){
|
||||
@Override // android.app.Application.ActivityLifecycleCallbacks
|
||||
public void onActivityPaused(Activity activity) {
|
||||
public void onActivityPaused(Activity activity){
|
||||
}
|
||||
|
||||
@Override // android.app.Application.ActivityLifecycleCallbacks
|
||||
public void onActivityResumed(Activity activity) {
|
||||
public void onActivityResumed(Activity activity){
|
||||
}
|
||||
|
||||
@Override // android.app.Application.ActivityLifecycleCallbacks
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle bundle){
|
||||
}
|
||||
|
||||
@Override // android.app.Application.ActivityLifecycleCallbacks
|
||||
public void onActivityStarted(Activity activity) {
|
||||
public void onActivityStarted(Activity activity){
|
||||
}
|
||||
|
||||
@Override // android.app.Application.ActivityLifecycleCallbacks
|
||||
public void onActivityStopped(Activity activity) {
|
||||
public void onActivityStopped(Activity activity){
|
||||
}
|
||||
|
||||
@Override // android.app.Application.ActivityLifecycleCallbacks
|
||||
public void onActivityCreated(Activity activity, Bundle bundle) {
|
||||
if (activity instanceof VKActivity) {
|
||||
public void onActivityCreated(Activity activity, Bundle bundle){
|
||||
if(activity instanceof VKActivity){
|
||||
activities.add(activity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.app.Application.ActivityLifecycleCallbacks
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
public void onActivityDestroyed(Activity activity){
|
||||
activities.remove(activity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Activity getCurrentActivity() {
|
||||
if (activities.size() == 0) return null;
|
||||
public static Activity getCurrentActivity(){
|
||||
if(activities.size() == 0) return null;
|
||||
else return activities.get(0);
|
||||
}
|
||||
|
||||
public static String getApplicationName() {
|
||||
public static String getApplicationName(){
|
||||
return getContext().getApplicationInfo().loadLabel(getContext().getPackageManager()).toString();
|
||||
}
|
||||
|
||||
public static Context BaseContextLocale(Context context) {
|
||||
public static Context BaseContextLocale(Context context){
|
||||
Locale locale = new Locale(getLocale());
|
||||
Locale.setDefault(locale);
|
||||
|
||||
var resources = context.getResources();
|
||||
var configuration = resources.getConfiguration();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
if(Build.VERSION.SDK_INT >= 24){
|
||||
configuration.setLocale(locale);
|
||||
configuration.setLayoutDirection(locale);
|
||||
return context.createConfigurationContext(configuration);
|
||||
@@ -358,12 +361,12 @@ public class Globals {
|
||||
return context;
|
||||
} // Language changer and BaseContext injector
|
||||
|
||||
public static float[] getCenterScreenCoords() {
|
||||
public static float[] getCenterScreenCoords(){
|
||||
int width = getResources().getDisplayMetrics().widthPixels;
|
||||
int height = getResources().getDisplayMetrics().heightPixels;
|
||||
|
||||
int centerWidth = width/2;
|
||||
int centerHeight = height/2;
|
||||
return new float[] {centerWidth, centerHeight};
|
||||
int centerWidth = width / 2;
|
||||
int centerHeight = height / 2;
|
||||
return new float[]{centerWidth, centerHeight};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class JsonInjectors {
|
||||
public static JSONObject profileButton() throws JSONException {
|
||||
public class JsonInjectors{
|
||||
public static JSONObject profileButton() throws JSONException{
|
||||
String pic = "https:\\/\\/sun1-18.userapi.com\\/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ\\/5R-DEF37PFs.png";
|
||||
String title = "Помоги проекту донатом и получи бонус!";
|
||||
String link = "https:\\/\\/vk.com\\/vtosters_official";
|
||||
@@ -19,7 +19,7 @@ public class JsonInjectors {
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
public static JSONObject discoverBanner() throws JSONException {
|
||||
public static JSONObject discoverBanner() throws JSONException{
|
||||
String smallimg = "https:\\/\\/sun1-25.userapi.com\\/3D4YtNHjgwoyxav3FksnYRINp_FhWULuDKYdcA\\/zfCUgKMS0O4.png";
|
||||
String background = "https:\\/\\/images.wsj.net\\/im-501403";
|
||||
String title = "Задонать";
|
||||
@@ -30,21 +30,21 @@ public class JsonInjectors {
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
public static JSONObject discoverBannerButton() throws JSONException {
|
||||
public static JSONObject discoverBannerButton() throws JSONException{
|
||||
String link = "vk.com\\/vtosters_official";
|
||||
|
||||
JSONObject jsonObj = new JSONObject("{\"type\":\"open_url\",\"url\":\"" + link + "\",\"target\":\"internal\"}");
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
public static String haveDonateBanner() {
|
||||
public static String haveDonateBanner(){
|
||||
Random random = new Random();
|
||||
int randomshower = random.nextInt(8);
|
||||
|
||||
return hasVerification() || donaterecomm() || randomshower != 1 ? "null" : "info";
|
||||
}
|
||||
|
||||
public static String haveDonateButton() {
|
||||
public static String haveDonateButton(){
|
||||
Random random = new Random();
|
||||
int randomshower = random.nextInt(10);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import static java.lang.Long.MAX_VALUE;
|
||||
import static ru.vtosters.lite.ui.fragments.dockbar.DockBarManager.getInstance;
|
||||
import static ru.vtosters.lite.utils.Globals.getContext;
|
||||
import static ru.vtosters.lite.utils.Globals.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.Globals.sendToast;
|
||||
import static ru.vtosters.lite.utils.Preferences.adsgroup;
|
||||
import static ru.vtosters.lite.utils.Preferences.adsstories;
|
||||
import static ru.vtosters.lite.utils.Preferences.authorsrecomm;
|
||||
@@ -22,7 +21,6 @@ import com.vk.discover.DiscoverFragment;
|
||||
import com.vk.fave.fragments.FaveTabFragment;
|
||||
import com.vk.menu.MenuFragment;
|
||||
import com.vk.music.fragment.MusicFragment;
|
||||
import com.vk.navigation.NavigatorKeys;
|
||||
import com.vk.newsfeed.HomeFragment;
|
||||
import com.vk.newsfeed.NewsfeedFragment;
|
||||
import com.vk.notifications.NotificationsContainerFragment;
|
||||
@@ -38,7 +36,6 @@ import com.vtosters.lite.fragments.y2.VideosFragment;
|
||||
import com.vtosters.lite.general.fragments.GamesFragment;
|
||||
import com.vtosters.lite.general.fragments.PhotosFragment;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -49,18 +46,11 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Newsfeed {
|
||||
public class Newsfeed{
|
||||
public static List<String> mFilters;
|
||||
|
||||
public static boolean isBlockedByFilter(String str){
|
||||
for (String str2 : mFilters) {
|
||||
if(str.toLowerCase().contains(str2.toLowerCase())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setupFilters(){
|
||||
mFilters=new ArrayList();
|
||||
mFilters = new ArrayList();
|
||||
|
||||
getFilter("refsfilter", "Referals.txt");
|
||||
getFilter("shortlinkfilter", "LinkShorter.txt");
|
||||
@@ -78,9 +68,9 @@ public class Newsfeed {
|
||||
public static void getFilter(String boolname, String filename){
|
||||
if(getBoolValue(boolname, true)){
|
||||
try {
|
||||
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(getContext().getAssets().open(filename)));
|
||||
while (true) {
|
||||
String readLine=bufferedReader.readLine();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(getContext().getAssets().open(filename)));
|
||||
while(true) {
|
||||
String readLine = bufferedReader.readLine();
|
||||
if(readLine != null){
|
||||
mFilters.add(readLine);
|
||||
} else {
|
||||
@@ -104,7 +94,7 @@ public class Newsfeed {
|
||||
return false;
|
||||
}
|
||||
optString = obj.optString("filters", "");
|
||||
if(isAds(optString) || isAuthorRecommendations(optString) || isPostRecommendations(optString) || isFriendsRecommendations(optString)) {
|
||||
if(isAds(optString) || isAuthorRecommendations(optString) || isPostRecommendations(optString) || isFriendsRecommendations(optString)){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -118,7 +108,7 @@ public class Newsfeed {
|
||||
}
|
||||
|
||||
private static boolean checkCopyright(JSONObject json) throws JSONException{
|
||||
if(json.opt("copyright") != null) {
|
||||
if(json.opt("copyright") != null){
|
||||
JSONObject copyright = json.getJSONObject("copyright");
|
||||
String copyrightlink = copyright.getString("link");
|
||||
|
||||
@@ -126,10 +116,10 @@ public class Newsfeed {
|
||||
|
||||
// example of response
|
||||
//"copyright": {
|
||||
//"id": 251706814,
|
||||
//"link": "https://vk.com/wall251706814_9016",
|
||||
//"type": "owner",
|
||||
//"name": "Маргарита Буруня"
|
||||
//"id": 251706814,
|
||||
//"link": "https://vk.com/wall251706814_9016",
|
||||
//"type": "owner",
|
||||
//"name": "Маргарита Буруня"
|
||||
//}
|
||||
|
||||
}
|
||||
@@ -153,7 +143,7 @@ public class Newsfeed {
|
||||
}
|
||||
|
||||
public static boolean isBadNew(String text){
|
||||
for (String filter : mFilters) {
|
||||
for(String filter : mFilters) {
|
||||
if(text.toLowerCase().contains(filter.toLowerCase())){
|
||||
return true;
|
||||
}
|
||||
@@ -169,10 +159,10 @@ public class Newsfeed {
|
||||
|
||||
boolean postAds = postsrecomm();
|
||||
return (captionJson.getString("type").equals("explorebait") && postAds) || // Может быть интересно
|
||||
(captionJson.getString("type").equals("shared") && postAds) || // Поделился записью
|
||||
(postJson.getString("type").equals("digest") && postAds) || // Рекомедации
|
||||
(captionJson.getString("type").equals("commented") && postAds) || // Комментирует
|
||||
(captionJson.getString("type").equals("voted") && postAds); // Проголосовал в опросе
|
||||
(captionJson.getString("type").equals("shared") && postAds) || // Поделился записью
|
||||
(postJson.getString("type").equals("digest") && postAds) || // Рекомедации
|
||||
(captionJson.getString("type").equals("commented") && postAds) || // Комментирует
|
||||
(captionJson.getString("type").equals("voted") && postAds); // Проголосовал в опросе
|
||||
|
||||
} catch (JSONException e) {
|
||||
return false;
|
||||
@@ -213,7 +203,7 @@ public class Newsfeed {
|
||||
if(vkme()){
|
||||
return MAX_VALUE;
|
||||
}
|
||||
switch (getPrefsValue("newsupdate")) {
|
||||
switch(getPrefsValue("newsupdate")) {
|
||||
case "no_update":
|
||||
return MAX_VALUE;
|
||||
case "imd_update":
|
||||
@@ -227,7 +217,7 @@ public class Newsfeed {
|
||||
if(vkme()){
|
||||
return DialogsFragment.class;
|
||||
}
|
||||
switch (getPrefsValue("start_values")) {
|
||||
switch(getPrefsValue("start_values")) {
|
||||
case "newsfeed":
|
||||
return newfeed() ? HomeFragment.class : NewsfeedFragment.class;
|
||||
case "messenger":
|
||||
|
||||
@@ -6,36 +6,36 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class OEMDetector {
|
||||
public static boolean isOEM() {
|
||||
public class OEMDetector{
|
||||
public static boolean isOEM(){
|
||||
return isMIUI() || isEMUI() || isFlyme() || isZenUI() || isSamsung() || isVivo();
|
||||
}
|
||||
|
||||
private static boolean isMIUI() {
|
||||
private static boolean isMIUI(){
|
||||
return !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.name"));
|
||||
}
|
||||
|
||||
private static boolean isEMUI() {
|
||||
private static boolean isEMUI(){
|
||||
return !TextUtils.isEmpty(getSystemProperty("ro.build.hw_emui_api_level"));
|
||||
}
|
||||
|
||||
private static boolean isZenUI() {
|
||||
private static boolean isZenUI(){
|
||||
return !TextUtils.isEmpty(getSystemProperty("ro.asus.ui"));
|
||||
}
|
||||
|
||||
private static boolean isVivo() {
|
||||
private static boolean isVivo(){
|
||||
return !TextUtils.isEmpty(getSystemProperty("ro.vivo.os.version")) || !TextUtils.isEmpty(getSystemProperty("ro.vivo.rom")) || !TextUtils.isEmpty(getSystemProperty("ro.vivo.rom.version")) || !TextUtils.isEmpty(getSystemProperty("ro.vivo.build.version.sdk"));
|
||||
}
|
||||
|
||||
private static boolean isSamsung() {
|
||||
private static boolean isSamsung(){
|
||||
return !TextUtils.isEmpty(getSystemProperty("ro.config.knox"));
|
||||
}
|
||||
|
||||
private static boolean isFlyme() {
|
||||
private static boolean isFlyme(){
|
||||
return !TextUtils.isEmpty(getSystemProperty("ro.build.ro.meizu.rom.config")) || !TextUtils.isEmpty(getSystemProperty("persist.sys.static_blur_mode")) || !TextUtils.isEmpty(getSystemProperty("persist.sys.use.flyme.icon"));
|
||||
}
|
||||
|
||||
private static String getSystemProperty(String str) {
|
||||
private static String getSystemProperty(String str){
|
||||
BufferedReader bufferedReader;
|
||||
try {
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("getprop " + str).getInputStream()), 1024);
|
||||
|
||||
@@ -13,36 +13,33 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class OTAHelper {
|
||||
public class OTAHelper{
|
||||
|
||||
private static final String LATEST_RELEASE_URL = "https://api.github.com/repositories/473685743/releases/latest";
|
||||
private static final String LATEST_RELEASE_COMMIT_URL = "https://api.github.com/repositories/473685743/git/ref/tags/%s";
|
||||
|
||||
private OTAListener mListener;
|
||||
|
||||
private final OkHttpClient mClient = new OkHttpClient();
|
||||
|
||||
private OTAListener mListener;
|
||||
private JSONObject mReleaseJson;
|
||||
private JSONObject mCommitJson;
|
||||
|
||||
public OTAHelper(OTAListener listener) {
|
||||
public OTAHelper(OTAListener listener){
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
public void loadData() {
|
||||
public void loadData(){
|
||||
Request release = new Request.a()
|
||||
.a(LATEST_RELEASE_URL)
|
||||
.b().a();
|
||||
|
||||
mClient.a(release).a(new Callback() {
|
||||
mClient.a(release).a(new Callback(){
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
public void a(Call call, IOException e){
|
||||
Log.d("OTAHelper", "Error while getting latest release info: " + e);
|
||||
mListener.onUpdateCanceled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(Call call, Response response) throws IOException {
|
||||
public void a(Call call, Response response) throws IOException{
|
||||
try {
|
||||
setData(response);
|
||||
} catch (JSONException | NullPointerException e) {
|
||||
@@ -53,7 +50,7 @@ public class OTAHelper {
|
||||
});
|
||||
}
|
||||
|
||||
void setData(Response response) throws IOException, JSONException {
|
||||
void setData(Response response) throws IOException, JSONException{
|
||||
mReleaseJson = new JSONObject(response.a().g());
|
||||
|
||||
String tag = mReleaseJson.getString("tag_name");
|
||||
@@ -61,18 +58,18 @@ public class OTAHelper {
|
||||
.a(String.format(LATEST_RELEASE_COMMIT_URL, tag))
|
||||
.b().a();
|
||||
|
||||
mClient.a(commit).a(new Callback() {
|
||||
mClient.a(commit).a(new Callback(){
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
public void a(Call call, IOException e){
|
||||
Log.d("OTAHelper", "Error while getting latest commit info: " + e);
|
||||
mListener.onUpdateCanceled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(Call call, Response response) throws IOException {
|
||||
public void a(Call call, Response response) throws IOException{
|
||||
try {
|
||||
mCommitJson = new JSONObject(response.a().g());
|
||||
if (isNewVersion())
|
||||
if(isNewVersion())
|
||||
mListener.onUpdateApplied();
|
||||
else mListener.onUpdateCanceled();
|
||||
} catch (NullPointerException | JSONException e) {
|
||||
@@ -83,7 +80,7 @@ public class OTAHelper {
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isNewVersion() {
|
||||
public boolean isNewVersion(){
|
||||
try {
|
||||
String commitSHA = mCommitJson.getJSONObject("object").getString("sha");
|
||||
return !commitSHA.startsWith(About.getBuildNumber());
|
||||
@@ -92,7 +89,7 @@ public class OTAHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public String getNewVersionName() {
|
||||
public String getNewVersionName(){
|
||||
try {
|
||||
return mReleaseJson.getString("name");
|
||||
} catch (JSONException e) {
|
||||
@@ -100,7 +97,7 @@ public class OTAHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public String getUpdateDescription() {
|
||||
public String getUpdateDescription(){
|
||||
try {
|
||||
return mReleaseJson.getString("body");
|
||||
} catch (JSONException e) {
|
||||
@@ -108,7 +105,7 @@ public class OTAHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public String getDownloadUrl() {
|
||||
public String getDownloadUrl(){
|
||||
try {
|
||||
return mReleaseJson.getJSONArray("assets")
|
||||
.getJSONObject(0)
|
||||
@@ -118,7 +115,7 @@ public class OTAHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public interface OTAListener {
|
||||
public interface OTAListener{
|
||||
|
||||
void onUpdateApplied();
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.vk.medianative.MediaNative;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class OpusLoader {
|
||||
public class OpusLoader{
|
||||
private static long timetracker;
|
||||
private static boolean inited;
|
||||
|
||||
@@ -23,8 +23,8 @@ public class OpusLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static long getLength() {
|
||||
if (isReadyToUse()) {
|
||||
public static long getLength(){
|
||||
if(isReadyToUse()){
|
||||
long length = System.currentTimeMillis() - timetracker;
|
||||
timetracker = System.currentTimeMillis();
|
||||
return length;
|
||||
@@ -32,8 +32,8 @@ public class OpusLoader {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public static int AudioStartRecordBridge(String str) {
|
||||
if (isReadyToUse()) {
|
||||
public static int AudioStartRecordBridge(String str){
|
||||
if(isReadyToUse()){
|
||||
// Init custom AudioStartRecord
|
||||
timetracker = System.currentTimeMillis();
|
||||
return 1;
|
||||
@@ -41,21 +41,21 @@ public class OpusLoader {
|
||||
return MediaNative.audioStartRecord(str);
|
||||
}
|
||||
|
||||
public static int AudioWriteFrameBridge(ByteBuffer buffer, int length) {
|
||||
if (isReadyToUse()) {
|
||||
public static int AudioWriteFrameBridge(ByteBuffer buffer, int length){
|
||||
if(isReadyToUse()){
|
||||
// Init custom AudioWriteFrame
|
||||
}
|
||||
return MediaNative.audioWriteFrame(buffer, length);
|
||||
}
|
||||
|
||||
public static void AudioStopRecordBridge() {
|
||||
if (isReadyToUse()) {
|
||||
public static void AudioStopRecordBridge(){
|
||||
if(isReadyToUse()){
|
||||
// Init custom AudioStopRecord
|
||||
}
|
||||
MediaNative.audioStopRecord();
|
||||
}
|
||||
|
||||
private static boolean isReadyToUse() {
|
||||
private static boolean isReadyToUse(){
|
||||
return opusmodule() && inited;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,14 +42,12 @@ import java.util.Locale;
|
||||
|
||||
import ru.vtosters.lite.ui.fragments.VTSettings;
|
||||
|
||||
public class Preferences {
|
||||
public class Preferences{
|
||||
static final boolean isDebug = Debug.isDebuggerConnected();
|
||||
public static SharedPreferences preferences = getContext().getSharedPreferences("com.vtosters.lite_preferences", Context.MODE_PRIVATE);
|
||||
|
||||
public static String VERSIONNAME = "Beta";
|
||||
|
||||
static final boolean isDebug = Debug.isDebuggerConnected();
|
||||
|
||||
public static void init(Application application) {
|
||||
public static void init(Application application){
|
||||
setupFilters();
|
||||
fixGapps();
|
||||
setProxy();
|
||||
@@ -62,341 +60,341 @@ public class Preferences {
|
||||
getInstance().autoCleaningCache();
|
||||
} // VK Init
|
||||
|
||||
public static void forceOffline() {
|
||||
public static void forceOffline(){
|
||||
setupFilters();
|
||||
getInstance().autoCleaningCache();
|
||||
|
||||
edit().putBoolean("isdark", isDarkTheme()).commit();
|
||||
|
||||
if (setoffline() && !offline()) {
|
||||
if(setoffline() && !offline()){
|
||||
Users.a();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getBoolValue(String key, Boolean value) {
|
||||
if (preferences == null) {
|
||||
public static boolean getBoolValue(String key, Boolean value){
|
||||
if(preferences == null){
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
}
|
||||
return preferences.getBoolean(key, value);
|
||||
} // Set bool by default and get value
|
||||
|
||||
public static SharedPreferences getPrefsFromFile(String filename) {
|
||||
public static SharedPreferences getPrefsFromFile(String filename){
|
||||
return getContext().getSharedPreferences(filename, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public static boolean opusmodule() {
|
||||
public static boolean opusmodule(){
|
||||
return getBoolValue("opusmodule", true);
|
||||
}
|
||||
|
||||
public static boolean systemtheme() {
|
||||
public static boolean systemtheme(){
|
||||
return false; //getBoolValue("systemtheme", true) && VERSION.SDK_INT >= 28;
|
||||
}
|
||||
|
||||
public static boolean authorsrecomm() {
|
||||
public static boolean authorsrecomm(){
|
||||
return getBoolValue("authorsrecomm", false);
|
||||
}
|
||||
|
||||
public static boolean captions() {
|
||||
public static boolean captions(){
|
||||
return getBoolValue("captions", false);
|
||||
}
|
||||
|
||||
public static boolean copyright_post() {
|
||||
public static boolean copyright_post(){
|
||||
return getBoolValue("copyright_post", false);
|
||||
}
|
||||
|
||||
public static boolean default_ad_list() {
|
||||
public static boolean default_ad_list(){
|
||||
return getBoolValue("default_ad_list", false);
|
||||
}
|
||||
|
||||
public static boolean shitposting() {
|
||||
public static boolean shitposting(){
|
||||
return getBoolValue("shitposting", false);
|
||||
}
|
||||
|
||||
public static boolean friendsrecomm() {
|
||||
public static boolean friendsrecomm(){
|
||||
return getBoolValue("friendsrecomm", false);
|
||||
}
|
||||
|
||||
public static boolean isBGStickersEnabled() {
|
||||
public static boolean isBGStickersEnabled(){
|
||||
return getBoolValue("isBGStickersEnabled", true);
|
||||
}
|
||||
|
||||
public static boolean ads() {
|
||||
public static boolean ads(){
|
||||
return getBoolValue("__dbg_no_ads", false);
|
||||
}
|
||||
|
||||
public static boolean adsgroup() {
|
||||
public static boolean adsgroup(){
|
||||
return getBoolValue("adsgroup", false);
|
||||
}
|
||||
|
||||
public static boolean oldicons() {
|
||||
public static boolean oldicons(){
|
||||
return !milkshake();
|
||||
}
|
||||
|
||||
public static boolean vkme() {
|
||||
public static boolean vkme(){
|
||||
return getBoolValue("vkme", false);
|
||||
}
|
||||
|
||||
public static boolean adsslider() {
|
||||
public static boolean adsslider(){
|
||||
return getBoolValue("__dbg_no_slider_ads", false);
|
||||
}
|
||||
|
||||
public static boolean adsstories() {
|
||||
public static boolean adsstories(){
|
||||
return getBoolValue("adsstories", false);
|
||||
}
|
||||
|
||||
public static boolean alteremoji(Context context) {
|
||||
public static boolean alteremoji(Context context){
|
||||
return alteremojipref() ? alteremojipref() : Screen.l(context);
|
||||
}
|
||||
|
||||
public static boolean alteremojipref() {
|
||||
public static boolean alteremojipref(){
|
||||
return getBoolValue("alteremoji", false);
|
||||
}
|
||||
|
||||
public static boolean awayphp() {
|
||||
public static boolean awayphp(){
|
||||
return getBoolValue("awayphp", true);
|
||||
}
|
||||
|
||||
public static boolean musicFixNew() {
|
||||
public static boolean musicFixNew(){
|
||||
return getBoolValue("musicFixNew", true);
|
||||
}
|
||||
|
||||
public static Class useNewSettings() {
|
||||
public static Class useNewSettings(){
|
||||
boolean bool = getBoolValue("useNewSettings", true);
|
||||
return bool? VTSettings.class : SettingsListFragment.class;
|
||||
return bool ? VTSettings.class : SettingsListFragment.class;
|
||||
}
|
||||
|
||||
public static boolean VKUI_INJ() {
|
||||
public static boolean VKUI_INJ(){
|
||||
return getBoolValue("VKUI_INJ", true);
|
||||
}
|
||||
|
||||
public static boolean benchmark() {
|
||||
public static boolean benchmark(){
|
||||
return getBoolValue("benchmark", false);
|
||||
}
|
||||
|
||||
public static boolean calls() {
|
||||
public static boolean calls(){
|
||||
return getBoolValue("calls", false);
|
||||
}
|
||||
|
||||
public static boolean convUsersOnline() {
|
||||
public static boolean convUsersOnline(){
|
||||
return getBoolValue("convUsersOnline", false);
|
||||
}
|
||||
|
||||
public static boolean darkmode() {
|
||||
public static boolean darkmode(){
|
||||
return getBoolValue("darkmode", true);
|
||||
}
|
||||
|
||||
public static boolean dev() {
|
||||
public static boolean dev(){
|
||||
return getBoolValue("dev", false);
|
||||
}
|
||||
|
||||
public static boolean devmenu() {
|
||||
public static boolean devmenu(){
|
||||
return true; //getBoolValue("devmenu", false);
|
||||
}
|
||||
|
||||
public static boolean dnr() {
|
||||
public static boolean dnr(){
|
||||
return getBoolValue("dnr", true);
|
||||
}
|
||||
|
||||
public static boolean dns() {
|
||||
public static boolean dns(){
|
||||
return getBoolValue("dns", true);
|
||||
}
|
||||
|
||||
public static boolean libverify() {
|
||||
public static boolean libverify(){
|
||||
return getBoolValue("libverify", false);
|
||||
}
|
||||
|
||||
public static boolean dnt() {
|
||||
public static boolean dnt(){
|
||||
return getBoolValue("dnt", true);
|
||||
}
|
||||
|
||||
public static boolean dockcounter() {
|
||||
public static boolean dockcounter(){
|
||||
return getBoolValue("dockcounter", true);
|
||||
}
|
||||
|
||||
public static boolean feedcache() {
|
||||
public static boolean feedcache(){
|
||||
return getBoolValue("feedcache", true);
|
||||
}
|
||||
|
||||
|
||||
public static boolean superapp() {
|
||||
public static boolean superapp(){
|
||||
return getBoolValue("superapp", true);
|
||||
}
|
||||
|
||||
public static boolean milkshake() {
|
||||
public static boolean milkshake(){
|
||||
return getBoolValue("milkshake", true);
|
||||
}
|
||||
|
||||
public static boolean returnnorifs() {
|
||||
public static boolean returnnorifs(){
|
||||
return getBoolValue("returnnorifs", false);
|
||||
}
|
||||
|
||||
|
||||
public static boolean CommentsSort() {
|
||||
public static boolean CommentsSort(){
|
||||
return getBoolValue("commentssorting", false);
|
||||
}
|
||||
|
||||
public static boolean gcmfix() {
|
||||
public static boolean gcmfix(){
|
||||
return getBoolValue("gcmfix", true) && isValidSignature();
|
||||
}
|
||||
|
||||
public static boolean hasMusicSubscription() {
|
||||
public static boolean hasMusicSubscription(){
|
||||
return getBoolValue("hasMusicSubscription", true);
|
||||
}
|
||||
|
||||
public static boolean isEnableExternalOpening() {
|
||||
public static boolean isEnableExternalOpening(){
|
||||
return getBoolValue("isEnableExternalOpening", false);
|
||||
}
|
||||
|
||||
public static boolean iconvk() {
|
||||
public static boolean iconvk(){
|
||||
return getBoolValue("iconvk", false);
|
||||
}
|
||||
|
||||
public static boolean iconvkru() {
|
||||
public static boolean iconvkru(){
|
||||
return getBoolValue("iconvkru", false);
|
||||
}
|
||||
|
||||
public static boolean isMusicRestricted() {
|
||||
public static boolean isMusicRestricted(){
|
||||
return getBoolValue("isMusicRestricted", true);
|
||||
}
|
||||
|
||||
public static boolean msgflat() {
|
||||
public static boolean msgflat(){
|
||||
return getBoolValue("msgflat", false);
|
||||
}
|
||||
|
||||
public static boolean msgtails() {
|
||||
public static boolean msgtails(){
|
||||
return getBoolValue("msgtails", true);
|
||||
}
|
||||
|
||||
public static boolean navbar() {
|
||||
public static boolean navbar(){
|
||||
return getBoolValue("navbar", true);
|
||||
}
|
||||
|
||||
public static boolean newfeed() {
|
||||
public static boolean newfeed(){
|
||||
return getBoolValue("newfeed", true);
|
||||
}
|
||||
|
||||
public static boolean offline() {
|
||||
public static boolean offline(){
|
||||
return getBoolValue("offline", true);
|
||||
}
|
||||
|
||||
public static boolean oldabout() {
|
||||
public static boolean oldabout(){
|
||||
return getBoolValue("oldabout", false);
|
||||
}
|
||||
|
||||
public static boolean postsrecomm() {
|
||||
public static boolean postsrecomm(){
|
||||
return getBoolValue("postsrecomm", false);
|
||||
}
|
||||
|
||||
public static String readstatus() {
|
||||
public static String readstatus(){
|
||||
return dnr() ? "messages.markAsRead" : "null";
|
||||
}
|
||||
|
||||
public static String copyrightfix() {
|
||||
public static String copyrightfix(){
|
||||
return copyright_post() ? "copyright" : "ads_easy_promote";
|
||||
}
|
||||
|
||||
public static boolean refsfilter() {
|
||||
public static boolean refsfilter(){
|
||||
return getBoolValue("refsfilter", false);
|
||||
}
|
||||
|
||||
public static boolean setoffline() {
|
||||
public static boolean setoffline(){
|
||||
return getBoolValue("setoffline", true);
|
||||
}
|
||||
|
||||
public static boolean shortinfo() {
|
||||
public static boolean shortinfo(){
|
||||
return getBoolValue("shortinfo", true);
|
||||
}
|
||||
|
||||
public static boolean shortlinkfilter() {
|
||||
public static boolean shortlinkfilter(){
|
||||
return getBoolValue("shortlinkfilter", false);
|
||||
}
|
||||
|
||||
public static boolean shortpost() {
|
||||
public static boolean shortpost(){
|
||||
return getBoolValue("shortpost", true);
|
||||
}
|
||||
|
||||
public static boolean showmenu() {
|
||||
public static boolean showmenu(){
|
||||
return getBoolValue("showmenu", false);
|
||||
}
|
||||
|
||||
public static boolean ssl() {
|
||||
public static boolean ssl(){
|
||||
return getBoolValue("ssl", true);
|
||||
}
|
||||
|
||||
public static boolean stories() {
|
||||
public static boolean stories(){
|
||||
return getBoolValue("stories", true);
|
||||
}
|
||||
|
||||
public static boolean swipe() {
|
||||
public static boolean swipe(){
|
||||
return getBoolValue("swipe", true);
|
||||
}
|
||||
|
||||
public static boolean systememoji() {
|
||||
public static boolean systememoji(){
|
||||
return getBoolValue("systememoji", false);
|
||||
}
|
||||
|
||||
public static boolean unlockstats() {
|
||||
public static boolean unlockstats(){
|
||||
return getBoolValue("unlockstats", false);
|
||||
}
|
||||
|
||||
public static boolean usevkui() {
|
||||
public static boolean usevkui(){
|
||||
return getBoolValue("usevkui", true);
|
||||
}
|
||||
|
||||
public static boolean vksans() {
|
||||
public static boolean vksans(){
|
||||
return getBoolValue("vksans", false);
|
||||
}
|
||||
|
||||
public static boolean voice() {
|
||||
public static boolean voice(){
|
||||
return getBoolValue("voice", true);
|
||||
}
|
||||
|
||||
public static boolean newvideo() {
|
||||
public static boolean newvideo(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getMsgCount() {
|
||||
public static int getMsgCount(){
|
||||
String customvalue = getPrefsValue("msgcount");
|
||||
return customvalue.isEmpty() ? 30 : Integer.parseInt(customvalue);
|
||||
}
|
||||
|
||||
public static String MediacontentFix() {
|
||||
public static String MediacontentFix(){
|
||||
return VERSION.SDK_INT >= 29 ? "date_modified DESC" : "datetaken DESC";
|
||||
} // Fix photo picker for sdk 29+
|
||||
|
||||
public static String MediacontentFix2() {
|
||||
public static String MediacontentFix2(){
|
||||
return VERSION.SDK_INT >= 29 ? "date_modified" : "datetaken";
|
||||
} // Fix photo picker for sdk 29+
|
||||
|
||||
public static String MediacontentFix3() {
|
||||
public static String MediacontentFix3(){
|
||||
return VERSION.SDK_INT >= 29 ? ", date_modified=" : ", dateTaken=";
|
||||
} // Fix photo picker for sdk 29+
|
||||
|
||||
public static boolean color_grishka() {
|
||||
public static boolean color_grishka(){
|
||||
return getBoolValue("color_grishka", true);
|
||||
}
|
||||
|
||||
public static boolean vkme_msg() {
|
||||
public static boolean vkme_msg(){
|
||||
return getBoolValue("vkme_msg", false);
|
||||
}
|
||||
|
||||
public static boolean vkme_notifs() {
|
||||
public static boolean vkme_notifs(){
|
||||
return getBoolValue("vkme_notifs", false);
|
||||
}
|
||||
|
||||
public static boolean roundedmsgs() {
|
||||
public static boolean roundedmsgs(){
|
||||
return getBoolValue("roundedmsgs", false);
|
||||
}
|
||||
|
||||
public static boolean checkupdates() {
|
||||
public static boolean checkupdates(){
|
||||
return getBoolValue("checkupdates", true) && isValidSignature();
|
||||
}
|
||||
|
||||
public static boolean disableanimstickers() {
|
||||
public static boolean disableanimstickers(){
|
||||
return getBoolValue("disableanimstickers", true);
|
||||
}
|
||||
|
||||
public static boolean isValidSignature() {
|
||||
public static boolean isValidSignature(){
|
||||
try {
|
||||
return validateAppSignature();
|
||||
} catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) {
|
||||
@@ -405,38 +403,38 @@ public class Preferences {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean disableSettingsSumms() {
|
||||
public static boolean disableSettingsSumms(){
|
||||
return getBoolValue("disableSettingsSumms", false);
|
||||
}
|
||||
|
||||
public static boolean donaterecomm() {
|
||||
public static boolean donaterecomm(){
|
||||
return getBoolValue("donaterecomm", false);
|
||||
}
|
||||
|
||||
public static boolean hasVerification() {
|
||||
public static boolean hasVerification(){
|
||||
return isVerified(getUserId());
|
||||
}
|
||||
|
||||
public static boolean hasSpecialVerif() {
|
||||
public static boolean hasSpecialVerif(){
|
||||
return hasPrometheus(getUserId());
|
||||
}
|
||||
|
||||
public static String getLocale() {
|
||||
public static String getLocale(){
|
||||
String string = getPrefsValue("lang_value");
|
||||
|
||||
if (string.equals("system")) {
|
||||
if(string.equals("system")){
|
||||
return Locale.getDefault().getLanguage();
|
||||
}
|
||||
|
||||
return string.isEmpty() ? Locale.getDefault().getLanguage() : string;
|
||||
}
|
||||
|
||||
public static boolean fulltime() {
|
||||
public static boolean fulltime(){
|
||||
return getPrefsValue("dateformat").equals("noyear") || getPrefsValue("dateformat").equals("full") || getPrefsValue("dateformat").equals("noseconds");
|
||||
}
|
||||
|
||||
public static String getDateFormat() {
|
||||
switch (getPrefsValue("dateformat")) {
|
||||
public static String getDateFormat(){
|
||||
switch(getPrefsValue("dateformat")) {
|
||||
case "noyear":
|
||||
return getString("fulltime2");
|
||||
case "full":
|
||||
@@ -446,8 +444,8 @@ public class Preferences {
|
||||
}
|
||||
}
|
||||
|
||||
public static long getSizeForDelete() {
|
||||
switch (getPrefsValue("clearcache")) {
|
||||
public static long getSizeForDelete(){
|
||||
switch(getPrefsValue("clearcache")) {
|
||||
case "100mb":
|
||||
return 104857600L;
|
||||
case "500mb":
|
||||
@@ -463,14 +461,14 @@ public class Preferences {
|
||||
}
|
||||
}
|
||||
|
||||
public static int compress(int origquality) {
|
||||
public static int compress(int origquality){
|
||||
if(getBoolValue("shakal", false)) return 5;
|
||||
if(!getBoolValue("compressPhotos", true)) return 100;
|
||||
return origquality;
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public static SimpleDateFormat setDateFormat() {
|
||||
public static SimpleDateFormat setDateFormat(){
|
||||
return new SimpleDateFormat(getDateFormat());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
public class ProfileHide {
|
||||
public class ProfileHide{
|
||||
// private static final OkHttpClient client = new OkHttpClient();
|
||||
//
|
||||
// public static void injectMap(HashMap<Integer, AdministratorProfileFragment.a.a> hashMap) {
|
||||
|
||||
@@ -7,73 +7,73 @@ import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class Proxy {
|
||||
public static String getOauthComAuth() {
|
||||
public class Proxy{
|
||||
public static String getOauthComAuth(){
|
||||
return getOauthComHttps() + "/authorize";
|
||||
}
|
||||
|
||||
public static String getOauthComAuthClient() {
|
||||
public static String getOauthComAuthClient(){
|
||||
return getOauthComAuth() + "?client_id=";
|
||||
}
|
||||
|
||||
public static String getOauthComBlank() {
|
||||
public static String getOauthComBlank(){
|
||||
return getOauthComHttps() + "/blank.html";
|
||||
}
|
||||
|
||||
public static String getOauthComBlankRedirect() {
|
||||
public static String getOauthComBlankRedirect(){
|
||||
return "&redirect_uri=" + getOauthComBlank();
|
||||
}
|
||||
|
||||
public static String getOauthComHttps() {
|
||||
public static String getOauthComHttps(){
|
||||
return "https://" + getOauthCom();
|
||||
}
|
||||
|
||||
public static String getStaticComSupport() {
|
||||
public static String getStaticComSupport(){
|
||||
return getStaticCom() + "/support";
|
||||
}
|
||||
|
||||
public static String oauthFix() {
|
||||
public static String oauthFix(){
|
||||
return "https://oauth.vk.com/blank.html";
|
||||
}
|
||||
|
||||
public static String getApiCom() {
|
||||
public static String getApiCom(){
|
||||
String string = getPrefsValue("proxyapi");
|
||||
if (!proxy() & string.isEmpty()) return "api.vk.com";
|
||||
if(!proxy() & string.isEmpty()) return "api.vk.com";
|
||||
return string;
|
||||
}
|
||||
|
||||
public static String getAwayPhpCom() {
|
||||
public static String getAwayPhpCom(){
|
||||
String string = getPrefsValue("proxyapi");
|
||||
if (!proxy() & string.isEmpty()) return "m.vk.com";
|
||||
if(!proxy() & string.isEmpty()) return "m.vk.com";
|
||||
return string;
|
||||
}
|
||||
|
||||
public static String getOauthCom() {
|
||||
public static String getOauthCom(){
|
||||
String string = getPrefsValue("proxyoauth");
|
||||
if (!proxy() & string.isEmpty()) return "oauth.vk.com";
|
||||
if(!proxy() & string.isEmpty()) return "oauth.vk.com";
|
||||
return string;
|
||||
}
|
||||
|
||||
public static String getStaticCom() {
|
||||
public static String getStaticCom(){
|
||||
String string = getPrefsValue("proxystatic");
|
||||
if (!proxy() & string.isEmpty()) return "static.vk.com";
|
||||
if(!proxy() & string.isEmpty()) return "static.vk.com";
|
||||
return string;
|
||||
}
|
||||
|
||||
public static String staticFix(String str) {
|
||||
public static String staticFix(String str){
|
||||
String str2;
|
||||
String string = getPrefsValue("proxystatic");
|
||||
|
||||
if (!proxy() & string.isEmpty()) return str;
|
||||
if(!proxy() & string.isEmpty()) return str;
|
||||
|
||||
str2 = string;
|
||||
return str.replace(str2, "static.vk.com");
|
||||
}
|
||||
|
||||
public static void setProxy() {
|
||||
public static void setProxy(){
|
||||
Properties properties = getProperties();
|
||||
|
||||
switch (getPrefsValue("proxy")) {
|
||||
switch(getPrefsValue("proxy")) {
|
||||
case "zaborona":
|
||||
properties.setProperty("socksProxyHost", "socks.zaboronahelp.pp.ua");
|
||||
properties.setProperty("socksProxyPort", "1488");
|
||||
@@ -104,7 +104,7 @@ public class Proxy {
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetProxy() {
|
||||
public static void resetProxy(){
|
||||
clearProperty("https.proxyHost");
|
||||
clearProperty("https.proxyPort");
|
||||
clearProperty("https.proxyUser");
|
||||
@@ -117,7 +117,7 @@ public class Proxy {
|
||||
clearProperty("socksPortHost");
|
||||
} // Reset all proxies
|
||||
|
||||
public static void resetProxySocks() {
|
||||
public static void resetProxySocks(){
|
||||
clearProperty("https.proxyHost");
|
||||
clearProperty("https.proxyPort");
|
||||
clearProperty("https.proxyUser");
|
||||
@@ -128,7 +128,7 @@ public class Proxy {
|
||||
clearProperty("http.proxyPassword");
|
||||
} // Reset all except socks
|
||||
|
||||
public static void resetProxyHttp() {
|
||||
public static void resetProxyHttp(){
|
||||
clearProperty("https.proxyHost");
|
||||
clearProperty("https.proxyPort");
|
||||
clearProperty("https.proxyUser");
|
||||
@@ -137,7 +137,7 @@ public class Proxy {
|
||||
clearProperty("socksPortHost");
|
||||
} // Reset all except http
|
||||
|
||||
public static void resetProxyHttps() {
|
||||
public static void resetProxyHttps(){
|
||||
clearProperty("http.proxyHost");
|
||||
clearProperty("http.proxyPort");
|
||||
clearProperty("http.proxyUser");
|
||||
@@ -146,61 +146,61 @@ public class Proxy {
|
||||
clearProperty("socksPortHost");
|
||||
} // Reset all except https
|
||||
|
||||
public static String proxyHostHTTP() {
|
||||
public static String proxyHostHTTP(){
|
||||
String string = getPrefsValue("proxyHostHTTP");
|
||||
return string.isEmpty() ? "192.168.0.1" : string;
|
||||
}
|
||||
|
||||
public static String proxyHostHTTPS() {
|
||||
public static String proxyHostHTTPS(){
|
||||
String string = getPrefsValue("proxyHostHTTPS");
|
||||
return string.isEmpty() ? "192.168.0.1" : string;
|
||||
}
|
||||
|
||||
public static String proxyHostSocks() {
|
||||
public static String proxyHostSocks(){
|
||||
String string = getPrefsValue("proxyHostSocks");
|
||||
return string.isEmpty() ? "192.168.0.1" : string;
|
||||
}
|
||||
|
||||
public static String proxyPortHTTP() {
|
||||
public static String proxyPortHTTP(){
|
||||
String string = getPrefsValue("proxyPortHTTP");
|
||||
return string.isEmpty() ? "8888" : string;
|
||||
}
|
||||
|
||||
public static String proxyPortHTTPS() {
|
||||
public static String proxyPortHTTPS(){
|
||||
String string = getPrefsValue("proxyPortHTTPS");
|
||||
return string.isEmpty() ? "8888" : string;
|
||||
}
|
||||
|
||||
public static String proxyPortSocks() {
|
||||
public static String proxyPortSocks(){
|
||||
String string = getPrefsValue("proxyPortSocks");
|
||||
return string.isEmpty() ? "8888" : string;
|
||||
}
|
||||
|
||||
public static String proxyUserHTTP() {
|
||||
public static String proxyUserHTTP(){
|
||||
String string = getPrefsValue("proxyUserHTTP");
|
||||
return string.isEmpty() ? "" : string;
|
||||
}
|
||||
|
||||
public static String proxyUserHTTPS() {
|
||||
public static String proxyUserHTTPS(){
|
||||
String string = getPrefsValue("proxyUserHTTPS");
|
||||
return string.isEmpty() ? "" : string;
|
||||
}
|
||||
|
||||
public static String proxyPassHTTP() {
|
||||
public static String proxyPassHTTP(){
|
||||
String string = getPrefsValue("proxyPassHTTP");
|
||||
return string.isEmpty() ? "" : string;
|
||||
}
|
||||
|
||||
public static String proxyPassHTTPS() {
|
||||
public static String proxyPassHTTPS(){
|
||||
String string = getPrefsValue("proxyPassHTTPS");
|
||||
return string.isEmpty() ? "" : string;
|
||||
}
|
||||
|
||||
public static boolean proxy() {
|
||||
public static boolean proxy(){
|
||||
return getPrefsValue("proxy").equals("apiproxy");
|
||||
}
|
||||
|
||||
public static boolean proxyvk() {
|
||||
public static boolean proxyvk(){
|
||||
return getBoolValue("proxyvk", false);
|
||||
} // Official vk proxy enforcer
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public class ReflectionUtils {
|
||||
public class ReflectionUtils{
|
||||
|
||||
/**
|
||||
* Gets a class with specific name.
|
||||
* Supports smali type (Lpackage/Class;)
|
||||
* */
|
||||
public static Class<?> getClass(String name) throws ClassNotFoundException {
|
||||
if (name.contains(";"))
|
||||
*/
|
||||
public static Class<?> getClass(String name) throws ClassNotFoundException{
|
||||
if(name.contains(";"))
|
||||
name = name.substring(1, name.length() - 1).replace("/", ".");
|
||||
return Class.forName(name);
|
||||
}
|
||||
@@ -20,13 +20,13 @@ public class ReflectionUtils {
|
||||
/**
|
||||
* Gets a declared field with specific name.
|
||||
**/
|
||||
public static Field getDeclaredField(Class<?> clz, String fieldName) throws NoSuchFieldException {
|
||||
public static Field getDeclaredField(Class<?> clz, String fieldName) throws NoSuchFieldException{
|
||||
Field field = clz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
public static Field getDeclaredField(String className, String fieldName) throws NoSuchFieldException, ClassNotFoundException {
|
||||
public static Field getDeclaredField(String className, String fieldName) throws NoSuchFieldException, ClassNotFoundException{
|
||||
Field field = getClass(className).getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
@@ -35,21 +35,22 @@ public class ReflectionUtils {
|
||||
/**
|
||||
* Gets a field with specific name.
|
||||
**/
|
||||
public static Field getField(Class<?> clz, String fieldName) throws NoSuchFieldException {
|
||||
public static Field getField(Class<?> clz, String fieldName) throws NoSuchFieldException{
|
||||
Field field = clz.getField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
public static Field getField(String className, String fieldName) throws NoSuchFieldException, ClassNotFoundException {
|
||||
public static Field getField(String className, String fieldName) throws NoSuchFieldException, ClassNotFoundException{
|
||||
Field field = getClass(className).getField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a non-static field value*/
|
||||
public static <T> T getObjectField(Class<?> clz, String fieldName, Object instance) throws NoSuchFieldException, IllegalAccessException {
|
||||
* Gets a non-static field value
|
||||
*/
|
||||
public static <T> T getObjectField(Class<?> clz, String fieldName, Object instance) throws NoSuchFieldException, IllegalAccessException{
|
||||
Field field;
|
||||
try {
|
||||
field = clz.getField(fieldName);
|
||||
@@ -59,7 +60,7 @@ public class ReflectionUtils {
|
||||
return (T) field.get(instance);
|
||||
}
|
||||
|
||||
public static <T> T getObjectField(String className, String fieldName, Object instance) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException {
|
||||
public static <T> T getObjectField(String className, String fieldName, Object instance) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException{
|
||||
Field field;
|
||||
try {
|
||||
field = getField(className, fieldName);
|
||||
@@ -70,8 +71,9 @@ public class ReflectionUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value for non-static field*/
|
||||
public static void setObjectField(Class<?> clz, String fieldName, Object instance, Object value) throws NoSuchFieldException, IllegalAccessException {
|
||||
* Sets a value for non-static field
|
||||
*/
|
||||
public static void setObjectField(Class<?> clz, String fieldName, Object instance, Object value) throws NoSuchFieldException, IllegalAccessException{
|
||||
Field field;
|
||||
try {
|
||||
field = clz.getField(fieldName);
|
||||
@@ -81,7 +83,7 @@ public class ReflectionUtils {
|
||||
field.set(instance, value);
|
||||
}
|
||||
|
||||
public static void setObjectField(String className, String fieldName, Object instance, Object value) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException {
|
||||
public static void setObjectField(String className, String fieldName, Object instance, Object value) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException{
|
||||
Field field;
|
||||
try {
|
||||
field = getField(className, fieldName);
|
||||
@@ -92,8 +94,9 @@ public class ReflectionUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlocks modifying of field */
|
||||
private static void unlockField(Field field) throws NoSuchFieldException {
|
||||
* Unlocks modifying of field
|
||||
*/
|
||||
private static void unlockField(Field field) throws NoSuchFieldException{
|
||||
Field accessFlagsFld = getDeclaredField(Field.class, "accessFlags");
|
||||
try {
|
||||
int accessFlags = accessFlagsFld.getInt(field);
|
||||
@@ -104,8 +107,9 @@ public class ReflectionUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlocks modifying of non-static field and sets a value for it */
|
||||
public static void setObjectFinalField(Class<?> clz, String fieldName, Object instance, Object value) throws NoSuchFieldException, IllegalAccessException {
|
||||
* Unlocks modifying of non-static field and sets a value for it
|
||||
*/
|
||||
public static void setObjectFinalField(Class<?> clz, String fieldName, Object instance, Object value) throws NoSuchFieldException, IllegalAccessException{
|
||||
Field field;
|
||||
try {
|
||||
field = clz.getField(fieldName);
|
||||
@@ -113,13 +117,13 @@ public class ReflectionUtils {
|
||||
field = clz.getDeclaredField(fieldName);
|
||||
}
|
||||
|
||||
if (!Modifier.isFinal(field.getModifiers())) return;
|
||||
if(!Modifier.isFinal(field.getModifiers())) return;
|
||||
|
||||
unlockField(field);
|
||||
field.set(instance, value);
|
||||
}
|
||||
|
||||
public static void setObjectFinalField(String className, String fieldName, Object instance, Object value) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException {
|
||||
public static void setObjectFinalField(String className, String fieldName, Object instance, Object value) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException{
|
||||
Field field;
|
||||
try {
|
||||
field = getField(className, fieldName);
|
||||
@@ -127,15 +131,16 @@ public class ReflectionUtils {
|
||||
field = getDeclaredField(className, fieldName);
|
||||
}
|
||||
|
||||
if (!Modifier.isFinal(field.getModifiers())) return;
|
||||
if(!Modifier.isFinal(field.getModifiers())) return;
|
||||
|
||||
unlockField(field);
|
||||
field.set(instance, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value for static field*/
|
||||
public static void setObjectStaticField(Class<?> clz, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException {
|
||||
* Sets a value for static field
|
||||
*/
|
||||
public static void setObjectStaticField(Class<?> clz, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException{
|
||||
Field field;
|
||||
try {
|
||||
field = clz.getField(fieldName);
|
||||
@@ -145,7 +150,7 @@ public class ReflectionUtils {
|
||||
field.set(null, value);
|
||||
}
|
||||
|
||||
public static void setObjectStaticField(String className, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException {
|
||||
public static void setObjectStaticField(String className, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException{
|
||||
Field field;
|
||||
try {
|
||||
field = getField(className, fieldName);
|
||||
@@ -156,8 +161,9 @@ public class ReflectionUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlocks modifying of non-static field and sets a value for it */
|
||||
public static void setObjectFinalStaticField(Class<?> clz, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException {
|
||||
* Unlocks modifying of non-static field and sets a value for it
|
||||
*/
|
||||
public static void setObjectFinalStaticField(Class<?> clz, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException{
|
||||
Field field;
|
||||
try {
|
||||
field = clz.getField(fieldName);
|
||||
@@ -165,13 +171,13 @@ public class ReflectionUtils {
|
||||
field = clz.getDeclaredField(fieldName);
|
||||
}
|
||||
|
||||
if (!Modifier.isFinal(field.getModifiers())) return;
|
||||
if(!Modifier.isFinal(field.getModifiers())) return;
|
||||
|
||||
unlockField(field);
|
||||
field.set(null, value);
|
||||
}
|
||||
|
||||
public static void setObjectFinalStaticField(String className, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException {
|
||||
public static void setObjectFinalStaticField(String className, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException{
|
||||
Field field;
|
||||
try {
|
||||
field = getField(className, fieldName);
|
||||
@@ -179,15 +185,16 @@ public class ReflectionUtils {
|
||||
field = getDeclaredField(className, fieldName);
|
||||
}
|
||||
|
||||
if (!Modifier.isFinal(field.getModifiers())) return;
|
||||
if(!Modifier.isFinal(field.getModifiers())) return;
|
||||
|
||||
unlockField(field);
|
||||
field.set(null, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a static field value*/
|
||||
public static <T> T getObjectField(Class<?> clz, String fieldName) throws NoSuchFieldException, IllegalAccessException {
|
||||
* Gets a static field value
|
||||
*/
|
||||
public static <T> T getObjectField(Class<?> clz, String fieldName) throws NoSuchFieldException, IllegalAccessException{
|
||||
Field field;
|
||||
try {
|
||||
field = clz.getField(fieldName);
|
||||
@@ -200,21 +207,21 @@ public class ReflectionUtils {
|
||||
/**
|
||||
* Gets a method with specific name.
|
||||
**/
|
||||
public static Method getMethod(Class<?> clz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
|
||||
public static Method getMethod(Class<?> clz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException{
|
||||
Method method = clz.getMethod(methodName, parameterTypes);
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
}
|
||||
|
||||
public static Method getMethod(String className, String methodName, Class<?>... parameterTypes) throws ClassNotFoundException, NoSuchMethodException {
|
||||
public static Method getMethod(String className, String methodName, Class<?>... parameterTypes) throws ClassNotFoundException, NoSuchMethodException{
|
||||
Method method = getClass(className).getMethod(methodName, parameterTypes);
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
}
|
||||
|
||||
public static Method getMethod(Class<?> clz, String methodName, Object... parameters) throws NoSuchMethodException {
|
||||
public static Method getMethod(Class<?> clz, String methodName, Object... parameters) throws NoSuchMethodException{
|
||||
Class<?>[] parameterTypes = new Class<?>[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
for(int i = 0; i < parameters.length; i++) {
|
||||
parameterTypes[i] = parameters[i].getClass();
|
||||
}
|
||||
Method method = getMethod(clz, methodName, parameterTypes);
|
||||
@@ -222,9 +229,9 @@ public class ReflectionUtils {
|
||||
return method;
|
||||
}
|
||||
|
||||
public static Method getMethod(String className, String methodName, Object... parameters) throws ClassNotFoundException, NoSuchMethodException {
|
||||
public static Method getMethod(String className, String methodName, Object... parameters) throws ClassNotFoundException, NoSuchMethodException{
|
||||
Class<?>[] parameterTypes = new Class<?>[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
for(int i = 0; i < parameters.length; i++) {
|
||||
parameterTypes[i] = parameters[i].getClass();
|
||||
}
|
||||
Method method = getMethod(className, methodName, parameterTypes);
|
||||
@@ -235,21 +242,21 @@ public class ReflectionUtils {
|
||||
/**
|
||||
* Gets a declared method with specific name.
|
||||
**/
|
||||
public static Method getDeclaredMethod(Class<?> clz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
|
||||
public static Method getDeclaredMethod(Class<?> clz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException{
|
||||
Method method = clz.getDeclaredMethod(methodName, parameterTypes);
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
}
|
||||
|
||||
public static Method getDeclaredMethod(String className, String methodName, Class<?>... parameterTypes) throws ClassNotFoundException, NoSuchMethodException {
|
||||
public static Method getDeclaredMethod(String className, String methodName, Class<?>... parameterTypes) throws ClassNotFoundException, NoSuchMethodException{
|
||||
Method method = getClass(className).getDeclaredMethod(methodName, parameterTypes);
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
}
|
||||
|
||||
public static Method getDeclaredMethod(Class<?> clz, String methodName, Object... parameters) throws NoSuchMethodException {
|
||||
public static Method getDeclaredMethod(Class<?> clz, String methodName, Object... parameters) throws NoSuchMethodException{
|
||||
Class<?>[] parameterTypes = new Class<?>[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
for(int i = 0; i < parameters.length; i++) {
|
||||
parameterTypes[i] = parameters[i].getClass();
|
||||
}
|
||||
Method method = getDeclaredMethod(clz, methodName, parameterTypes);
|
||||
@@ -257,9 +264,9 @@ public class ReflectionUtils {
|
||||
return method;
|
||||
}
|
||||
|
||||
public static Method getDeclaredMethod(String className, String methodName, Object... parameters) throws ClassNotFoundException, NoSuchMethodException {
|
||||
public static Method getDeclaredMethod(String className, String methodName, Object... parameters) throws ClassNotFoundException, NoSuchMethodException{
|
||||
Class<?>[] parameterTypes = new Class<?>[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
for(int i = 0; i < parameters.length; i++) {
|
||||
parameterTypes[i] = parameters[i].getClass();
|
||||
}
|
||||
Method method = getDeclaredMethod(className, methodName, parameterTypes);
|
||||
@@ -268,8 +275,9 @@ public class ReflectionUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a non-static method*/
|
||||
public static <T> T invokeMethod(Class<?> clz, String methodName, Object instance, Class<?>[] parameterTypes, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
* Invokes a non-static method
|
||||
*/
|
||||
public static <T> T invokeMethod(Class<?> clz, String methodName, Object instance, Class<?>[] parameterTypes, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException{
|
||||
Method method;
|
||||
try {
|
||||
method = getMethod(clz, methodName, parameterTypes);
|
||||
@@ -279,7 +287,7 @@ public class ReflectionUtils {
|
||||
return (T) method.invoke(instance, parameters);
|
||||
}
|
||||
|
||||
public static <T> T invokeMethod(String className, String methodName, Object instance, Class<?>[] parameterTypes, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException {
|
||||
public static <T> T invokeMethod(String className, String methodName, Object instance, Class<?>[] parameterTypes, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException{
|
||||
Method method;
|
||||
try {
|
||||
method = getMethod(className, methodName, parameterTypes);
|
||||
@@ -289,9 +297,9 @@ public class ReflectionUtils {
|
||||
return (T) method.invoke(instance, parameters);
|
||||
}
|
||||
|
||||
public static <T> T invokeMethod(Class<?> clz, String methodName, Object instance, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
public static <T> T invokeMethod(Class<?> clz, String methodName, Object instance, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException{
|
||||
Class<?>[] parameterTypes = new Class<?>[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
for(int i = 0; i < parameters.length; i++) {
|
||||
parameterTypes[i] = parameters[i].getClass();
|
||||
}
|
||||
Method method;
|
||||
@@ -303,9 +311,9 @@ public class ReflectionUtils {
|
||||
return (T) method.invoke(instance, parameters);
|
||||
}
|
||||
|
||||
public static <T> T invokeMethod(String className, String methodName, Object instance, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException {
|
||||
public static <T> T invokeMethod(String className, String methodName, Object instance, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException{
|
||||
Class<?>[] parameterTypes = new Class<?>[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
for(int i = 0; i < parameters.length; i++) {
|
||||
parameterTypes[i] = parameters[i].getClass();
|
||||
}
|
||||
Method method;
|
||||
@@ -318,8 +326,9 @@ public class ReflectionUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a static method*/
|
||||
public static <T> T invokeStaticMethod(Class<?> clz, String methodName, Class<?>[] parameterTypes, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
* Invokes a static method
|
||||
*/
|
||||
public static <T> T invokeStaticMethod(Class<?> clz, String methodName, Class<?>[] parameterTypes, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException{
|
||||
Method method;
|
||||
try {
|
||||
method = getMethod(clz, methodName, parameterTypes);
|
||||
@@ -329,7 +338,7 @@ public class ReflectionUtils {
|
||||
return (T) method.invoke(null, parameters);
|
||||
}
|
||||
|
||||
public static <T> T invokeStaticMethod(String className, String methodName, Class<?>[] parameterTypes, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException {
|
||||
public static <T> T invokeStaticMethod(String className, String methodName, Class<?>[] parameterTypes, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException{
|
||||
Method method;
|
||||
try {
|
||||
method = getMethod(className, methodName, parameterTypes);
|
||||
@@ -339,9 +348,9 @@ public class ReflectionUtils {
|
||||
return (T) method.invoke(null, parameters);
|
||||
}
|
||||
|
||||
public static <T> T invokeStaticMethod(Class<?> clz, String methodName, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
public static <T> T invokeStaticMethod(Class<?> clz, String methodName, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException{
|
||||
Class<?>[] parameterTypes = new Class<?>[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
for(int i = 0; i < parameters.length; i++) {
|
||||
parameterTypes[i] = parameters[i].getClass();
|
||||
}
|
||||
Method method;
|
||||
@@ -353,9 +362,9 @@ public class ReflectionUtils {
|
||||
return (T) method.invoke(null, parameters);
|
||||
}
|
||||
|
||||
public static <T> T invokeStaticMethod(String className, String methodName, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException {
|
||||
public static <T> T invokeStaticMethod(String className, String methodName, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException{
|
||||
Class<?>[] parameterTypes = new Class<?>[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
for(int i = 0; i < parameters.length; i++) {
|
||||
parameterTypes[i] = parameters[i].getClass();
|
||||
}
|
||||
Method method;
|
||||
|
||||
@@ -10,36 +10,36 @@ import static ru.vtosters.lite.utils.Preferences.vksans;
|
||||
import static ru.vtosters.lite.utils.Proxy.proxy;
|
||||
import static ru.vtosters.lite.utils.Themes.isDarkTheme;
|
||||
|
||||
public class SSFS {
|
||||
public static String getSSFSLink() {
|
||||
public class SSFS{
|
||||
public static String getSSFSLink(){
|
||||
return SSFSDomain() + "?token=" + getUserToken() + "&vt_dark=" + getDarkVKUI() + "&vt_amoled=" + getAmoledVKUI() + "&secret=" + getUserSecret() + "&proxy=" + getUserProxy() + "&lang=" + getLocale() + "&vt=1&vksans=" + isVKSansEnabled() + "&vt_version=" + getBuildNumber() + "&vt_debug=" + isDEVModEnabled();
|
||||
}
|
||||
|
||||
public static String SSFSDomain() {
|
||||
public static String SSFSDomain(){
|
||||
String string = getPrefsValue("ssfscustom");
|
||||
|
||||
if (!string.isEmpty()) return string;
|
||||
if(!string.isEmpty()) return string;
|
||||
|
||||
return "https://vtsf.vknext.net";
|
||||
}
|
||||
|
||||
public static String getDarkVKUI() {
|
||||
public static String getDarkVKUI(){
|
||||
return isDarkTheme() ? "1" : "0";
|
||||
}
|
||||
|
||||
public static String getAmoledVKUI() {
|
||||
public static String getAmoledVKUI(){
|
||||
return getPrefsValue("darktheme").equals("amoled") && isDarkTheme() ? "1" : "0";
|
||||
}
|
||||
|
||||
public static String getUserProxy() {
|
||||
public static String getUserProxy(){
|
||||
return proxy() ? "1" : "0";
|
||||
}
|
||||
|
||||
public static String isVKSansEnabled() {
|
||||
public static String isVKSansEnabled(){
|
||||
return vksans() ? "1" : "0";
|
||||
}
|
||||
|
||||
public static String isDEVModEnabled() {
|
||||
public static String isDEVModEnabled(){
|
||||
return dev() ? "1" : "0";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,16 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class SettBackup {
|
||||
public class SettBackup{
|
||||
static SharedPreferences prefs = getContext().getSharedPreferences("com.vtosters.lite_preferences", Context.MODE_PRIVATE);
|
||||
|
||||
public static void deletePrefs() {
|
||||
public static void deletePrefs(){
|
||||
prefs.edit().clear().commit();
|
||||
File file = new File(new File(getContext().getFilesDir().getParent(), "shared_prefs"), "com.vtosters.lite_preferences");
|
||||
if (file.exists()) file.delete();
|
||||
if(file.exists()) file.delete();
|
||||
}
|
||||
|
||||
public static void backupSettings() {
|
||||
public static void backupSettings(){
|
||||
SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault());
|
||||
String currentDateandTime = date.format(new Date());
|
||||
var directory = getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS + "/VTLBackups/") + "/Backup_" + currentDateandTime + ".txt";
|
||||
@@ -36,7 +36,7 @@ public class SettBackup {
|
||||
try {
|
||||
var exists = file.createNewFile();
|
||||
|
||||
if (!exists) {
|
||||
if(!exists){
|
||||
file.delete();
|
||||
file.createNewFile();
|
||||
}
|
||||
@@ -56,13 +56,14 @@ public class SettBackup {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getAllPrefs() {
|
||||
public static String getAllPrefs(){
|
||||
Map<String, ?> allPrefs = prefs.getAll();
|
||||
return Base64.encodeToString(allPrefs.toString().getBytes(), 1);
|
||||
}
|
||||
|
||||
public static void restoreBackup() {
|
||||
File dir = new File(getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS + "/VTLBackups/").getPath());;
|
||||
public static void restoreBackup(){
|
||||
File dir = new File(getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS + "/VTLBackups/").getPath());
|
||||
;
|
||||
// TODO Make restore backup from file list
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import android.content.pm.Signature;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class SignatureChecker {
|
||||
public class SignatureChecker{
|
||||
private static final String APP_SIGNATURE = "QzNFQTI3Q0ExNEJENzJFM0U2QUUyMDM0OTdCNDQ0NUFEQUMxRjk0NQ==";
|
||||
|
||||
public static String getSHA1(byte[] sig) throws NoSuchAlgorithmException{
|
||||
@@ -28,7 +28,7 @@ public class SignatureChecker {
|
||||
'9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
char[] hexChars = new char[bytes.length * 2];
|
||||
int v;
|
||||
for (int j = 0; j < bytes.length; j++) {
|
||||
for(int j = 0; j < bytes.length; j++) {
|
||||
v = bytes[j] & 0xFF;
|
||||
hexChars[j * 2] = hexArray[v >>> 4];
|
||||
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
|
||||
@@ -38,7 +38,7 @@ public class SignatureChecker {
|
||||
|
||||
public static boolean validateAppSignature() throws NameNotFoundException, NoSuchAlgorithmException{
|
||||
@SuppressLint("PackageManagerGetSignatures") PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getPackageName(), GET_SIGNATURES);
|
||||
for (Signature signature : packageInfo.signatures) {
|
||||
for(Signature signature : packageInfo.signatures) {
|
||||
String sha1 = getSHA1(signature.toByteArray());
|
||||
return decode(APP_SIGNATURE).equals(sha1);
|
||||
}
|
||||
|
||||
@@ -3,19 +3,16 @@ package ru.vtosters.lite.utils;
|
||||
import static android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
|
||||
import static ru.vtosters.lite.utils.Globals.edit;
|
||||
import static ru.vtosters.lite.utils.Globals.getCenterScreenCoords;
|
||||
import static ru.vtosters.lite.utils.Globals.getContext;
|
||||
import static ru.vtosters.lite.utils.Globals.getCurrentActivity;
|
||||
import static ru.vtosters.lite.utils.Globals.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.Globals.getPrefsValue;
|
||||
import static ru.vtosters.lite.utils.Globals.getResources;
|
||||
import static ru.vtosters.lite.utils.Globals.sendToast;
|
||||
import static ru.vtosters.lite.utils.Preferences.color_grishka;
|
||||
import static ru.vtosters.lite.utils.Preferences.isBGStickersEnabled;
|
||||
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 static ru.vtosters.lite.utils.Preferences.vksans;
|
||||
import static ru.vtosters.lite.utils.ReflectionUtils.*;
|
||||
import static ru.vtosters.lite.utils.VKUIInjector.isLoaded;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
@@ -43,20 +40,19 @@ import com.vk.core.ui.themes.VKThemeHelper;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.data.ThemeTracker;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Themes {
|
||||
public class Themes{
|
||||
public static List<String> accentColors = Arrays.asList(
|
||||
"5692d7", "528bcc", "7aa0cc", "518bcc", "6296d0", "2f68aa", "638ebf", "5181b8", "71aaeb", "4774a8", "5baaf4", "4186c8", "add3ff", "4774a8", "718198", "5a9eff", "99a2ad", "74a2d6", "e9eef3", "dfe3e7", "eff1f3", "5c9ce6", "4986cc", "4680c2"
|
||||
);
|
||||
|
||||
public static void applyTheme(VKTheme theme) {
|
||||
public static void applyTheme(VKTheme theme){
|
||||
VKThemeHelper.theme(theme, getCurrentActivity(), getCenterScreenCoords());
|
||||
} // Apply VKTheme and ImTheme (hard applying without dynamic theme changing)
|
||||
|
||||
public static void setTheme(VKTheme theme, Activity activity) {
|
||||
public static void setTheme(VKTheme theme, Activity activity){
|
||||
if(activity == null) activity = getCurrentActivity();
|
||||
VKThemeHelper.theme(theme, activity, getCenterScreenCoords());
|
||||
ThemeTracker.a();
|
||||
@@ -65,129 +61,129 @@ public class Themes {
|
||||
WebCachePreloader.e();
|
||||
} // apply changed theme
|
||||
|
||||
public static boolean isDarkTheme() {
|
||||
public static boolean isDarkTheme(){
|
||||
return VKThemeHelper.r();
|
||||
}
|
||||
|
||||
public static int getAccentColor() {
|
||||
public static int getAccentColor(){
|
||||
return getColorFromAttr(getAttrId("accent"));
|
||||
} // Color accent
|
||||
|
||||
public static int getTextAttr() {
|
||||
public static int getTextAttr(){
|
||||
return getColorFromAttr(getAttrId("text_primary"));
|
||||
} // Text Primary color
|
||||
|
||||
public static int getSTextAttr() {
|
||||
public static int getSTextAttr(){
|
||||
return getColorFromAttr(getAttrId("text_secondary"));
|
||||
} // Text Secondary color
|
||||
|
||||
public static int getTabbarBackground() {
|
||||
public static int getTabbarBackground(){
|
||||
return getColorFromAttr(getAttrId("tabbar_background"));
|
||||
} // Tabbar/Navbar background
|
||||
|
||||
public static int getBackgroundContent() {
|
||||
public static int getBackgroundContent(){
|
||||
return getColorFromAttr(getAttrId("background_content"));
|
||||
} // Background color in app
|
||||
|
||||
public static int getBackgroundPage() {
|
||||
public static int getBackgroundPage(){
|
||||
return getColorFromAttr(getAttrId("background_page"));
|
||||
} // Background color in app
|
||||
|
||||
public static int getHeaderBackground() {
|
||||
public static int getHeaderBackground(){
|
||||
return getColorFromAttr(getAttrId("header_background"));
|
||||
} // Toolbar/Header background
|
||||
|
||||
public static int getHeaderText() {
|
||||
public static int getHeaderText(){
|
||||
return getColorFromAttr(getAttrId("header_text"));
|
||||
} // Header/Toolbar color text
|
||||
|
||||
public static int getAmoledTheme() {
|
||||
public static int getAmoledTheme(){
|
||||
return getIdentifier("BaseAmoledStyle", "style");
|
||||
} // Get Amoled theme id
|
||||
|
||||
public static int picFix() {
|
||||
public static int picFix(){
|
||||
return getIdentifier("ActionBarThemeFix", "style");
|
||||
} // Fix tabbar color in photo viewer
|
||||
|
||||
public static int getAmoledImTheme() {
|
||||
public static int getAmoledImTheme(){
|
||||
return getIdentifier("VkIm.Theme.VkApp.Amoled", "style");
|
||||
} // Get Amoled theme id for messages
|
||||
|
||||
public static int getAmoledMeTheme() {
|
||||
public static int getAmoledMeTheme(){
|
||||
return getIdentifier("VkIm.Theme.VkMe.Amoled", "style");
|
||||
} // Get Amoled theme id for messages with rounded msg
|
||||
|
||||
public static int getAttrId(String attr) {
|
||||
public static int getAttrId(String attr){
|
||||
return getIdentifier(attr, "attr");
|
||||
}
|
||||
|
||||
public static void setBarTheme(View getview) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
public static void setBarTheme(View getview){
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
|
||||
getview.setSystemUiVisibility(getNeededColorNavbar() | getNeededColorStatusbar());
|
||||
}
|
||||
} // Set white/dark statusbar/navbar icons
|
||||
|
||||
public static int getNeededColorStatusbar() {
|
||||
public static int getNeededColorStatusbar(){
|
||||
return !isDarkTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? 8192 : 0;
|
||||
}
|
||||
|
||||
public static int getNeededColorNavbar() {
|
||||
public static int getNeededColorNavbar(){
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? isDarkTheme() ? SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR : 0 : 0;
|
||||
}
|
||||
|
||||
public static int getNeededColorStatusbarFix() {
|
||||
public static int getNeededColorStatusbarFix(){
|
||||
return VKThemeHelper.r() ? 8192 : 0;
|
||||
}
|
||||
|
||||
public static VKTheme getDarkTheme() {
|
||||
switch (getPrefsValue("darktheme")) {
|
||||
public static VKTheme getDarkTheme(){
|
||||
switch(getPrefsValue("darktheme")) {
|
||||
//case "amoled":
|
||||
//return VKTheme.AMOLED;
|
||||
//return VKTheme.AMOLED;
|
||||
default:
|
||||
return isMilkshake()? VKTheme.VKAPP_MILK_DARK : VKTheme.VKAPP_DARK;
|
||||
return isMilkshake() ? VKTheme.VKAPP_MILK_DARK : VKTheme.VKAPP_DARK;
|
||||
}
|
||||
} // Return needed theme for theme changer
|
||||
|
||||
public static VKTheme getLightTheme() {
|
||||
switch (getPrefsValue("lighttheme")) {
|
||||
public static VKTheme getLightTheme(){
|
||||
switch(getPrefsValue("lighttheme")) {
|
||||
default:
|
||||
return isMilkshake()? VKTheme.VKAPP_MILK_LIGHT : VKTheme.VKAPP_LIGHT;
|
||||
return isMilkshake() ? VKTheme.VKAPP_MILK_LIGHT : VKTheme.VKAPP_LIGHT;
|
||||
}
|
||||
} // Return needed theme for theme changer
|
||||
|
||||
public static int getColorFromAttr(int attr) {
|
||||
public static int getColorFromAttr(int attr){
|
||||
return VKThemeHelper.d(attr);
|
||||
} // Get needed attr color
|
||||
|
||||
public static boolean isAndroidMonet() {
|
||||
public static boolean isAndroidMonet(){
|
||||
return color_grishka() && Build.VERSION.SDK_INT >= 31;
|
||||
}
|
||||
|
||||
public static boolean isMilkshake() {
|
||||
public static boolean isMilkshake(){
|
||||
return MilkshakeHelper.e();
|
||||
}
|
||||
|
||||
public static boolean isColorRefAccented(int color) {
|
||||
for (int accent : new int[]{R.color.accent_blue, R.color.azure_A400, R.color.blue, R.color.blue_200, R.color.blue_200_muted, R.color.blue_300, R.color.blue_400, R.color.cool_blue, R.color.cornflower_blue, R.color.cornflower_blue_two, R.color.dot_unread, R.color.fave_promo_btn_pressed, R.color.header_blue, R.color.vkim_ripple_dark, R.color.colorAccent, R.color.light_blue, R.color.light_blue_gray, R.color.live_emoji_butt_hide, R.color.music_action_button_blue, R.color.name, R.color.picker_blue, R.color.picker_blue_pressed, R.color.picker_tab_bg_selected, R.color.picker_tab_text_selected, R.color.sharing_blue_btn_normal, R.color.sharing_blue_btn_pressed, R.color.sky_300, R.color.text_blue, R.color.tip_background, R.color.tw__blue_default, R.color.tw__blue_pressed, R.color.vkim_msg_sending_ic, R.color.vkim_playing_drawable_rect, R.color.white_blue32}) {
|
||||
public static boolean isColorRefAccented(int color){
|
||||
for(int accent : new int[]{R.color.accent_blue, R.color.azure_A400, R.color.blue, R.color.blue_200, R.color.blue_200_muted, R.color.blue_300, R.color.blue_400, R.color.cool_blue, R.color.cornflower_blue, R.color.cornflower_blue_two, R.color.dot_unread, R.color.fave_promo_btn_pressed, R.color.header_blue, R.color.vkim_ripple_dark, R.color.colorAccent, R.color.light_blue, R.color.light_blue_gray, R.color.live_emoji_butt_hide, R.color.music_action_button_blue, R.color.name, R.color.picker_blue, R.color.picker_blue_pressed, R.color.picker_tab_bg_selected, R.color.picker_tab_text_selected, R.color.sharing_blue_btn_normal, R.color.sharing_blue_btn_pressed, R.color.sky_300, R.color.text_blue, R.color.tip_background, R.color.tw__blue_default, R.color.tw__blue_pressed, R.color.vkim_msg_sending_ic, R.color.vkim_playing_drawable_rect, R.color.white_blue32}) {
|
||||
if(color == accent) return true;
|
||||
}
|
||||
return false;
|
||||
} // Accent colors
|
||||
|
||||
public static void themeMonetToolbar(ImageButton imageButton, Toolbar toolbar) {
|
||||
public static void themeMonetToolbar(ImageButton imageButton, Toolbar toolbar){
|
||||
imageButton.setImageTintList(ColorStateList.valueOf(getHeaderText()));
|
||||
toolbar.setElevation(0.0f);
|
||||
}
|
||||
|
||||
public static Drawable recolorDrawable(Drawable drawable) {
|
||||
if (drawable == null) return null;
|
||||
public static Drawable recolorDrawable(Drawable drawable){
|
||||
if(drawable == null) return null;
|
||||
return new RecoloredDrawable(drawable, getAccentColor());
|
||||
} // Recolor drawable to accent color
|
||||
|
||||
public static Drawable recolorVKIconMenu(Drawable drawable) {
|
||||
public static Drawable recolorVKIconMenu(Drawable drawable){
|
||||
int accent = getHeaderText();
|
||||
|
||||
if (drawable == null) return null;
|
||||
if(drawable == null) return null;
|
||||
|
||||
if(isAndroidMonet() || isDarkTheme()) accent = getAccentColor();
|
||||
|
||||
@@ -195,8 +191,8 @@ public class Themes {
|
||||
} // Recolor vk icon to accent color
|
||||
|
||||
|
||||
public static Drawable recolorDrawableToolbar(Drawable drawable) {
|
||||
if (drawable == null) return null;
|
||||
public static Drawable recolorDrawableToolbar(Drawable drawable){
|
||||
if(drawable == null) return null;
|
||||
|
||||
if(!isAndroidMonet()) return drawable;
|
||||
|
||||
@@ -204,15 +200,15 @@ public class Themes {
|
||||
} // Recolor toolbar drawable to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public static Drawable recolorDrawableInt(int drawable) {
|
||||
public static Drawable recolorDrawableInt(int drawable){
|
||||
if(!isAndroidMonet()) return getResources().getDrawable(drawable);
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables") Drawable res = getResources().getDrawable(drawable);
|
||||
return new RecoloredDrawable(res, getAccentColor());
|
||||
} // Get res drawable via id and coloring to accent
|
||||
|
||||
public static ColorStateList recolorCSL(ColorStateList colorStateList) {
|
||||
if (colorStateList == null) return null;
|
||||
public static ColorStateList recolorCSL(ColorStateList colorStateList){
|
||||
if(colorStateList == null) return null;
|
||||
|
||||
if(!isAndroidMonet()) return colorStateList;
|
||||
|
||||
@@ -220,15 +216,15 @@ public class Themes {
|
||||
} // Recolor ColorStateList to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForColorStateLists")
|
||||
public static ColorStateList themeCSL(Context context, int color) {
|
||||
public static ColorStateList themeCSL(Context context, int color){
|
||||
|
||||
if (isColorRefAccented(color) && isAndroidMonet()) {
|
||||
if(isColorRefAccented(color) && isAndroidMonet()){
|
||||
return ColorStateList.valueOf(getAccentColor());
|
||||
}
|
||||
|
||||
ColorStateList csl;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
if(Build.VERSION.SDK_INT >= 23){
|
||||
csl = context.getColorStateList(color);
|
||||
} else {
|
||||
csl = context.getResources().getColorStateList(color);
|
||||
@@ -241,11 +237,11 @@ public class Themes {
|
||||
boolean isUnselAccent = isAccentedColor(unsel);
|
||||
boolean isSelAccent = isAccentedColor(sel);
|
||||
|
||||
if (isUnselAccent || isSelAccent) {
|
||||
if(isUnselAccent || isSelAccent){
|
||||
|
||||
return new ColorStateList(new int[][] {
|
||||
return new ColorStateList(new int[][]{
|
||||
new int[]{android.R.attr.state_selected}, new int[]{-android.R.attr.state_selected}
|
||||
}, new int[] {isSelAccent ? getAccentColor() : sel, isUnselAccent ? getAccentColor() : unsel});
|
||||
}, new int[]{isSelAccent ? getAccentColor() : sel, isUnselAccent ? getAccentColor() : unsel});
|
||||
}
|
||||
|
||||
return csl;
|
||||
@@ -256,7 +252,7 @@ public class Themes {
|
||||
}
|
||||
} // Recolor ColorStateList
|
||||
|
||||
public static int darken(int color, float by) {
|
||||
public static int darken(int color, float by){
|
||||
float[] hsl = new float[3];
|
||||
ColorUtils.colorToHSL(color, hsl);
|
||||
hsl[2] -= by;
|
||||
@@ -264,124 +260,120 @@ public class Themes {
|
||||
return ColorUtils.HSLToColor(hsl);
|
||||
}
|
||||
|
||||
public static int lighten(int color, float factor) {
|
||||
public static int lighten(int color, float factor){
|
||||
int red = (int) ((Color.red(color) * (1 - factor) / 255 + factor) * 255);
|
||||
int green = (int) ((Color.green(color) * (1 - factor) / 255 + factor) * 255);
|
||||
int blue = (int) ((Color.blue(color) * (1 - factor) / 255 + factor) * 255);
|
||||
return Color.argb(Color.alpha(color), red, green, blue);
|
||||
}
|
||||
|
||||
public static int fixTextColor(int resid) {
|
||||
if (resid == R.color.music_action_button_gray || resid == R.color.cool_grey || resid == R.color.accent_blue){
|
||||
return isDarkTheme()? R.color.white : R.color.cool_grey;
|
||||
public static int fixTextColor(int resid){
|
||||
if(resid == R.color.music_action_button_gray || resid == R.color.cool_grey || resid == R.color.accent_blue){
|
||||
return isDarkTheme() ? R.color.white : R.color.cool_grey;
|
||||
}
|
||||
return resid;
|
||||
}
|
||||
|
||||
public static int halfAlpha(int src) {
|
||||
public static int halfAlpha(int src){
|
||||
return ColorUtils.setAlphaComponent(src, 169);
|
||||
}
|
||||
|
||||
public static boolean isAccentedColor(ColorStateList target) {
|
||||
public static boolean isAccentedColor(ColorStateList target){
|
||||
return target != null && isAccentedColor(target.getDefaultColor());
|
||||
}
|
||||
|
||||
public static boolean isAccentedColor(int target) {
|
||||
public static boolean isAccentedColor(int target){
|
||||
return accentColors.contains(hex(target).toLowerCase());
|
||||
}
|
||||
|
||||
public static int getColor(Context context, int i) {
|
||||
if (isColorRefAccented(i) && isAndroidMonet()) {
|
||||
public static int getColor(Context context, int i){
|
||||
if(isColorRefAccented(i) && isAndroidMonet()){
|
||||
return getAccentColor();
|
||||
}
|
||||
return context.getColor(i);
|
||||
} // Android Support color injector + accent color checker
|
||||
|
||||
public static int getColor2(int i) {
|
||||
if (isColorRefAccented(i) && isAndroidMonet()) {
|
||||
public static int getColor2(int i){
|
||||
if(isColorRefAccented(i) && isAndroidMonet()){
|
||||
return getAccentColor();
|
||||
}
|
||||
return getResources().getColor(i);
|
||||
} // Android Support color injector + accent color checker
|
||||
|
||||
public static void setNavbarColor(Window window, int i) {
|
||||
if (navbar()) {
|
||||
public static void setNavbarColor(Window window, int i){
|
||||
if(navbar()){
|
||||
window.setNavigationBarColor(getTabbarBackground());
|
||||
window.getDecorView().setSystemUiVisibility(getNeededColorNavbar());
|
||||
}
|
||||
}
|
||||
|
||||
public static String hex(int i) {
|
||||
public static String hex(int i){
|
||||
return String.format("#%06X", Integer.valueOf(i & 16777215));
|
||||
} // Get color as hex string
|
||||
|
||||
public static int vk_sans_display_demibold() {
|
||||
public static int vk_sans_display_demibold(){
|
||||
return vksans() ? R.font.vk_sans_display_demibold : R.font.tt_commons_demi_bold;
|
||||
}
|
||||
|
||||
public static int vk_sans_text_black() {
|
||||
public static int vk_sans_text_black(){
|
||||
return vksans() ? R.font.vk_sans_display_bold : R.font.roboto_black;
|
||||
}
|
||||
|
||||
public static int vk_sans_text_bold() {
|
||||
public static int vk_sans_text_bold(){
|
||||
return vksans() ? R.font.vk_sans_text_bold : R.font.roboto_bold;
|
||||
}
|
||||
|
||||
public static int vk_sans_text_demibold() {
|
||||
public static int vk_sans_text_demibold(){
|
||||
return vksans() ? R.font.vk_sans_text_demibold : R.font.roboto_bold_italic;
|
||||
}
|
||||
|
||||
public static int vk_sans_text_light() {
|
||||
public static int vk_sans_text_light(){
|
||||
return vksans() ? R.font.vk_sans_text_light : R.font.roboto_light;
|
||||
}
|
||||
|
||||
public static int vk_sans_text_medium() {
|
||||
public static int vk_sans_text_medium(){
|
||||
return vksans() ? R.font.vk_sans_text_medium : R.font.roboto_medium;
|
||||
}
|
||||
|
||||
public static int vk_sans_text_regular() {
|
||||
public static int vk_sans_text_regular(){
|
||||
return vksans() ? R.font.vk_sans_text_regular : R.font.roboto_regular;
|
||||
}
|
||||
|
||||
public static String getBackgroundStickers() {
|
||||
if (isBGStickersEnabled()) {
|
||||
public static String getBackgroundStickers(){
|
||||
if(isBGStickersEnabled()){
|
||||
return "images_with_background";
|
||||
}
|
||||
return "images";
|
||||
}
|
||||
|
||||
public static int getNavigationHeight(int Default) {
|
||||
public static int getNavigationHeight(int Default){
|
||||
int VKME = R.dimen.design_bottom_sheet_peek_height_min;
|
||||
|
||||
return vkme()? VKME : Default;
|
||||
return vkme() ? VKME : Default;
|
||||
}
|
||||
|
||||
public static int getNavigationWidth(int Default) {
|
||||
public static int getNavigationWidth(int Default){
|
||||
int VKME = R.dimen.app_minimumsize_h;
|
||||
|
||||
return vkme()? VKME : Default;
|
||||
return vkme() ? VKME : Default;
|
||||
}
|
||||
|
||||
private void getCurrentThemeID(VKTheme paramVKTheme) {
|
||||
Preference.b("vk_theme_helper", "current_theme", paramVKTheme.getId());
|
||||
}
|
||||
|
||||
public static void systemThemeChanger(Activity activity) { // ded
|
||||
public static void systemThemeChanger(Activity activity){ // ded
|
||||
boolean isDarkTheme = isDarkTheme();
|
||||
|
||||
if (!isDarkTheme){
|
||||
if(!isDarkTheme){
|
||||
applyTheme(getDarkTheme());
|
||||
} else {
|
||||
applyTheme(getLightTheme());
|
||||
}
|
||||
|
||||
if (!systemtheme()){
|
||||
if(!systemtheme()){
|
||||
edit().putBoolean("isdark", isDarkTheme).commit();
|
||||
return;
|
||||
}
|
||||
|
||||
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
switch (currentNightMode) {
|
||||
switch(currentNightMode) {
|
||||
case Configuration.UI_MODE_NIGHT_UNDEFINED:
|
||||
case Configuration.UI_MODE_NIGHT_NO:
|
||||
edit().putBoolean("isdark", false).commit();
|
||||
@@ -393,4 +385,8 @@ public class Themes {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void getCurrentThemeID(VKTheme paramVKTheme){
|
||||
Preference.b("vk_theme_helper", "current_theme", paramVKTheme.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import static ru.vtosters.lite.utils.Preferences.superapp;
|
||||
import com.vk.toggle.FeatureManager;
|
||||
import com.vk.toggle.Features;
|
||||
|
||||
public class Toggles {
|
||||
public class Toggles{
|
||||
public static boolean redirect(Features.Type feature){
|
||||
switch (feature) {
|
||||
switch(feature) {
|
||||
case EXPERIMENT_NEWS_DISABLE_CACHE:
|
||||
return feedcache();
|
||||
case FEATURE_SUPERAPP_MENU:
|
||||
|
||||
@@ -7,7 +7,6 @@ import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Themes.getAccentColor;
|
||||
import static ru.vtosters.lite.utils.Themes.getBackgroundContent;
|
||||
import static ru.vtosters.lite.utils.Themes.getBackgroundPage;
|
||||
import static ru.vtosters.lite.utils.Themes.getColorFromAttr;
|
||||
import static ru.vtosters.lite.utils.Themes.getHeaderBackground;
|
||||
import static ru.vtosters.lite.utils.Themes.getHeaderText;
|
||||
import static ru.vtosters.lite.utils.Themes.getTextAttr;
|
||||
@@ -15,29 +14,27 @@ import static ru.vtosters.lite.utils.Themes.hex;
|
||||
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class VKUIInjector {
|
||||
public class VKUIInjector{
|
||||
public static boolean isLoaded = false;
|
||||
private static String loadedCSS = "";
|
||||
private static String loadedCSSAmoled = "";
|
||||
|
||||
private static String load(String str) {
|
||||
private static String load(String str){
|
||||
try {
|
||||
InputStream open = getContext().getAssets().open(str);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(open, StandardCharsets.UTF_8));
|
||||
|
||||
while (true) {
|
||||
while(true) {
|
||||
String readLine = bufferedReader.readLine();
|
||||
if (readLine != null) {
|
||||
if(readLine != null){
|
||||
sb.append(readLine);
|
||||
} else {
|
||||
bufferedReader.close();
|
||||
@@ -52,7 +49,7 @@ public class VKUIInjector {
|
||||
}
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
public static void load(){
|
||||
loadedCSS = load("vt_ui_accent.css")
|
||||
.replace("%header_background%", hex(getHeaderBackground()))
|
||||
.replace("%background_content%", hex(getBackgroundContent()))
|
||||
@@ -65,27 +62,27 @@ public class VKUIInjector {
|
||||
isLoaded = true;
|
||||
}
|
||||
|
||||
private static void inject(WebView webView, String str) {
|
||||
private static void inject(WebView webView, String str){
|
||||
webView.loadUrl("javascript:(function() {var parent = document.getElementsByTagName('head').item(0);var style = document.createElement('style');style.type = 'text/css';style.innerHTML = window.atob('" + str + "');parent.appendChild(style)})()");
|
||||
}
|
||||
|
||||
public static void inject(WebView webView) {
|
||||
public static void inject(WebView webView){
|
||||
String string = getPrefsValue("darktheme");
|
||||
|
||||
if (getBoolValue("VKUI_INJ", true)) {
|
||||
if(getBoolValue("VKUI_INJ", true)){
|
||||
|
||||
if (!isLoaded) {
|
||||
if(!isLoaded){
|
||||
load();
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (true/*Themes.isAccentedCache()*/) {
|
||||
if(true/*Themes.isAccentedCache()*/){
|
||||
sb.append("\n\n");
|
||||
sb.append(loadedCSS);
|
||||
}
|
||||
|
||||
if (string.equals("amoled")) {
|
||||
if(string.equals("amoled")){
|
||||
sb.append("\n\n");
|
||||
sb.append(loadedCSSAmoled);
|
||||
}
|
||||
|
||||
@@ -7,15 +7,9 @@ import com.vk.core.util.LangUtils;
|
||||
import com.vk.core.util.UriExt;
|
||||
import com.vk.webapp.VkUiFragment;
|
||||
|
||||
public final class VKUIwrapper extends VkUiFragment {
|
||||
public final class VKUIwrapper extends VkUiFragment{
|
||||
static String link;
|
||||
|
||||
public void onCreate(Bundle bundle){
|
||||
VKUIwrapper.super.onCreate(bundle);
|
||||
|
||||
N(link);
|
||||
}
|
||||
|
||||
public static void setLink(String getlink){
|
||||
link = getlink;
|
||||
}
|
||||
@@ -25,4 +19,10 @@ public final class VKUIwrapper extends VkUiFragment {
|
||||
Uri.Builder appendQueryParameter = UriExt.a(appendPath).appendQueryParameter("lang", LangUtils.a());
|
||||
link = appendQueryParameter.build().toString();
|
||||
}
|
||||
|
||||
public void onCreate(Bundle bundle){
|
||||
VKUIwrapper.super.onCreate(bundle);
|
||||
|
||||
N(link);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user