Skip to content

Commit

Permalink
Merge pull request #151 from nikitasius/noshit_9.3.3
Browse files Browse the repository at this point in the history
Telegraher 9.33.28
  • Loading branch information
nikitasius authored Jan 27, 2023
2 parents 98e9559 + 40e3df7 commit f5eb6c4
Show file tree
Hide file tree
Showing 24 changed files with 195 additions and 310 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/Dockerfile_bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
asset_name: ${{ env.ANAME }}${{ env.AARCH }}.apk
asset_content_type: application/gzip
env:
RNAME: Telegraher 9.33.27
TNAME: graher_9.33.27_
ANAME: Telegraher.9.33.27.
RNAME: Telegraher 9.33.28
TNAME: graher_9.33.28_
ANAME: Telegraher.9.33.28.
AARCH: bundle
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ different)
* Realeases are
here: [https://github.com/nikitasius/Telegraher/releases](https://github.com/nikitasius/Telegraher/releases)
* if it contain `beta` it mean it's BETA
* Last release `9.33.27`: [bundle](https://github.com/nikitasius/Telegraher/releases/tag/graher_9.33.27_bundle)
* Last release `9.33.28`: [bundle](https://github.com/nikitasius/Telegraher/releases/tag/graher_9.33.28_bundle)
* Last beta: write `!beta` in chat

### Issues/Wishlist
Expand Down
6 changes: 6 additions & 0 deletions README_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changes

* 9.33.28
* removing memory leaks
* "optimise the code"
* removing old shit from early years also
* wanted to remove conditions about SDK <=19 (or even less).. damn there are hungreds of these cases, let TG clean
their code (it doesn't seriosly affect perfomance, just code keep legacy shit over the years).
* 9.33.27
* everyone can enable blur, it's disabled by default now
* auto-nigth settings are disabled by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ private void onTextDetailCellImageClicked(View view) {
private void killThatApp() {
if (Build.VERSION.SDK_INT >= 21) {
getParentActivity().finishAndRemoveTask();
} else if (Build.VERSION.SDK_INT >= 16) {
} else if (Build.VERSION.SDK_INT >= 19) {
getParentActivity().finishAffinity();
}
System.exit(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,15 +915,16 @@ private void deleteRow(SQLiteDatabase writableDatabase, int key) {

private void addOrUpdateRow(SQLiteDatabase writableDatabase, CachedContent cachedContent)
throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
writeContentMetadata(cachedContent.getMetadata(), new DataOutputStream(outputStream));
byte[] data = outputStream.toByteArray();

ContentValues values = new ContentValues();
values.put(COLUMN_ID, cachedContent.id);
values.put(COLUMN_KEY, cachedContent.key);
values.put(COLUMN_METADATA, data);
writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values);
try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
writeContentMetadata(cachedContent.getMetadata(), new DataOutputStream(outputStream));
byte[] data = outputStream.toByteArray();

ContentValues values = new ContentValues();
values.put(COLUMN_ID, cachedContent.id);
values.put(COLUMN_KEY, cachedContent.key);
values.put(COLUMN_METADATA, data);
writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values);
}
}

private static void delete(DatabaseProvider databaseProvider, String hexUid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ public PhoneFormat(String countryCode) {
}

public void init(String countryCode) {
InputStream stream = null;
ByteArrayOutputStream bos = null;
try {
stream = ApplicationLoader.applicationContext.getAssets().open("PhoneFormats.dat");
bos = new ByteArrayOutputStream();
try (InputStream stream = ApplicationLoader.applicationContext.getAssets().open("PhoneFormats.dat"); ByteArrayOutputStream bos = new ByteArrayOutputStream()){
byte[] buf = new byte[1024];
int len;
while ((len = stream.read(buf, 0, 1024)) != -1) {
Expand All @@ -115,23 +111,9 @@ public void init(String countryCode) {
buffer = ByteBuffer.wrap(data);
buffer.order(ByteOrder.LITTLE_ENDIAN);
} catch (Exception e) {
FileLog.e(e);
e.printStackTrace();
return;
} finally {
try {
if (bos != null) {
bos.close();
}
} catch (Exception e) {
FileLog.e(e);
}
try {
if (stream != null) {
stream.close();
}
} catch (Exception e) {
FileLog.e(e);
}
}

if (countryCode != null && countryCode.length() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1757,20 +1757,18 @@ public static void hideKeyboard(View view) {

public static ArrayList<File> getDataDirs() {
ArrayList<File> result = null;
if (Build.VERSION.SDK_INT >= 19) {
File[] dirs = ApplicationLoader.applicationContext.getExternalFilesDirs(null);
if (dirs != null) {
for (int a = 0; a < dirs.length; a++) {
if (dirs[a] == null) {
continue;
}
String path = dirs[a].getAbsolutePath();
File[] dirs = ApplicationLoader.applicationContext.getExternalFilesDirs(null);
if (dirs != null) {
for (int a = 0; a < dirs.length; a++) {
if (dirs[a] == null) {
continue;
}
String path = dirs[a].getAbsolutePath();

if (result == null) {
result = new ArrayList<>();
}
result.add(dirs[a]);
if (result == null) {
result = new ArrayList<>();
}
result.add(dirs[a]);
}
}
if (result == null) {
Expand All @@ -1784,21 +1782,19 @@ public static ArrayList<File> getDataDirs() {

public static ArrayList<File> getRootDirs() {
ArrayList<File> result = null;
if (Build.VERSION.SDK_INT >= 19) {
File[] dirs = ApplicationLoader.applicationContext.getExternalFilesDirs(null);
if (dirs != null) {
for (int a = 0; a < dirs.length; a++) {
if (dirs[a] == null) {
continue;
}
String path = dirs[a].getAbsolutePath();
int idx = path.indexOf("/Android");
if (idx >= 0) {
if (result == null) {
result = new ArrayList<>();
}
result.add(new File(path.substring(0, idx)));
File[] dirs = ApplicationLoader.applicationContext.getExternalFilesDirs(null);
if (dirs != null) {
for (int a = 0; a < dirs.length; a++) {
if (dirs[a] == null) {
continue;
}
String path = dirs[a].getAbsolutePath();
int idx = path.indexOf("/Android");
if (idx >= 0) {
if (result == null) {
result = new ArrayList<>();
}
result.add(new File(path.substring(0, idx)));
}
}
}
Expand All @@ -1821,19 +1817,15 @@ public static File getCacheDir() {
if (state == null || state.startsWith(Environment.MEDIA_MOUNTED)) {
try {
File file;
if (Build.VERSION.SDK_INT >= 19) {
File[] dirs = ApplicationLoader.applicationContext.getExternalCacheDirs();
file = dirs[0];
if (!TextUtils.isEmpty(SharedConfig.storageCacheDir)) {
for (int a = 0; a < dirs.length; a++) {
if (dirs[a] != null && dirs[a].getAbsolutePath().startsWith(SharedConfig.storageCacheDir)) {
file = dirs[a];
break;
}
File[] dirs = ApplicationLoader.applicationContext.getExternalCacheDirs();
file = dirs[0];
if (!TextUtils.isEmpty(SharedConfig.storageCacheDir)) {
for (int a = 0; a < dirs.length; a++) {
if (dirs[a] != null && dirs[a].getAbsolutePath().startsWith(SharedConfig.storageCacheDir)) {
file = dirs[a];
break;
}
}
} else {
file = ApplicationLoader.applicationContext.getExternalCacheDir();
}
if (file != null) {
return file;
Expand Down Expand Up @@ -3074,29 +3066,27 @@ public static byte[] decodeQuotedPrintable(final byte[] bytes) {
if (bytes == null) {
return null;
}
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
for (int i = 0; i < bytes.length; i++) {
final int b = bytes[i];
if (b == '=') {
try {
final int u = Character.digit((char) bytes[++i], 16);
final int l = Character.digit((char) bytes[++i], 16);
buffer.write((char) ((u << 4) + l));
} catch (Exception e) {
FileLog.e(e);
return null;
try (final ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {
for (int i = 0; i < bytes.length; i++) {
final int b = bytes[i];
if (b == '=') {
try {
final int u = Character.digit((char) bytes[++i], 16);
final int l = Character.digit((char) bytes[++i], 16);
buffer.write((char) ((u << 4) + l));
} catch (Exception e) {
FileLog.e(e);
return null;
}
} else {
buffer.write(b);
}
} else {
buffer.write(b);
}
}
byte[] array = buffer.toByteArray();
try {
buffer.close();
return buffer.toByteArray();
} catch (Exception e) {
FileLog.e(e);
}
return array;
return null;
}

public static boolean copyFile(InputStream sourceFile, File destFile) throws IOException {
Expand Down
49 changes: 16 additions & 33 deletions TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,9 @@ public void run() {
originalBitmap = scaledBitmap;
}
}
FileOutputStream stream = new FileOutputStream(thumbFile);
originalBitmap.compress(Bitmap.CompressFormat.JPEG, info.big ? 83 : 60, stream);
try {
stream.close();

try (FileOutputStream stream = new FileOutputStream(thumbFile)){
originalBitmap.compress(Bitmap.CompressFormat.JPEG, info.big ? 83 : 60, stream);
} catch (Exception e) {
FileLog.e(e);
}
Expand Down Expand Up @@ -3561,10 +3560,8 @@ public static boolean shouldSendImageAsDocument(String path, Uri uri) {
public static Bitmap loadBitmap(String path, Uri uri, float maxWidth, float maxHeight, boolean useMaxScale) {
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
InputStream inputStream = null;

if (path == null && uri != null && uri.getScheme() != null) {
String imageFilePath = null;
if (uri.getScheme().contains("file")) {
path = uri.getPath();
} else if (Build.VERSION.SDK_INT < 30 || !"content".equals(uri.getScheme())) {
Expand All @@ -3579,12 +3576,8 @@ public static Bitmap loadBitmap(String path, Uri uri, float maxWidth, float maxH
if (path != null) {
BitmapFactory.decodeFile(path, bmOptions);
} else if (uri != null) {
boolean error = false;
try {
inputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
try (InputStream inputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri)){
BitmapFactory.decodeStream(inputStream, null, bmOptions);
inputStream.close();
inputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
} catch (Throwable e) {
FileLog.e(e);
return null;
Expand Down Expand Up @@ -3683,7 +3676,7 @@ public static Bitmap loadBitmap(String path, Uri uri, float maxWidth, float maxH
}
}
} else if (uri != null) {
try {
try (InputStream inputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri)){
b = BitmapFactory.decodeStream(inputStream, null, bmOptions);
if (b != null) {
if (bmOptions.inPurgeable) {
Expand All @@ -3697,12 +3690,6 @@ public static Bitmap loadBitmap(String path, Uri uri, float maxWidth, float maxH
}
} catch (Throwable e) {
FileLog.e(e);
} finally {
try {
inputStream.close();
} catch (Throwable e) {
FileLog.e(e);
}
}
}

Expand Down Expand Up @@ -3770,23 +3757,19 @@ private static TLRPC.PhotoSize scaleAndSaveImageInternal(TLRPC.PhotoSize photoSi
fileDir = location.volume_id != Integer.MIN_VALUE ? FileLoader.getDirectory(FileLoader.MEDIA_DIR_IMAGE) : FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
}
final File cacheFile = new File(fileDir, fileName);
//TODO was crash in DEBUG_PRIVATE
// if (compressFormat == Bitmap.CompressFormat.JPEG && progressive && BuildVars.DEBUG_VERSION) {
// photoSize.size = Utilities.saveProgressiveJpeg(scaledBitmap, scaledBitmap.getWidth(), scaledBitmap.getHeight(), scaledBitmap.getRowBytes(), quality, cacheFile.getAbsolutePath());
// } else {
FileOutputStream stream = new FileOutputStream(cacheFile);
scaledBitmap.compress(compressFormat, quality, stream);
if (!cache) {
photoSize.size = (int) stream.getChannel().size();
}
stream.close();
try(FileOutputStream stream = new FileOutputStream(cacheFile)) {
scaledBitmap.compress(compressFormat, quality, stream);
if (!cache) {
photoSize.size = (int) stream.getChannel().size();
}
}
// }
if (cache) {
ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
scaledBitmap.compress(compressFormat, quality, stream2);
photoSize.bytes = stream2.toByteArray();
photoSize.size = photoSize.bytes.length;
stream2.close();
try(ByteArrayOutputStream stream2 = new ByteArrayOutputStream()) {
scaledBitmap.compress(compressFormat, quality, stream2);
photoSize.bytes = stream2.toByteArray();
photoSize.size = photoSize.bytes.length;
}
}
if (scaledBitmap != bitmap) {
scaledBitmap.recycle();
Expand Down
Loading

0 comments on commit f5eb6c4

Please sign in to comment.