wallpapers hooks: fix (maybe)

- close outputstream > release dedicated memory
- delete temp file on exit
- improved check"compress" for null
This commit is contained in:
Erik Kiznov
2022-08-26 23:12:48 +05:00
parent d9f03a5d0e
commit f96baa58ac
@@ -73,8 +73,10 @@ public class WallpapersHooks {
inputStream.close(); inputStream.close();
File outPutFile = File.createTempFile("wallpaper_temp","image"); File outPutFile = File.createTempFile("wallpaper_temp","image");
outPutFile.deleteOnExit();
FileOutputStream outputStream = new FileOutputStream(outPutFile); FileOutputStream outputStream = new FileOutputStream(outPutFile);
selectedBitmap.compress(Bitmap.CompressFormat.PNG, 85 , outputStream); selectedBitmap.compress(Bitmap.CompressFormat.PNG, 85 , outputStream);
outputStream.close();
return outPutFile; return outPutFile;
} catch (Exception e) { } catch (Exception e) {
@@ -93,16 +95,20 @@ public class WallpapersHooks {
} }
public static String getWallpaperUrl() { public static String getWallpaperUrl() {
if (getWallpaperFile().exists() && eligibleWallpaperFile(getWallpaperFile())) var file = getWallpaperFile();
if (compress(getWallpaperFile()) == null) {
if (file.exists() && eligibleWallpaperFile(file)) {
var compressed = compress(file);
if (compressed == null) {
return "default"; return "default";
} else if (getBoolValue("compresswp", true)){ } else if (getBoolValue("compresswp", true) && compressed != null) {
return compress(getWallpaperFile()).getAbsolutePath(); return compressed.getAbsolutePath();
} else { } else {
return getWallpaperFile().getAbsolutePath(); return file.getAbsolutePath();
} }
else }
return "default";
return "default";
} }
public static Drawable getWallpaper() { public static Drawable getWallpaper() {