Skip to content

Commit

Permalink
refactor: #63 Provide Image file to other apps
Browse files Browse the repository at this point in the history
- Change the storage location from `lang<LANG>/images/` to `/Pictures`
  • Loading branch information
nya-elimu committed Nov 25, 2020
1 parent fa62a32 commit 3980d12
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions app/src/main/java/ai/elimu/content_provider/util/FileHelper.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package ai.elimu.content_provider.util;

import android.content.Context;
import android.os.Environment;

import java.io.File;

import ai.elimu.content_provider.language.SharedPreferencesHelper;
import ai.elimu.model.enums.Language;
import ai.elimu.model.v2.gson.content.ImageGson;
import ai.elimu.model.v2.gson.content.VideoGson;

Expand All @@ -14,43 +13,20 @@
*/
public class FileHelper {

private static File getImagesDirectory(Context context) {
File externalFilesDir = context.getExternalFilesDir(null);
Language language = SharedPreferencesHelper.getLanguage(context);
File languageDirectory = new File(externalFilesDir, "lang-" + language.getIsoCode());
File imagesDirectory = new File(languageDirectory, "images");
if (!imagesDirectory.exists()) {
imagesDirectory.mkdirs();
}
return imagesDirectory;
}

public static File getImageFile(ImageGson imageGson, Context context) {
if ((imageGson.getId() == null) || (imageGson.getRevisionNumber() == null)) {
return null;
}
File imagesDirectory = getImagesDirectory(context);
File imagesDirectory = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File file = new File(imagesDirectory, imageGson.getId() + "_r" + imageGson.getRevisionNumber() + "." + imageGson.getImageFormat().toString().toLowerCase());
return file;
}


private static File getVideosDirectory(Context context) {
File externalFilesDir = context.getExternalFilesDir(null);
Language language = SharedPreferencesHelper.getLanguage(context);
File languageDirectory = new File(externalFilesDir, "lang-" + language.getIsoCode());
File videosDirectory = new File(languageDirectory, "videos");
if (!videosDirectory.exists()) {
videosDirectory.mkdirs();
}
return videosDirectory;
}

public static File getVideoFile(VideoGson videoGson, Context context) {
if ((videoGson.getId() == null) || (videoGson.getRevisionNumber() == null)) {
return null;
}
File videosDirectory = getVideosDirectory(context);
File videosDirectory = context.getExternalFilesDir(Environment.DIRECTORY_MOVIES);
File file = new File(videosDirectory, videoGson.getId() + "_r" + videoGson.getRevisionNumber() + "." + videoGson.getVideoFormat().toString().toLowerCase());
return file;
}
Expand Down

0 comments on commit 3980d12

Please sign in to comment.