Closed vrsrohit closed 5 years ago
what does NewImageSaver class look like?
its just a class to handle saving and loading of files I have pasted here please check it
package com.dsrtech.whatsappstickers.utils;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
public class NewImageSaver {
private Context mContext;
public NewImageSaver(Context context) {
this.mContext = context;
}
public void save(Bitmap bitmapImage, String directoryName, String fileName) {
File mainDirectory = new File(mContext.getFilesDir(), "PIXEL_WHATSAPP_STICKERS");
// creates the directory if not present yet
mainDirectory.mkdir();
File subDirectory = new File(mainDirectory, directoryName);
subDirectory.mkdir();
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(new File(subDirectory, fileName));
if (fileName.equals("tray_Cuppy.png")) {
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
} else {
bitmapImage.compress(Bitmap.CompressFormat.WEBP, 50, fileOutputStream);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fileOutputStream != null) {
fileOutputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
private File[] loadFilesOfDirectory(String directoryName) {
File directory = new File(mContext.getFilesDir(), directoryName);
if (!directory.exists() && !directory.mkdirs()) {
Log.e("ImageSaver", "Error creating directory " + directory);
}
return directory.listFiles();
}
public ArrayList<String> loadPathsOfDirectory(String directoryName) {
if (new File(mContext.getFilesDir(), "PIXEL_WHATSAPP_STICKERS"+File.separator+directoryName).listFiles().length > 0) {
ArrayList<String> paths = new ArrayList<>();
for (File file : new File(mContext.getFilesDir(), "PIXEL_WHATSAPP_STICKERS"+File.separator+directoryName).listFiles()) {
paths.add(file.getPath());
}
return paths;
}
return null;
}
public File loadFile(String directoryName, String bitmapName) {
try {
File[] files = (loadFilesOfDirectory("PIXEL_WHATSAPP_STICKERS"+File.separator+directoryName));
for (File file : files) {
if (((file.getName()).equals(bitmapName))) {
return file;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public ArrayList<String> loadFileNames(String directoryName) {
ArrayList<String> filenames = new ArrayList<>();
try {
File[] files = (loadFilesOfDirectory("PIXEL_WHATSAPP_STICKERS"+File.separator+directoryName));
for (File file : files) {
filenames.add(file.getName());
}
return filenames;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public int loadMainFolderSize(){
return loadFilesOfDirectory("PIXEL_WHATSAPP_STICKERS").length;
}
public ArrayList<String> loadPaths(String directoryName) {
ArrayList<String> filenames = new ArrayList<>();
try {
File[] files = (loadFilesOfDirectory("PIXEL_WHATSAPP_STICKERS"+File.separator+directoryName));
for (File file : files) {
if (!file.getName().endsWith(".png")){
filenames.add(file.getPath());
}
}
return filenames;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
@simonzhexu @MarvinJWendt Please Help guys its very urgent for me
Hey, This Issue seems to be inactive. To keep things organized I will close this for now. If this Issue is still relevant, don't hesitate to drop a comment and I will reopen it if necessary.
Sincerely, Marvin Wendt
Hello I am trying to load stickers from server , I am saving them in internal storage and changed the content provider to suit my requirement but the problem here is when I tried to add 5 sticker packs only 2/3 are reflecting correctly in WhatsApp and they are loading very slowly . (sometimes all packs will show in WhatsApp but fail to display stickers if in case it displays stickers after re opening once or twice they are getting cleared from whatsapp )
Here I have pasted my ContentProvider. Please Help !!
PS :: I have switched of battery optimisation for the app and tested in 4 different type of mobiles.