diff --git a/build.gradle b/build.gradle index e8ad494f..8b987852 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.2' + classpath 'com.android.tools.build:gradle:3.4.1' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d597e849..8f9fa55d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Feb 25 10:01:07 WIB 2019 +#Mon May 20 03:29:47 EEST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImageFileLoader.java b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImageFileLoader.java index d2140bec..8263ce17 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImageFileLoader.java +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImageFileLoader.java @@ -3,6 +3,7 @@ import android.content.Context; import android.database.Cursor; import android.provider.MediaStore; + import androidx.annotation.Nullable; import com.esafirm.imagepicker.features.common.ImageLoaderListener; @@ -34,8 +35,8 @@ public ImageFileLoader(Context context) { MediaStore.Images.Media.BUCKET_DISPLAY_NAME }; - public void loadDeviceImages(final boolean isFolderMode, final boolean includeVideo, final boolean includeAnimation, final ArrayList excludedImages, final ImageLoaderListener listener) { - getExecutorService().execute(new ImageLoadRunnable(isFolderMode, includeVideo, includeAnimation, excludedImages, listener)); + public void loadDeviceImages(final boolean isFolderMode, final boolean onlyVideo, final boolean includeVideo, final boolean includeAnimation, final ArrayList excludedImages, final ImageLoaderListener listener) { + getExecutorService().execute(new ImageLoadRunnable(isFolderMode, onlyVideo, includeVideo, includeAnimation, excludedImages, listener)); } public void abortLoadImages() { @@ -56,14 +57,16 @@ private class ImageLoadRunnable implements Runnable { private boolean isFolderMode; private boolean includeVideo; + private boolean onlyVideo; private boolean includeAnimation; private ArrayList exlucedImages; private ImageLoaderListener listener; - public ImageLoadRunnable(boolean isFolderMode, boolean includeVideo, boolean includeAnimation, ArrayList excludedImages, ImageLoaderListener listener) { + public ImageLoadRunnable(boolean isFolderMode, boolean onlyVideo, boolean includeVideo, boolean includeAnimation, ArrayList excludedImages, ImageLoaderListener listener) { this.isFolderMode = isFolderMode; this.includeVideo = includeVideo; this.includeAnimation = includeAnimation; + this.onlyVideo = onlyVideo; this.exlucedImages = excludedImages; this.listener = listener; } @@ -71,7 +74,13 @@ public ImageLoadRunnable(boolean isFolderMode, boolean includeVideo, boolean inc @Override public void run() { Cursor cursor; - if (includeVideo) { + if (onlyVideo) { + String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO; + + cursor = context.getContentResolver().query(MediaStore.Files.getContentUri("external"), projection, + selection, null, MediaStore.Images.Media.DATE_ADDED); + } else if (includeVideo) { String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE + " OR " + MediaStore.Files.FileColumns.MEDIA_TYPE + "=" diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePicker.java b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePicker.java index 269cd883..e68d57c3 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePicker.java +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePicker.java @@ -4,6 +4,11 @@ import android.content.Context; import android.content.Intent; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.StyleRes; +import androidx.fragment.app.Fragment; + import com.esafirm.imagepicker.features.cameraonly.ImagePickerCameraOnly; import com.esafirm.imagepicker.features.imageloader.ImageLoader; import com.esafirm.imagepicker.helper.ConfigUtils; @@ -15,11 +20,6 @@ import java.util.ArrayList; import java.util.List; -import androidx.annotation.ColorInt; -import androidx.annotation.NonNull; -import androidx.annotation.StyleRes; -import androidx.fragment.app.Fragment; - public abstract class ImagePicker { private ImagePickerConfig config; @@ -163,6 +163,11 @@ public ImagePicker includeVideo(boolean includeVideo) { return this; } + public ImagePicker onlyVideo(boolean onlyVideo) { + config.setOnlyVideo(onlyVideo); + return this; + } + public ImagePicker includeAnimation(boolean includeAnimation) { config.setIncludeAnimation(includeAnimation); return this; diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerConfig.java b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerConfig.java index d5a9ac8c..36708891 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerConfig.java +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerConfig.java @@ -2,6 +2,7 @@ import android.os.Parcel; import android.os.Parcelable; + import androidx.annotation.StyleRes; import com.esafirm.imagepicker.features.common.BaseConfig; @@ -29,6 +30,7 @@ public class ImagePickerConfig extends BaseConfig implements Parcelable { private boolean folderMode; private boolean includeVideo; + private boolean onlyVideo; private boolean includeAnimation; private boolean showCamera; @@ -79,6 +81,14 @@ public void setIncludeVideo(boolean includeVideo) { this.includeVideo = includeVideo; } + public boolean isOnlyVideo() { + return onlyVideo; + } + + public void setOnlyVideo(boolean onlyVideo) { + this.onlyVideo = onlyVideo; + } + public boolean isIncludeAnimation() { return includeAnimation; } @@ -198,7 +208,8 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeInt(this.theme); dest.writeByte(this.folderMode ? (byte) 1 : (byte) 0); dest.writeByte(this.includeVideo ? (byte) 1 : (byte) 0); - dest.writeByte(this.includeAnimation ? (byte) 1: (byte) 0); + dest.writeByte(this.onlyVideo ? (byte) 1 : (byte) 0); + dest.writeByte(this.includeAnimation ? (byte) 1 : (byte) 0); dest.writeByte(this.showCamera ? (byte) 1 : (byte) 0); dest.writeSerializable(this.imageLoader); } @@ -222,6 +233,7 @@ protected ImagePickerConfig(Parcel in) { this.theme = in.readInt(); this.folderMode = in.readByte() != 0; this.includeVideo = in.readByte() != 0; + this.onlyVideo = in.readByte() != 0; this.includeAnimation = in.readByte() != 0; this.showCamera = in.readByte() != 0; this.imageLoader = (ImageLoader) in.readSerializable(); diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerPresenter.java b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerPresenter.java index 91cd37d0..b6c12fc3 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerPresenter.java +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerPresenter.java @@ -4,7 +4,9 @@ import android.content.Intent; import android.os.Handler; import android.os.Looper; + import androidx.fragment.app.Fragment; + import android.widget.Toast; import com.esafirm.imagepicker.R; @@ -51,12 +53,13 @@ void loadImages(ImagePickerConfig config) { boolean isFolder = config.isFolderMode(); boolean includeVideo = config.isIncludeVideo(); + boolean onlyVideo = config.isOnlyVideo(); boolean includeAnimation = config.isIncludeAnimation(); ArrayList excludedImages = config.getExcludedImages(); runOnUiIfAvailable(() -> getView().showLoading(true)); - imageLoader.loadDeviceImages(isFolder, includeVideo, includeAnimation, excludedImages, new ImageLoaderListener() { + imageLoader.loadDeviceImages(isFolder, onlyVideo, includeVideo, includeAnimation, excludedImages, new ImageLoaderListener() { @Override public void onImageLoaded(final List images, final List folders) { runOnUiIfAvailable(() -> { diff --git a/sample/src/main/java/com/esafirm/sample/MainActivity.java b/sample/src/main/java/com/esafirm/sample/MainActivity.java index e88de8ce..e3e2af31 100644 --- a/sample/src/main/java/com/esafirm/sample/MainActivity.java +++ b/sample/src/main/java/com/esafirm/sample/MainActivity.java @@ -20,6 +20,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; + import rx.Observable; import rx.functions.Action1; @@ -76,6 +77,7 @@ private ImagePicker getImagePicker() { final boolean useCustomImageLoader = ((Switch) findViewById(R.id.ef_switch_imageloader)).isChecked(); final boolean folderMode = ((Switch) findViewById(R.id.ef_switch_folder_mode)).isChecked(); final boolean includeVideo = ((Switch) findViewById(R.id.ef_switch_include_video)).isChecked(); + final boolean onlyVideo = ((Switch) findViewById(R.id.ef_switch_only_video)).isChecked(); final boolean isExclude = ((Switch) findViewById(R.id.ef_switch_include_exclude)).isChecked(); ImagePicker imagePicker = ImagePicker.create(this) @@ -86,6 +88,7 @@ private ImagePicker getImagePicker() { : ReturnMode.NONE) // set whether pick action or camera action should return immediate result or not. Only works in single mode for image picker .folderMode(folderMode) // set folder mode (false by default) .includeVideo(includeVideo) // include video (false by default) + .onlyVideo(onlyVideo) // include video (false by default) .toolbarArrowColor(Color.RED) // set toolbar arrow up color .toolbarFolderTitle("Folder") // folder selection title .toolbarImageTitle("Tap to select") // image selection title diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 93ab46e5..3d1232ea 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -40,6 +40,13 @@ android:layout_marginBottom="@dimen/ef_spacing" android:text="Include Video"/> + +