Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #75 from yazeed44/add-video-support
Browse files Browse the repository at this point in the history
Add video support
  • Loading branch information
yazeed44 committed Sep 18, 2015
2 parents d6a11b2 + 411b0df commit 09bdebf
Show file tree
Hide file tree
Showing 21 changed files with 357 additions and 136 deletions.
4 changes: 2 additions & 2 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@
<orderEntry type="library" exported="" name="support-v4-23.0.0" level="project" />
<orderEntry type="library" exported="" name="glide-3.6.1" level="project" />
<orderEntry type="library" exported="" name="material-dialogs-0.7.9.1" level="project" />
<orderEntry type="library" exported="" name="commons-io-1.3.2" level="project" />
<orderEntry type="library" exported="" name="robospice-cache-1.4.14" level="project" />
<orderEntry type="library" exported="" name="robospice-1.4.14" level="project" />
<orderEntry type="library" exported="" name="commons-io-1.3.2" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.0" level="project" />
<orderEntry type="library" exported="" name="robospice-1.4.14" level="project" />
<orderEntry type="module" module-name="imagepicker" exported="" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public void onPickImageMultipleInfinite(View view) {

}

public void onClickPickImageWithVideos(View view) {
new Picker.Builder(this, this, R.style.MIP_theme)
.setPickMode(Picker.PickMode.MULTIPLE_IMAGES)
.setVideosEnabled(true)
.build()
.startActivity();

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
android:onClick="onClickPickImageSingle"
android:text="@string/btn_pick_single_image" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClickPickImageWithVideos"
android:text="@string/btn_pick_with_videos" />

<android.support.v7.widget.RecyclerView
android:id="@+id/images_sample"

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<string name="btn_pick_multiple_images_with_limit">Pick Multiple images (6 is the limit)</string>
<string name="btn_pick_single_image">Pick single image</string>
<string name="btn_pick_multiple_image_infinite">Pick multiple images (No limit)</string>
<string name="btn_pick_with_videos">Pick multiple images (with video)</string>

</resources>
5 changes: 4 additions & 1 deletion imagepicker/imagepicker.iml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand All @@ -84,7 +85,9 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform (1)" jdkType="Android SDK" />
Expand All @@ -93,9 +96,9 @@
<orderEntry type="library" exported="" name="eventbus-2.4.0" level="project" />
<orderEntry type="library" exported="" name="design-23.0.0" level="project" />
<orderEntry type="library" exported="" name="floatingactionbutton-1.3.0" level="project" />
<orderEntry type="library" exported="" name="robospice-1.4.14" level="project" />
<orderEntry type="library" exported="" name="commons-io-1.3.2" level="project" />
<orderEntry type="library" exported="" name="robospice-cache-1.4.14" level="project" />
<orderEntry type="library" exported="" name="robospice-1.4.14" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.0" level="project" />
<orderEntry type="library" exported="" name="library-1.2.3" level="project" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,35 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
* Created by yazeed44 on 6/14/15.
*/
public class AlbumEntry implements Serializable {
public final int id;
public final String name;
public final ImageEntry coverImage;
public final ArrayList<ImageEntry> imageList = new ArrayList<>();
public ImageEntry coverImage;

public AlbumEntry(int albumId, String albumName, ImageEntry coverImage) {

public AlbumEntry(int albumId, String albumName) {
this.id = albumId;
this.name = albumName;
this.coverImage = coverImage;
}

public void addPhoto(ImageEntry imageEntry) {
imageList.add(imageEntry);
}
public void sortImagesByTimeDesc() {
Collections.sort(imageList, new Comparator<ImageEntry>() {
@Override
public int compare(ImageEntry lhs, ImageEntry rhs) {
return (int) (rhs.dateAdded - lhs.dateAdded);
}
});

coverImage = imageList.get(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
public class ImageEntry implements Serializable {
public final int imageId;
public final String path;
public final long dateAdded;
public boolean isPicked = false;
public boolean isVideo = false;

public ImageEntry(final Builder builder) {
this.path = builder.mPath;
this.imageId = builder.mImageId;
this.dateAdded = builder.mDateAdded;
}

public static ImageEntry from(final Cursor cursor) {
Expand All @@ -29,7 +32,7 @@ public static ImageEntry from(final Uri uri) {

@Override
public boolean equals(Object o) {
return o instanceof ImageEntry && imageId == ((ImageEntry) o).imageId;
return o instanceof ImageEntry && ((ImageEntry) o).path.equals(path);
}

@Override
Expand All @@ -44,6 +47,7 @@ public static class Builder {
public static int count = -1;
private final String mPath;
private int mImageId;
private long mDateAdded;

public Builder(final String path) {
this.mPath = path;
Expand All @@ -60,12 +64,15 @@ public static Builder from(final Uri uri) {
public static Builder from(final Cursor cursor) {
final int dataColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
final int imageIdColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID);
final int dateAddedColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED);

final int imageId = cursor.getInt(imageIdColumn);
final String path = cursor.getString(dataColumn);
final long dateAdded = cursor.getLong(dateAddedColumn);

return new ImageEntry.Builder(path)
.imageId(imageId)
.dateAdded(dateAdded)
;

}
Expand All @@ -76,6 +83,11 @@ public Builder imageId(int imageId) {
return this;
}

public Builder dateAdded(long timestamp) {
this.mDateAdded = timestamp;
return this;
}


public ImageEntry build() {
return new ImageEntry(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.yazeed44.imagepicker.util.LoadingAlbumsRequest;
import net.yazeed44.imagepicker.util.OfflineSpiceService;
import net.yazeed44.imagepicker.util.Picker;
import net.yazeed44.imagepicker.util.Util;

import java.util.ArrayList;

Expand Down Expand Up @@ -54,17 +55,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
if (albumLoadedEvent != null) {
mAlbumList = albumLoadedEvent.albumList;
}



}


setupAdapter();


setupRecycler();
setupAdapter();

return mAlbumsRecycler;
}
Expand Down Expand Up @@ -122,12 +116,8 @@ public void run() {

}
}, 100);



}


}

protected void setupRecycler() {
Expand All @@ -143,15 +133,13 @@ protected void setupRecycler() {

public void setupAdapter() {
if (mAlbumList == null) {
final LoadingAlbumsRequest loadingRequest = new LoadingAlbumsRequest(getActivity());
final LoadingAlbumsRequest loadingRequest = new LoadingAlbumsRequest(getActivity(), mPickOptions);

mSpiceManager.execute(loadingRequest, this);
} else {

mAlbumsRecycler.setAdapter(new AlbumsAdapter(this, mAlbumList, mAlbumsRecycler));
}


}

private boolean hasLoadedSuccessfully(final ArrayList albumList) {
Expand All @@ -167,14 +155,10 @@ public void onEvent(final Events.OnReloadAlbumsEvent reloadAlbums) {
}

private void pickLatestCapturedImage() {



for (final AlbumEntry albumEntry : mAlbumList) {
if (albumEntry.name.equals(PickerActivity.CAPTURED_IMAGES_ALBUM_NAME)) {
EventBus.getDefault().postSticky(new Events.OnPickImageEvent(Util.getAllPhotosAlbum(mAlbumList).imageList.get(0)));
mAlbumsRecycler.getChildAt(mAlbumList.indexOf(albumEntry)).performClick();
EventBus.getDefault().postSticky(new Events.OnPickImageEvent(albumEntry.imageList.get(0)));

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.yazeed44.imagepicker.ui;

import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
Expand Down Expand Up @@ -34,6 +35,7 @@ public class ImagesThumbnailAdapter extends RecyclerView.Adapter<ImagesThumbnail
protected final Picker mPickOptions;

protected final Drawable mCheckIcon;
protected final Drawable mVideoIcon;
protected final Fragment mFragment;


Expand All @@ -44,6 +46,7 @@ public ImagesThumbnailAdapter(final Fragment fragment, final AlbumEntry album, f
mPickOptions = pickOptions;

mCheckIcon = createCheckIcon();
mVideoIcon = createVideoIcon();
}

private Drawable createCheckIcon() {
Expand All @@ -53,6 +56,16 @@ private Drawable createCheckIcon() {
return checkIcon;
}

private Drawable createVideoIcon() {
if (!mPickOptions.videosEnabled) {
return null;
}
Drawable videoIcon = ContextCompat.getDrawable(mRecyclerView.getContext(), R.drawable.ic_play_arrow);
videoIcon = DrawableCompat.wrap(videoIcon);
DrawableCompat.setTint(videoIcon, mPickOptions.videoIconTintColor);
return videoIcon;
}

@Override
public ImageViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
final View imageLayout = LayoutInflater.from(mRecyclerView.getContext()).inflate(R.layout.element_image, viewGroup, false);
Expand Down Expand Up @@ -106,7 +119,7 @@ public void drawGrid(final ImageViewHolder holder, final ImageEntry imageEntry)


holder.check.setImageDrawable(mCheckIcon);

holder.videoIcon.setVisibility(View.GONE);

if (imageEntry.isPicked) {
holder.itemView.setBackgroundColor(mPickOptions.imageBackgroundColorWhenChecked);
Expand All @@ -127,6 +140,13 @@ public void drawGrid(final ImageViewHolder holder, final ImageEntry imageEntry)
if (mPickOptions.pickMode == Picker.PickMode.SINGLE_IMAGE) {
holder.check.setVisibility(View.GONE);
}

if (imageEntry.isVideo) {
holder.thumbnail.setColorFilter(mPickOptions.videoThumbnailOverlayColor, PorterDuff.Mode.MULTIPLY);
holder.videoIcon.setImageDrawable(mVideoIcon);
holder.videoIcon.setVisibility(View.VISIBLE);
}

}


Expand All @@ -153,12 +173,14 @@ public void pickImage(final ImageViewHolder holder, final ImageEntry imageEntry)
public static class ImageViewHolder extends RecyclerView.ViewHolder {
private final ImageView thumbnail;
private final ImageView check;
private final ImageView videoIcon;

public ImageViewHolder(final View itemView, final Util.OnClickImage listener) {
super(itemView);

thumbnail = (ImageView) itemView.findViewById(R.id.image_thumbnail);
check = (ImageView) itemView.findViewById(R.id.image_check);
videoIcon = (ImageView) itemView.findViewById(R.id.image_video_icon);

itemView.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Loading

0 comments on commit 09bdebf

Please sign in to comment.