Skip to content

Commit

Permalink
Merge pull request #71 from miguelbcr/#68-move-fileprovider-methods
Browse files Browse the repository at this point in the history
#68 - Move fileProvider methos to register builder
  • Loading branch information
miguelbcr authored Jun 6, 2017
2 parents b0fc850 + 40e0803 commit e6466f0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T extends Activity> SingleSelectionBuilder<T> single(T activity) {
Expand All @@ -65,13 +95,15 @@ public static <T extends Fragment> MultipleSelectionBuilder<T> multiple(T fragme
}

private abstract static class Builder<T, B extends Builder<T, B>> {
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));
}

Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit e6466f0

Please sign in to comment.