Skip to content

Commit

Permalink
Merge pull request #24 from FuckBoilerplate/feature/#23-use_internal_…
Browse files Browse the repository at this point in the history
…storage

Fix #23 - added option to save images in internal storage
  • Loading branch information
miguelbcr authored Jun 26, 2016
2 parents a2bacf2 + 7c7817c commit 8e26f79
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private void pickupImage() {

size = Size.Small;
RxPaparazzo.takeImage(SampleActivity.this)
.useInternalStorage()
.crop(options)
.size(size)
.usingGallery()
Expand All @@ -125,6 +126,7 @@ private void pickupImage() {
private void pickupImages() {
size = Size.Small;
RxPaparazzo.takeImages(SampleActivity.this)
.useInternalStorage()
.crop()
.size(size)
.usingGallery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private void pickupImage() {

size = Size.Small;
RxPaparazzo.takeImage(this)
.useInternalStorage()
.crop(options)
.size(size)
.usingGallery()
Expand All @@ -117,6 +118,7 @@ private void pickupImage() {
private void pickupImages() {
size = Size.Small;
RxPaparazzo.takeImages(this)
.useInternalStorage()
.crop()
.size(size)
.usingGallery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public BuilderImage(T ui) {
super(ui);
}

/**
* Calling it the images will be saved in internal storage, otherwise in public storage
*/
public BuilderImage<T> useInternalStorage() {
this.config.setUseInternalStorage();
return this;
}

/**
* Sets the size for the retrieved image.
* @param size
Expand Down Expand Up @@ -130,6 +138,14 @@ public BuilderImages(T ui) {
super(ui);
}

/**
* Calling it the images will be saved in internal storage, otherwise in public storage
*/
public BuilderImages<T> useInternalStorage() {
this.config.setUseInternalStorage();
return this;
}

/**
* Sets the size for the retrieved image.
* @param size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public class Config {
private Size size;
private boolean doCrop;
private UCrop.Options options;
private boolean useInternalStorage;

public Config() {
this.size = Size.Screen;
this.doCrop = false;
this.useInternalStorage = false;
}

public Size getSize() {
Expand Down Expand Up @@ -53,4 +55,12 @@ public UCrop.Options getOptions() {
public void setSize(Size size) {
this.size = size;
}

public boolean useInternalStorage() {
return useInternalStorage;
}

public void setUseInternalStorage() {
this.useInternalStorage = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import rx.functions.Func3;

public final class SaveImage extends UseCase<String> {
private static final String DATE_FORMAT = "ddMMyyyy_HHmmss.SSS";
private static final String DATE_FORMAT = "ddMMyyyy_HHmmss_SSS";
private static final String LOCALE_EN = "en";
private final TargetUi targetUi;
private final Config config;
Expand Down Expand Up @@ -112,12 +112,14 @@ private String getApplicationName(Context context) {
private File getPublicDir(String dirRoot, String dirname) {
File storageDir = null;

if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File dir = (dirRoot != null) ? Environment.getExternalStoragePublicDirectory(dirRoot) : Environment.getExternalStorageDirectory();
storageDir = new File(dir, dirname);
if (!config.useInternalStorage()) {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File dir = (dirRoot != null) ? Environment.getExternalStoragePublicDirectory(dirRoot) : Environment.getExternalStorageDirectory();
storageDir = new File(dir, dirname);

if (!storageDir.exists() && !storageDir.mkdirs()) {
if (!storageDir.exists() && !storageDir.mkdirs()) {
storageDir = null;
}
}
}

Expand Down

0 comments on commit 8e26f79

Please sign in to comment.