Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null error in video picker when there is no external storage #71

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ proguard/

# Log Files
*.log
.DS_Store

# Android Studio Navigation editor temp files
.navigation/
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ Please star this library if you like it. :)
intent2 = new Intent(this, VideoPickActivity.class);
intent2.putExtra(IS_NEED_CAMERA, true);
intent2.putExtra(Constant.MAX_NUMBER, 9);
intent2.putExtra(Constant.MAX_VIDEO_DURATION, 30); //Optional for setting duration in seconds.
intent2.putExtra(Constant.VIDEO_QUALITY, 1); //Optional for setting quality. 0 for low quality & 1 for high quality.
startActivityForResult(intent2, Constant.REQUEST_CODE_PICK_VIDEO);
break;
case R.id.btn_pick_audio:
Intent intent3 = new Intent(this, AudioPickActivity.class);
intent3.putExtra(IS_NEED_RECORDER, true);
intent3.putExtra(Constant.MAX_NUMBER, 9);
intent3.putExtra(Constant.MAX_AUDIO_SIZE, 5900); //Optional for setting size of recorded file in bytes. 5900 = ~ 1 second
startActivityForResult(intent3, Constant.REQUEST_CODE_PICK_AUDIO);
break;
case R.id.btn_pick_file:
Expand Down
25 changes: 16 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
compileSdkVersion 29
//buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.vincent.filepickersample"
minSdkVersion 14
targetSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
disable 'Deprecation'
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'

testCompile 'junit:junit:4.12'
compile project(':filepicker')
testImplementation 'junit:junit:4.12'
implementation project(':filepicker')
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.vincent.filepickersample;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* Date: 2015/10/29
* Time: 15:31
*/

public class LocalFileUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
private Context mContext;
private Thread.UncaughtExceptionHandler mDefaultHandler;
Expand Down
15 changes: 3 additions & 12 deletions app/src/main/java/com/vincent/filepickersample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
package com.vincent.filepickersample;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.vincent.filepicker.Constant;
import com.vincent.filepicker.Util;
import com.vincent.filepicker.activity.AudioPickActivity;
import com.vincent.filepicker.activity.ImagePickActivity;
import com.vincent.filepicker.activity.NormalFilePickActivity;
import com.vincent.filepicker.activity.VideoPickActivity;
import com.vincent.filepicker.filter.FileFilter;
import com.vincent.filepicker.filter.callback.FilterResultCallback;
import com.vincent.filepicker.filter.entity.AudioFile;
import com.vincent.filepicker.filter.entity.BaseFile;
import com.vincent.filepicker.filter.entity.Directory;
import com.vincent.filepicker.filter.entity.ImageFile;
import com.vincent.filepicker.filter.entity.NormalFile;
import com.vincent.filepicker.filter.entity.VideoFile;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.vincent.filepicker.activity.AudioPickActivity.IS_NEED_RECORDER;
import static com.vincent.filepicker.activity.BaseActivity.IS_NEED_FOLDER_LIST;
import static com.vincent.filepicker.activity.ImagePickActivity.IS_NEED_CAMERA;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private TextView mTvResult;

@Override
Expand Down Expand Up @@ -72,7 +63,7 @@ public void onClick(View v) {
intent4.putExtra(Constant.MAX_NUMBER, 9);
intent4.putExtra(IS_NEED_FOLDER_LIST, true);
intent4.putExtra(NormalFilePickActivity.SUFFIX,
new String[] {"xlsx", "xls", "doc", "dOcX", "ppt", ".pptx", "pdf"});
new String[]{"xlsx", "xls", "doc", "dOcX", "ppt", ".pptx", "pdf"});
startActivityForResult(intent4, Constant.REQUEST_CODE_PICK_FILE);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* Date: 2017/2/27
* Time: 14:46
*/

public class TheApplication extends Application {
@Override
public void onCreate() {
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

buildscript {
repositories {
jcenter()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -16,8 +16,8 @@ buildscript {

allprojects {
repositories {
jcenter()
google()
jcenter()
}
}

Expand Down
51 changes: 36 additions & 15 deletions filepicker/build.gradle
Original file line number Diff line number Diff line change
@@ -1,41 +1,62 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
compileSdkVersion 28
//buildToolsVersion "26.0.2"

defaultConfig {
minSdkVersion 14
targetSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
// Exclude file to avoid
// Error: Duplicate files during packaging of APK
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
lintOptions {
disable 'Deprecation'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '30.0.2'
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.1.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:26.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
//Glide
compile ("com.github.bumptech.glide:glide:4.6.1") {
implementation ("com.github.bumptech.glide:glide:4.11.0") {
exclude group: "com.android.support"
}
compile 'com.github.bumptech.glide:annotations:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
compile 'com.bm.photoview:library:1.4.1'
compile 'com.android.support:design:26.1.0'
compile 'pub.devrel:easypermissions:0.3.0'
implementation 'com.github.bumptech.glide:annotations:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.bm.photoview:library:1.4.1'
implementation 'com.google.android.material:material:1.0.0'
api 'pub.devrel:easypermissions:3.0.0'
}

apply from: 'publish.gradle'
6 changes: 6 additions & 0 deletions filepicker/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.vincent.filepicker;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
2 changes: 1 addition & 1 deletion filepicker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
android:screenOrientation="portrait"
android:theme="@style/vw_FilePickerTheme" />
<provider
android:name="android.support.v4.content.FileProvider"
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
Expand Down
4 changes: 4 additions & 0 deletions filepicker/src/main/java/com/vincent/filepicker/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

public class Constant {
public static final String MAX_NUMBER = "MaxNumber";
public static final String MAX_VIDEO_DURATION = "MaxVideoDuration";
public static final String VIDEO_QUALITY = "VideoQuality";
public static final String MAX_AUDIO_SIZE = "AudioFileSize";
public static final String DIRECTORY = "Directory";

public static final int REQUEST_CODE_PICK_IMAGE = 0x100;
public static final String RESULT_PICK_IMAGE = "ResultPickImage";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import android.view.View;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.vincent.filepicker.adapter.FolderListAdapter;
Expand Down
18 changes: 14 additions & 4 deletions filepicker/src/main/java/com/vincent/filepicker/Util.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.vincent.filepicker;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.DecelerateInterpolator;

import com.vincent.filepicker.filter.entity.BaseFile;

import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -131,4 +130,15 @@ public static String extractFileSuffix(String url) {
return "";
}
}

public static void sortFileList(List<? extends BaseFile> list) {
Collections.sort(list, (c1, c2) -> {
if (c1.getDate() > c2.getDate()) {
return -1;
} else if (c1.getDate() < c2.getDate()) {
return 1;
}
return 0;
});
}
}
Loading