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

Add Video Thumbnail preview and set default theme to light #53

Merged
merged 6 commits into from
Sep 29, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ dependencies {
compile project(':library')

// Image loading sample
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.github.bumptech.glide:glide:3.6.1'
}
4 changes: 2 additions & 2 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</activity>

<activity
android:name="com.nononsenseapps.filepicker.sample.ImagePickerActivity"
android:name=".MultimediaPickerActivity"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup this naming makes sense now

android:label="@string/title_activity_no_nonsense_file_picker"
android:theme="@style/SampleTheme">
<intent-filter>
Expand All @@ -74,7 +74,7 @@
</activity>

<activity
android:name="com.nononsenseapps.filepicker.sample.ImagePickerActivity2"
android:name=".MultimediaPickerActivity2"
android:label="@string/title_activity_no_nonsense_file_picker"
android:theme="@style/SampleThemeLight">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
/**
* All this class does is return a suitable fragment.
*/
public class ImagePickerActivity extends AbstractFilePickerActivity {
public class MultimediaPickerActivity extends AbstractFilePickerActivity {

public ImagePickerActivity() {
public MultimediaPickerActivity() {
super();
}

@Override
protected AbstractFilePickerFragment<File> getFragment(
final String startPath, final int mode, final boolean allowMultiple,
final boolean allowCreateDir) {
AbstractFilePickerFragment<File> fragment = new ImagePickerFragment();
AbstractFilePickerFragment<File> fragment = new MultimediaPickerFragment();
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
fragment.setArgs(startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
mode, allowMultiple, allowCreateDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
/**
* Duplicate to allow second theme to be used.
*/
public class ImagePickerActivity2 extends ImagePickerActivity {
public class MultimediaPickerActivity2 extends MultimediaPickerActivity {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
/**
* A sample which demonstrates how appropriate methods
* can be overwritten in order to enable enhanced
* capabilities, in this case showing thumbnails of images.
* capabilities, in this case showing thumbnails of images and thumbnail of videos.
* <p/>
* I am still listing all files, so I extend from the ready made
* SD-card browser classes. This allows this class to focus
* entirely on the image side of things.
*
* <p/>
* To load the image I am using the super great Glide library
* which only requires a single line of code in this file.
*/
public class ImagePickerFragment extends FilePickerFragment {
public class MultimediaPickerFragment extends FilePickerFragment {

/**
* An extremely simple method for identifying images. This
Expand All @@ -60,7 +60,22 @@ protected boolean isImage(File file) {
}

/**
* Overriding this method allows us to inject a preview image
* An extremely simple method for identifying videos. This
* could be improved, but it's good enough for this example.
*
* @param file which could be an video
* @return true if the file can be previewed, false otherwise
*/
private boolean isVideo(File file) {
if (isDir(file)) {
return false;
}
return file.getPath().endsWith(".mp4")||
file.getPath().endsWith(".MP4");
}

/**
* Overriding this method allows us to inject a preview image and thumbnail of videos
* in the layout
*
* @param vh to bind data from either a file or directory
Expand All @@ -78,6 +93,10 @@ public void onBindViewHolder(DirViewHolder vh, int position, File file) {
if (isImage(file)) {
vh.icon.setVisibility(View.VISIBLE);
Glide.with(this).load(file).centerCrop().into((ImageView) vh.icon);
} else if (isVideo(file)) {
vh.icon.setVisibility(View.VISIBLE);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much point in having to blocks with the exact same code. Would make sense to unify them I think, something like

if (isMultimedia(file)) {
//...
}

or

if (isPreviewable(file)) {
//...
}

Glide.with(this).load(file).centerCrop().into((ImageView) vh.icon);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ public void onClick(final View v) {

if (checkLightTheme.isChecked()) {
i = new Intent(NoNonsenseFilePicker.this,
ImagePickerActivity2.class);
MultimediaPickerActivity2.class);
} else {
i = new Intent(NoNonsenseFilePicker.this,
ImagePickerActivity.class);
MultimediaPickerActivity.class);
}
i.setAction(Intent.ACTION_GET_CONTENT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
android:gravity="center_vertical"
style="?android:textAppearanceMedium"
android:fontFamily="light"
android:layout_gravity="left"/>
android:layout_gravity="left"
android:checked="true"/>

</LinearLayout>

Expand All @@ -125,7 +126,7 @@
<Button
android:layout_width="match_parent"
android:layout_height="64dp"
android:text="Pick SD-card with image preview"
android:text="Pick SD-card with multimedia preview"
android:layout_marginTop="16dp"
android:id="@+id/button_image"
android:gravity="center"
Expand Down