Skip to content

Commit

Permalink
Merge pull request #222 from mnayef95/only-video-support
Browse files Browse the repository at this point in the history
Support only video
  • Loading branch information
esafirm authored Aug 3, 2019
2 parents 369ba31 + 4bec8ce commit 4a94076
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<File> 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<File> excludedImages, final ImageLoaderListener listener) {
getExecutorService().execute(new ImageLoadRunnable(isFolderMode, onlyVideo, includeVideo, includeAnimation, excludedImages, listener));
}

public void abortLoadImages() {
Expand All @@ -56,22 +57,30 @@ private class ImageLoadRunnable implements Runnable {

private boolean isFolderMode;
private boolean includeVideo;
private boolean onlyVideo;
private boolean includeAnimation;
private ArrayList<File> exlucedImages;
private ImageLoaderListener listener;

public ImageLoadRunnable(boolean isFolderMode, boolean includeVideo, boolean includeAnimation, ArrayList<File> excludedImages, ImageLoaderListener listener) {
public ImageLoadRunnable(boolean isFolderMode, boolean onlyVideo, boolean includeVideo, boolean includeAnimation, ArrayList<File> excludedImages, ImageLoaderListener listener) {
this.isFolderMode = isFolderMode;
this.includeVideo = includeVideo;
this.includeAnimation = includeAnimation;
this.onlyVideo = onlyVideo;
this.exlucedImages = excludedImages;
this.listener = listener;
}

@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 + "="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.StyleRes;

import com.esafirm.imagepicker.features.common.BaseConfig;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<File> 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<Image> images, final List<Folder> folders) {
runOnUiIfAvailable(() -> {
Expand Down
3 changes: 3 additions & 0 deletions sample/src/main/java/com/esafirm/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import rx.Observable;
import rx.functions.Action1;

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
android:layout_marginBottom="@dimen/ef_spacing"
android:text="Include Video"/>

<Switch
android:id="@+id/ef_switch_only_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/ef_spacing"
android:text="Only video"/>

<Switch
android:id="@+id/ef_switch_single"
android:layout_width="wrap_content"
Expand Down

0 comments on commit 4a94076

Please sign in to comment.