Skip to content

Commit

Permalink
Merge pull request #81 from Siddounet/file-multiple-mime-types
Browse files Browse the repository at this point in the history
File picker multiple mime types management
  • Loading branch information
miguelbcr authored Nov 14, 2017
2 parents 4bfec3e + 2485a95 commit 5f3975d
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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.miguelbcr.ui.rx_paparazzo2.sample.fragments.SampleFragment;
import com.yalantis.ucrop.UCrop;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
Expand Down Expand Up @@ -83,6 +84,10 @@ private void initViews() {
findViewById(R.id.fab_pickup_images).setOnClickListener(v -> pickupImages());
findViewById(R.id.fab_pickup_file).setOnClickListener(v -> pickupFile());
findViewById(R.id.fab_pickup_files).setOnClickListener(v -> pickupFiles());
findViewById(R.id.fab_pickup_multiple_types_file)
.setOnClickListener(v -> pickupMultipleTypesFile());
findViewById(R.id.fab_pickup_multiple_types_files)
.setOnClickListener(v -> pickupMultipleTypesFiles());

loadImages();
}
Expand Down Expand Up @@ -146,6 +151,28 @@ private void pickupFiles() {
processMultiple(pickMultiple);
}

private void pickupMultipleTypesFile() {
Observable<Response<SampleActivity, FileData>> pickUsingFiles =
pickSingle(null, new SmallSize())
.setMultipleMimeType("image/jpeg", "image/jpg", "image/png", "application/pdf")
.useInternalStorage()
.useDocumentPicker()
.usingFiles();

processSingle(pickUsingFiles);
}

private void pickupMultipleTypesFiles() {
Observable<Response<SampleActivity, List<FileData>>> pickMultiple =
pickMultiple(new SmallSize())
.setMultipleMimeType("image/jpeg", "image/jpg", "image/png", "application/pdf")
.useInternalStorage()
.useDocumentPicker()
.usingFiles();

processMultiple(pickMultiple);
}

private void processSingle(Observable<Response<SampleActivity, FileData>> pickUsingGallery) {
pickUsingGallery
.subscribeOn(Schedulers.io())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.miguelbcr.ui.rx_paparazzo2.RxPaparazzo;
Expand All @@ -23,7 +21,6 @@
import com.miguelbcr.ui.rx_paparazzo2.sample.activities.PickerUtil;
import com.miguelbcr.ui.rx_paparazzo2.sample.activities.Testable;
import com.miguelbcr.ui.rx_paparazzo2.sample.adapters.ImagesAdapter;
import com.squareup.picasso.Picasso;
import com.yalantis.ucrop.UCrop;

import java.util.ArrayList;
Expand Down Expand Up @@ -85,6 +82,10 @@ private void initViews() {
view.findViewById(R.id.fab_pickup_images).setOnClickListener(v -> pickupImages());
view.findViewById(R.id.fab_pickup_file).setOnClickListener(v -> pickupFile());
view.findViewById(R.id.fab_pickup_files).setOnClickListener(v -> pickupFiles());
view.findViewById(R.id.fab_pickup_multiple_types_file)
.setOnClickListener(v -> pickupMultipleTypesFile());
view.findViewById(R.id.fab_pickup_multiple_types_files)
.setOnClickListener(v -> pickupMultipleTypesFiles());

loadImages();
}
Expand Down Expand Up @@ -150,6 +151,28 @@ private void pickupFiles() {
processMultiple(pickMultiple);
}

private void pickupMultipleTypesFile() {
Observable<Response<SampleFragment, FileData>> pickUsingFiles =
pickSingle(null, new SmallSize())
.setMultipleMimeType("image/jpeg", "image/jpg", "image/png", "application/pdf")
.useInternalStorage()
.useDocumentPicker()
.usingFiles();

processSingle(pickUsingFiles);
}

private void pickupMultipleTypesFiles() {
Observable<Response<SampleFragment, List<FileData>>> pickMultiple =
pickMultiple(new SmallSize())
.setMultipleMimeType("image/jpeg", "image/jpg", "image/png", "application/pdf")
.useInternalStorage()
.useDocumentPicker()
.usingFiles();

processMultiple(pickMultiple);
}

private void processSingle(Observable<Response<SampleFragment, FileData>> pickUsingGallery) {
pickUsingGallery
.subscribeOn(Schedulers.io())
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/res/layout/sample_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,39 @@

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

<TextView
android:id="@+id/fab_pickup_multiple_types_file"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:layout_marginTop="10dp"
android:drawableLeft="@drawable/ic_image_black_24dp"
android:drawablePadding="5dp"
android:padding="5dp"
android:text="Pdf and images file"
android:textColor="@android:color/white"
android:layout_weight="1"/>

<TextView
android:id="@+id/fab_pickup_multiple_types_files"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:layout_marginTop="10dp"
android:drawableLeft="@drawable/ic_collections_black_24dp"
android:drawablePadding="5dp"
android:padding="5dp"
android:text="Pdf and images files"
android:textColor="@android:color/white"
android:layout_weight="1"/>
</LinearLayout>

</LinearLayout>

<android.support.v7.widget.RecyclerView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ public B setMimeType(String mimeType) {
return self;
}

/**
* Sets the mime types of the picker.
*/
public B setMultipleMimeType(String... mimeType) {
this.config.setPickMultipleMimeTypes(mimeType);
return self;
}

/**
* Enables cropping of images.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Config {
private boolean useInternalStorage;

private String pickMimeType;
private String[] pickMultipleMimeTypes;
private boolean pickOpenableOnly;
private boolean useDocumentPicker;
private boolean sendToMediaScanner;
Expand All @@ -51,6 +52,7 @@ public Config() {
this.useDocumentPicker = false;
this.pickOpenableOnly = false;
this.pickMimeType = null;
this.pickMultipleMimeTypes = null;
this.sendToMediaScanner = false;
this.failCropIfNotImage = false;
this.fileProviderAuthority = null;
Expand Down Expand Up @@ -116,6 +118,18 @@ public String getMimeType(String defaultMimeType) {
return pickMimeType;
}

public void setPickMultipleMimeTypes(String... pickMultipleMimeTypes) {
this.pickMultipleMimeTypes = pickMultipleMimeTypes;
}

public String[] getMultipleMimeTypes() {
if (this.pickMultipleMimeTypes == null) {
return null;
}

return pickMultipleMimeTypes;
}

public void setPickOpenableOnly(boolean pickOpenableOnly) {
this.pickOpenableOnly = pickOpenableOnly;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ public Observable<Uri> react() {
}

private Intent getFileChooserIntent() {
String mimeType = config.getMimeType(getDefaultMimeType());
Intent intent = new Intent();
intent.setType(mimeType);
if (config.getMultipleMimeTypes() == null) {
intent.setType(config.getMimeType(getDefaultMimeType()));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent.setType(DEFAULT_MIME_TYPE);
intent.putExtra(Intent.EXTRA_MIME_TYPES, config.getMultipleMimeTypes());
}

if (config.isUseDocumentPicker() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ private List<Uri> getUris(Intent intent) {
}

private Intent getFileChooserIntent() {
String mimeType = config.getMimeType(getDefaultMimeType());
Intent intent = new Intent();
intent.setType(mimeType);
if (config.getMultipleMimeTypes() == null) {
intent.setType(config.getMimeType(getDefaultMimeType()));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent.setType(DEFAULT_MIME_TYPE);
intent.putExtra(Intent.EXTRA_MIME_TYPES, config.getMultipleMimeTypes());
}

if (config.isUseDocumentPicker() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
Expand Down

0 comments on commit 5f3975d

Please sign in to comment.