codesyle cringe

This commit is contained in:
gdlbo
2022-07-11 21:14:02 +03:00
parent 5bd52c23ae
commit 4d719e4308
87 changed files with 825 additions and 833 deletions
@@ -38,7 +38,7 @@ public class NotificationsHelper{
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);
}
@@ -57,7 +57,7 @@ public class NotificationsHelper{
}
public void packDownloadUpdated(TelegramStickersPack pack, int downloadProgress){
if(System.currentTimeMillis() - lastNotificationTime.get() < MIN_TIME_BETWEEN_UPDATE_NOTIFICATIONS)
if (System.currentTimeMillis() - lastNotificationTime.get() < MIN_TIME_BETWEEN_UPDATE_NOTIFICATIONS)
return;
lastNotificationTime.set(System.currentTimeMillis());
@@ -69,7 +69,7 @@ public class NotificationsHelper{
builder.setOngoing(true);
builder.setOnlyAlertOnce(true);
if(downloadingPacksNotificationsIds.containsKey(pack))
if (downloadingPacksNotificationsIds.containsKey(pack))
manager.notify(downloadingPacksNotificationsIds.get(pack), builder.build());
}
@@ -80,12 +80,12 @@ public class NotificationsHelper{
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();
}
@@ -100,7 +100,7 @@ public class NotificationsHelper{
private Notification.Builder commonBuilder(){
var builder = new Notification.Builder(c).setPriority(Notification.PRIORITY_MAX).setSmallIcon(getIdentifier("ic_download_24", "drawable"));
if(oreo()){
if (oreo()) {
builder.setChannelId(NOTIFICATION_CHANNEL_ID);
}
@@ -21,7 +21,7 @@ class PackDeletionTask extends AsyncTask<Void, Void, Boolean>{
protected Boolean doInBackground(Void... voids){
boolean success = true;
for(File f : pack.folder.listFiles()) {
for (File f : pack.folder.listFiles()) {
success = success && f.delete();
}
@@ -42,9 +42,9 @@ public class TelegramStickersPack extends CustomStickersPack{
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);
}
@@ -57,16 +57,16 @@ public class TelegramStickersPack extends CustomStickersPack{
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)
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");
@@ -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;
@@ -79,12 +79,12 @@ public class TelegramStickersService{
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);
});
}
@@ -92,7 +92,7 @@ public class TelegramStickersService{
public void onAllPacksLoaded(ArrayList<TelegramStickersPack> packs){
ready = true;
if(notify){
if (notify) {
notifyActivePacksListChanged();
notifyInactivePacksListChanged();
}
@@ -114,60 +114,60 @@ public class TelegramStickersService{
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){
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){
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){
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(){
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(){
getContext().sendBroadcast(new Intent(StickersFragment.ACTION_RELOAD));
if(listeners.isEmpty())
if (listeners.isEmpty())
return;
for(StickersEventsListener listener : listeners) {
for (StickersEventsListener listener : listeners) {
listener.onInactivePacksListChanged();
}
}
@@ -193,12 +193,12 @@ public class TelegramStickersService{
}
public boolean requestPackDownload(final String id, File packFolder){
if(currentlyDownloading.contains(id)){
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;
@@ -208,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;
@@ -238,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);
@@ -255,7 +255,7 @@ public class TelegramStickersService{
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);
@@ -287,7 +287,7 @@ public class TelegramStickersService{
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);
@@ -299,33 +299,33 @@ public class TelegramStickersService{
}
public void setPackEnabled(final TelegramStickersPack pack, final boolean enabled, final boolean notify){
if(!ready){
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){
if (!ready) {
queuedTasks.add(() -> deletePack(pack));
return;
}
@@ -338,7 +338,7 @@ public class TelegramStickersService{
packs.remove(index);
notifyPackRemoved(pack, index);
if(pack.enabled){
if (pack.enabled) {
activePacks.remove(pack);
notifyActivePacksListChanged();
} else {
@@ -346,7 +346,7 @@ public class TelegramStickersService{
notifyInactivePacksListChanged();
}
if(d)
if (d)
new PackDeletionTask(pack).executeOnExecutor(executor);
}
@@ -355,7 +355,7 @@ public class TelegramStickersService{
}
private void syncPack(final TelegramStickersPack pack){
if(!ready){
if (!ready) {
queuedTasks.add(() -> syncPack(pack));
return;
}
@@ -371,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);
@@ -38,7 +38,7 @@ public class TelegramStickersDbHelper extends SQLiteOpenHelper{
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
if(oldVersion == 1 && newVersion == 2){
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));
}
}
@@ -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;
@@ -115,7 +115,7 @@ public class TelegramStickersDbHelper extends SQLiteOpenHelper{
@Override
protected ArrayList<TelegramStickersPack> doInBackground(Void... voids){
if(readableDb == null)
if (readableDb == null)
loadDatabases();
String sortOrder = TelegramStickersContract.StickersTableEntry.COLUMN_NAME_INDEX + " ASC";
@@ -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();
}
@@ -85,11 +85,11 @@ public class TelegramStickersGrabber{
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();
@@ -104,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;
@@ -121,12 +121,12 @@ public class TelegramStickersGrabber{
@Override
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();
}
@@ -185,8 +185,8 @@ public class TelegramStickersGrabber{
@Override
public void onResponse(NetCall call, NetResponse response) throws IOException{
if(!response.isSuccessful()){
if(response.getData() != null)
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"));
@@ -199,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;
}
@@ -220,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")));
}
@@ -232,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;
}
@@ -255,7 +255,7 @@ 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();
@@ -265,7 +265,7 @@ public class TelegramStickersGrabber{
httpClient.newCall(fileInfoRequest).enqueue(new NetCallback(){
@Override
public void onFailure(NetCall call, IOException e){
if(deathFlag.up())
if (deathFlag.up())
return;
deathFlag.raise();
@@ -276,13 +276,13 @@ public class TelegramStickersGrabber{
@Override
public void onResponse(NetCall call, NetResponse response) throws IOException{
if(deathFlag.up())
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);
@@ -301,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(){
@Override
public void onFailure(NetCall call, IOException e){
if(deathFlag.up())
if (deathFlag.up())
return;
deathFlag.raise();
@@ -319,13 +319,13 @@ public class TelegramStickersGrabber{
@Override
public void onResponse(NetCall call, NetResponse response) throws IOException{
if(deathFlag.up())
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);
@@ -333,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);
@@ -355,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);
@@ -376,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()));
@@ -17,14 +17,14 @@ public class GoalCounter{
}
public synchronized void increase(){
if(++i == goal)
if (++i == goal)
listener.onGoalReached();
Log.d("COUNTER", "G=" + goal + ", I=" + i);
}
public synchronized void increase(int delta){
if((i += delta) == goal)
if ((i += delta) == goal)
listener.onGoalReached();
}