added compressing of wallpaper

speedup chat open
fix crash if file is too large
This commit is contained in:
gdlbo
2022-08-18 23:22:48 +03:00
parent 452b4aa667
commit 6cbe7caec1
@@ -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) {