From 6cbe7caec1cd6830953c5f531910019190249ae1 Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Thu, 18 Aug 2022 23:22:48 +0300 Subject: [PATCH] added compressing of wallpaper speedup chat open fix crash if file is too large --- .../lite/ui/wallpapers/WallpapersHooks.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpapersHooks.java b/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpapersHooks.java index 5973bc042..d512711cc 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpapersHooks.java +++ b/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpapersHooks.java @@ -10,11 +10,16 @@ import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext; import static ru.vtosters.lite.utils.AndroidUtils.getPreferences; import static ru.vtosters.lite.utils.Preferences.hasVerification; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.view.View; import android.widget.ImageView; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; import ru.vtosters.lite.utils.AndroidUtils; @@ -25,7 +30,28 @@ public class WallpapersHooks { private static boolean mUpdateWallpaperRequested = true; public static File getWallpaperFile() { - return mWallpaperFile == null ? mWallpaperFile = new File(getGlobalContext().getFilesDir(), "wallpaper.png") : mWallpaperFile; + return mWallpaperFile == null ? mWallpaperFile = compressFile(new File(getGlobalContext().getFilesDir(), "wallpaper.png")) : mWallpaperFile; + } + + public static File compressFile(File file) { + Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); + File compressedFile = new File(file.getParent(), file.getName()); + OutputStream out = null; + try { + out = new FileOutputStream(compressedFile); + bitmap.compress(Bitmap.CompressFormat.PNG, 95, out); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (out != null) { + out.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return compressedFile; } public static void setBg(View view) {