From 40e0803ff921d41a890e6af5700bc0f8659fcd21 Mon Sep 17 00:00:00 2001 From: miguelbcr Date: Tue, 6 Jun 2017 22:31:25 +0200 Subject: [PATCH] #68 - Move fileProvider methos to register builder --- .../sample/SampleApplication.java | 5 +- .../sample/activities/SampleActivity.java | 12 ++--- .../ui/rx_paparazzo2/RxPaparazzo.java | 52 ++++++++++++------- .../ui/rx_paparazzo2/entities/Config.java | 4 +- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/com/miguelbcr/ui/rx_paparazzo2/sample/SampleApplication.java b/app/src/main/java/com/miguelbcr/ui/rx_paparazzo2/sample/SampleApplication.java index 7f148eb..5458c39 100644 --- a/app/src/main/java/com/miguelbcr/ui/rx_paparazzo2/sample/SampleApplication.java +++ b/app/src/main/java/com/miguelbcr/ui/rx_paparazzo2/sample/SampleApplication.java @@ -18,7 +18,10 @@ public class SampleApplication extends Application { @Override public void onCreate() { super.onCreate(); - RxPaparazzo.register(this); + RxPaparazzo.register(this) + .withFileProviderAuthority("") + .withFileProviderPath(""); + AppCare.YesSir.takeCareOn(this); if (LeakCanary.isInAnalyzerProcess(this)) { diff --git a/app/src/main/java/com/miguelbcr/ui/rx_paparazzo2/sample/activities/SampleActivity.java b/app/src/main/java/com/miguelbcr/ui/rx_paparazzo2/sample/activities/SampleActivity.java index 4aa7d78..3937d3a 100644 --- a/app/src/main/java/com/miguelbcr/ui/rx_paparazzo2/sample/activities/SampleActivity.java +++ b/app/src/main/java/com/miguelbcr/ui/rx_paparazzo2/sample/activities/SampleActivity.java @@ -8,10 +8,7 @@ import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; - import com.miguelbcr.ui.rx_paparazzo2.RxPaparazzo; import com.miguelbcr.ui.rx_paparazzo2.entities.FileData; import com.miguelbcr.ui.rx_paparazzo2.entities.Response; @@ -21,17 +18,14 @@ import com.miguelbcr.ui.rx_paparazzo2.entities.size.SmallSize; import com.miguelbcr.ui.rx_paparazzo2.sample.R; import com.miguelbcr.ui.rx_paparazzo2.sample.adapters.ImagesAdapter; -import com.squareup.picasso.Picasso; import com.yalantis.ucrop.UCrop; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; +import java.io.File; +import java.util.ArrayList; +import java.util.List; public class SampleActivity extends AppCompatActivity implements Testable { private static final String STATE_FILES = "FILES"; diff --git a/rx_paparazzo/src/main/java/com/miguelbcr/ui/rx_paparazzo2/RxPaparazzo.java b/rx_paparazzo/src/main/java/com/miguelbcr/ui/rx_paparazzo2/RxPaparazzo.java index add1cb2..8f0ff3f 100644 --- a/rx_paparazzo/src/main/java/com/miguelbcr/ui/rx_paparazzo2/RxPaparazzo.java +++ b/rx_paparazzo/src/main/java/com/miguelbcr/ui/rx_paparazzo2/RxPaparazzo.java @@ -37,9 +37,39 @@ public final class RxPaparazzo { public static final int RESULT_DENIED_PERMISSION = 2; public static final int RESULT_DENIED_PERMISSION_NEVER_ASK = 3; + private static String fileProviderAuthority; + private static String fileProviderPath; - public static void register(Application application) { + private RxPaparazzo() { + } + + public static RegisterBuilder register(Application application) { RxActivityResult.register(application); + return new RegisterBuilder(); + } + + public static class RegisterBuilder { + private final RegisterBuilder self; + + RegisterBuilder() { + this.self = this; + } + + /** + * Sets this to the value of name attribute of {@link android.support.v4.content.FileProvider} in AndroidManifest.xml + */ + public RegisterBuilder withFileProviderAuthority(String authority) { + fileProviderAuthority = authority; + return self; + } + + /** + * Sets this to the path to use in the {@link android.support.v4.content.FileProvider} xml file + */ + public RegisterBuilder withFileProviderPath(String path) { + fileProviderPath = path; + return self; + } } public static SingleSelectionBuilder single(T activity) { @@ -65,13 +95,15 @@ public static MultipleSelectionBuilder multiple(T fragme } private abstract static class Builder> { - private final Config config; private final ApplicationComponent applicationComponent; private final B self; + private final Config config; Builder(T ui) { this.self = (B)this; this.config = new Config(); + this.config.setFileProviderAuthority(fileProviderAuthority); + this.config.setFileProviderPath(fileProviderPath); this.applicationComponent = ApplicationComponent.create(new ApplicationModule(config, ui)); } @@ -88,22 +120,6 @@ public B setMaximumFileSizeInBytes(long maximumFileSizeInBytes) { return self; } - /** - * Sets this to the value of name attribute of {@link android.support.v4.content.FileProvider} in AndroidManifest.xml - */ - public B setFileProviderAuthority(String authority) { - this.config.setFileProviderAuthority(authority); - return self; - } - - /** - * Sets this to the path to use in the {@link android.support.v4.content.FileProvider} xml file - */ - public B setFileProviderPath(String authority) { - this.config.setFileProviderPath(authority); - return self; - } - /** * Limits the file which can be selected to those obey {@link android.content.Intent}.CATEGORY_OPENABLE. */ diff --git a/rx_paparazzo/src/main/java/com/miguelbcr/ui/rx_paparazzo2/entities/Config.java b/rx_paparazzo/src/main/java/com/miguelbcr/ui/rx_paparazzo2/entities/Config.java index f272d96..886cbe7 100644 --- a/rx_paparazzo/src/main/java/com/miguelbcr/ui/rx_paparazzo2/entities/Config.java +++ b/rx_paparazzo/src/main/java/com/miguelbcr/ui/rx_paparazzo2/entities/Config.java @@ -149,7 +149,7 @@ public void setFileProviderAuthority(String fileProviderAuthority) { } public String getFileProviderAuthority(Context context) { - if (fileProviderAuthority == null) { + if (fileProviderAuthority == null || fileProviderAuthority.trim().length() == 0) { return context.getPackageName() + "." + DEFAULT_FILE_PROVIDER_AUTHORITIES_SUFFIX; } @@ -161,7 +161,7 @@ public void setFileProviderPath(String fileProviderDirectory) { } public String getFileProviderDirectory() { - if (fileProviderDirectory == null) { + if (fileProviderDirectory == null || fileProviderDirectory.trim().length() == 0) { return DEFAULT_FILE_PROVIDER_PATH; }