From 47a57057f5073baed2c415fb3653d109fa04bc2d Mon Sep 17 00:00:00 2001 From: Jibon Lawrence Costa Date: Sat, 8 Sep 2018 14:37:22 +0800 Subject: [PATCH 01/10] Added few features * EXTRA_VIDEO_QUALITY * EXTRA_DURATION_LIMIT * EXTRA_MAX_BYTES --- README.md | 3 +++ .../java/com/vincent/filepicker/Constant.java | 3 +++ .../filepicker/activity/AudioPickActivity.java | 9 +++++++++ .../filepicker/activity/VideoPickActivity.java | 9 +++++++-- .../filepicker/adapter/VideoPickAdapter.java | 15 +++++++++++---- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6ad11d8..f7b088f 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/filepicker/src/main/java/com/vincent/filepicker/Constant.java b/filepicker/src/main/java/com/vincent/filepicker/Constant.java index 04d274f..511b9c8 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/Constant.java +++ b/filepicker/src/main/java/com/vincent/filepicker/Constant.java @@ -8,6 +8,9 @@ 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 int REQUEST_CODE_PICK_IMAGE = 0x100; public static final String RESULT_PICK_IMAGE = "ResultPickImage"; diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java index 1b7976b..b6c839e 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java @@ -41,6 +41,7 @@ public class AudioPickActivity extends BaseActivity { public static final int DEFAULT_MAX_NUMBER = 9; private int mMaxNumber; + private int mMaxSize = 0; private int mCurrentNumber = 0; private RecyclerView mRecyclerView; private AudioPickAdapter mAdapter; @@ -69,6 +70,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { mMaxNumber = getIntent().getIntExtra(Constant.MAX_NUMBER, DEFAULT_MAX_NUMBER); isNeedRecorder = getIntent().getBooleanExtra(IS_NEED_RECORDER, false); + mMaxSize = getIntent().getIntExtra(Constant.MAX_AUDIO_SIZE, 0); isTakenAutoSelected = getIntent().getBooleanExtra(IS_TAKEN_AUTO_SELECTED, true); initView(); } @@ -152,6 +154,13 @@ public void onFolderListClick(Directory directory) { @Override public void onClick(View v) { Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); + + if(mMaxSize > 0){ + String MAX_SIZE = android.provider.MediaStore.Audio.Media.EXTRA_MAX_BYTES; + long bytes = (long) (mMaxSize * 4L); + intent.putExtra(MAX_SIZE , bytes); + } + if (Util.detectIntent(AudioPickActivity.this, intent)) { startActivityForResult(intent, Constant.REQUEST_CODE_TAKE_AUDIO); } else { diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java index fa36965..a271846 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java @@ -40,9 +40,12 @@ public class VideoPickActivity extends BaseActivity { public static final String IS_TAKEN_AUTO_SELECTED = "IsTakenAutoSelected"; public static final int DEFAULT_MAX_NUMBER = 9; + public static final int DEFAULT_MAX_VIDEO_DURATION = 0; public static final int COLUMN_NUMBER = 3; private int mMaxNumber; - private int mCurrentNumber = 0; + private int mCurrentNumber; + private int mMaxVideoDuration = 0; + private int mVideoQuality = 1; private RecyclerView mRecyclerView; private VideoPickAdapter mAdapter; private boolean isNeedCamera; @@ -68,6 +71,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.vw_activity_video_pick); mMaxNumber = getIntent().getIntExtra(Constant.MAX_NUMBER, DEFAULT_MAX_NUMBER); + mMaxVideoDuration = getIntent().getIntExtra(Constant.MAX_VIDEO_DURATION, DEFAULT_MAX_VIDEO_DURATION); + mVideoQuality = getIntent().getIntExtra(Constant.VIDEO_QUALITY, 1); isNeedCamera = getIntent().getBooleanExtra(IS_NEED_CAMERA, false); isTakenAutoSelected = getIntent().getBooleanExtra(IS_TAKEN_AUTO_SELECTED, true); initView(); @@ -82,7 +87,7 @@ private void initView() { mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.addItemDecoration(new DividerGridItemDecoration(this)); - mAdapter = new VideoPickAdapter(this, isNeedCamera, mMaxNumber); + mAdapter = new VideoPickAdapter(this, isNeedCamera, mMaxNumber, mMaxVideoDuration, mVideoQuality); mRecyclerView.setAdapter(mAdapter); mAdapter.setOnSelectStateListener(new OnSelectStateListener() { diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java index f2dbed8..186f3a2 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java @@ -45,17 +45,21 @@ public class VideoPickAdapter extends BaseAdapter { private boolean isNeedCamera; private int mMaxNumber; + private int mMaxVideoDuration = 0; + private int mVideoQuality = 1; private int mCurrentNumber = 0; public String mVideoPath; - public VideoPickAdapter(Context ctx, boolean needCamera, int max) { - this(ctx, new ArrayList(), needCamera, max); + public VideoPickAdapter(Context ctx, boolean needCamera, int max, int duration, int quality) { + this(ctx, new ArrayList(), needCamera, max, duration, quality); } - public VideoPickAdapter(Context ctx, ArrayList list, boolean needCamera, int max) { + public VideoPickAdapter(Context ctx, ArrayList list, boolean needCamera, int max, int duration, int quality) { super(ctx, list); isNeedCamera = needCamera; mMaxNumber = max; + mMaxVideoDuration = duration; + mVideoQuality = quality; } @Override @@ -92,7 +96,10 @@ public void onClick(View v) { Uri uri = mContext.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); - intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); + intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, mVideoQuality); + if(mMaxVideoDuration > 0){ + intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT , mMaxVideoDuration); + } if (Util.detectIntent(mContext, intent)) { ((Activity) mContext).startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO); } else { From bed7ef67aa312116c98c9cc2b1ac16ac022da29c Mon Sep 17 00:00:00 2001 From: Jibon Lawrence Costa Date: Wed, 12 Sep 2018 10:52:23 +0800 Subject: [PATCH 02/10] fixed crash SD card files selection When you will select files from SD card the app will get crash but this patch will fix it. java.lang.IllegalArgumentException: Failed to find configured root that contains... --- filepicker/src/main/res/xml/file_paths.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/filepicker/src/main/res/xml/file_paths.xml b/filepicker/src/main/res/xml/file_paths.xml index ec07dbe..9d4658d 100644 --- a/filepicker/src/main/res/xml/file_paths.xml +++ b/filepicker/src/main/res/xml/file_paths.xml @@ -3,4 +3,7 @@ + \ No newline at end of file From b8f34e560d306aa2a02b8ee05e0bf610ce53f2c6 Mon Sep 17 00:00:00 2001 From: Jibon Lawrence Costa Date: Wed, 12 Sep 2018 14:37:42 +0800 Subject: [PATCH 03/10] .m4a file support --- .../com/vincent/filepicker/filter/loader/AudioLoader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java index f64fd0f..0e71b92 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java @@ -39,10 +39,10 @@ public AudioLoader(Context context) { setSelection(MIME_TYPE + "=? or " + MIME_TYPE + "=? or " -// + MIME_TYPE + "=? or " + + MIME_TYPE + "=? or " + MIME_TYPE + "=?"); String[] selectionArgs; - selectionArgs = new String[]{"audio/mpeg", "audio/mp3", "audio/x-ms-wma"}; + selectionArgs = new String[]{"audio/mpeg", "audio/mp3", "audio/x-ms-wma", "audio/mp4"}; setSelectionArgs(selectionArgs); } } From 4eaedc27c08eb1939153d91764a70a3d1fe69bd7 Mon Sep 17 00:00:00 2001 From: HarinKaklotar Date: Tue, 14 Jan 2020 20:51:52 +0530 Subject: [PATCH 04/10] update dependency androidx --- app/build.gradle | 25 +++++++---- .../ExampleInstrumentedTest.java | 4 +- .../LocalFileUncaughtExceptionHandler.java | 1 - .../filepickersample/MainActivity.java | 15 ++----- .../filepickersample/TheApplication.java | 1 - build.gradle | 6 +-- filepicker/build.gradle | 44 +++++++++++++------ filepicker/proguard-rules.pro | 6 +++ .../filepicker/ExampleInstrumentedTest.java | 4 +- filepicker/src/main/AndroidManifest.xml | 2 +- .../filepicker/DividerGridItemDecoration.java | 6 +-- .../filepicker/DividerListItemDecoration.java | 6 +-- .../vincent/filepicker/FolderListHelper.java | 8 ++-- .../activity/AudioPickActivity.java | 6 +-- .../filepicker/activity/BaseActivity.java | 9 ++-- .../activity/ImageBrowserActivity.java | 8 ++-- .../activity/ImagePickActivity.java | 4 +- .../activity/NormalFilePickActivity.java | 12 +++-- .../activity/VideoPickActivity.java | 6 +-- .../filepicker/adapter/AudioPickAdapter.java | 4 +- .../filepicker/adapter/BaseAdapter.java | 2 +- .../filepicker/adapter/FolderListAdapter.java | 4 +- .../filepicker/adapter/ImagePickAdapter.java | 2 +- .../adapter/NormalFilePickAdapter.java | 2 +- .../filepicker/adapter/VideoPickAdapter.java | 4 +- .../vincent/filepicker/filter/FileFilter.java | 2 +- .../filter/callback/FileLoaderCallbacks.java | 14 ++---- .../filepicker/filter/loader/AudioLoader.java | 2 +- .../filepicker/filter/loader/FileLoader.java | 4 +- .../filepicker/filter/loader/ImageLoader.java | 2 +- .../filepicker/filter/loader/VideoLoader.java | 2 +- .../res/layout/vw_activity_audio_pick.xml | 2 +- .../main/res/layout/vw_activity_file_pick.xml | 2 +- .../res/layout/vw_activity_image_browser.xml | 4 +- .../res/layout/vw_activity_image_pick.xml | 2 +- .../res/layout/vw_activity_video_pick.xml | 2 +- .../main/res/layout/vw_layout_folder_list.xml | 2 +- gradle.properties | 2 + gradle/wrapper/gradle-wrapper.properties | 4 +- 39 files changed, 120 insertions(+), 117 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b112300..0894159 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 26 - buildToolsVersion "26.0.2" + compileSdkVersion 28 + //buildToolsVersion "26.0.2" defaultConfig { applicationId "com.vincent.filepickersample" minSdkVersion 14 - targetSdkVersion 26 + targetSdkVersion 28 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -17,15 +17,22 @@ android { 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') } diff --git a/app/src/androidTest/java/com/vincent/filepickersample/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/vincent/filepickersample/ExampleInstrumentedTest.java index 0bb89a4..4e432a4 100644 --- a/app/src/androidTest/java/com/vincent/filepickersample/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/vincent/filepickersample/ExampleInstrumentedTest.java @@ -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; diff --git a/app/src/main/java/com/vincent/filepickersample/LocalFileUncaughtExceptionHandler.java b/app/src/main/java/com/vincent/filepickersample/LocalFileUncaughtExceptionHandler.java index cd65406..d9c9793 100644 --- a/app/src/main/java/com/vincent/filepickersample/LocalFileUncaughtExceptionHandler.java +++ b/app/src/main/java/com/vincent/filepickersample/LocalFileUncaughtExceptionHandler.java @@ -21,7 +21,6 @@ * Date: 2015/10/29 * Time: 15:31 */ - public class LocalFileUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { private Context mContext; private Thread.UncaughtExceptionHandler mDefaultHandler; diff --git a/app/src/main/java/com/vincent/filepickersample/MainActivity.java b/app/src/main/java/com/vincent/filepickersample/MainActivity.java index 06ea11b..e7d02bf 100644 --- a/app/src/main/java/com/vincent/filepickersample/MainActivity.java +++ b/app/src/main/java/com/vincent/filepickersample/MainActivity.java @@ -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 @@ -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; } diff --git a/app/src/main/java/com/vincent/filepickersample/TheApplication.java b/app/src/main/java/com/vincent/filepickersample/TheApplication.java index 3d05f52..d9c0d49 100644 --- a/app/src/main/java/com/vincent/filepickersample/TheApplication.java +++ b/app/src/main/java/com/vincent/filepickersample/TheApplication.java @@ -7,7 +7,6 @@ * Date: 2017/2/27 * Time: 14:46 */ - public class TheApplication extends Application { @Override public void onCreate() { diff --git a/build.gradle b/build.gradle index b0c2fb8..58563d4 100644 --- a/build.gradle +++ b/build.gradle @@ -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:3.5.3' 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 @@ -16,8 +16,8 @@ buildscript { allprojects { repositories { - jcenter() google() + jcenter() } } diff --git a/filepicker/build.gradle b/filepicker/build.gradle index ecc6a0a..f698372 100644 --- a/filepicker/build.gradle +++ b/filepicker/build.gradle @@ -1,15 +1,15 @@ 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 { @@ -17,25 +17,41 @@ android { 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' + } } 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.6.1") { exclude group: "com.android.support" } - compile 'com.github.bumptech.glide:annotations:4.6.1' + implementation '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.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' \ No newline at end of file diff --git a/filepicker/proguard-rules.pro b/filepicker/proguard-rules.pro index 808e1a7..ce91729 100644 --- a/filepicker/proguard-rules.pro +++ b/filepicker/proguard-rules.pro @@ -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 *; +} \ No newline at end of file diff --git a/filepicker/src/androidTest/java/com/vincent/filepicker/ExampleInstrumentedTest.java b/filepicker/src/androidTest/java/com/vincent/filepicker/ExampleInstrumentedTest.java index 400719b..471d53c 100644 --- a/filepicker/src/androidTest/java/com/vincent/filepicker/ExampleInstrumentedTest.java +++ b/filepicker/src/androidTest/java/com/vincent/filepicker/ExampleInstrumentedTest.java @@ -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; diff --git a/filepicker/src/main/AndroidManifest.xml b/filepicker/src/main/AndroidManifest.xml index 229e584..492fb23 100644 --- a/filepicker/src/main/AndroidManifest.xml +++ b/filepicker/src/main/AndroidManifest.xml @@ -30,7 +30,7 @@ android:screenOrientation="portrait" android:theme="@style/vw_FilePickerTheme" /> diff --git a/filepicker/src/main/java/com/vincent/filepicker/DividerGridItemDecoration.java b/filepicker/src/main/java/com/vincent/filepicker/DividerGridItemDecoration.java index d7b95fc..9de28bf 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/DividerGridItemDecoration.java +++ b/filepicker/src/main/java/com/vincent/filepicker/DividerGridItemDecoration.java @@ -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; /** diff --git a/filepicker/src/main/java/com/vincent/filepicker/DividerListItemDecoration.java b/filepicker/src/main/java/com/vincent/filepicker/DividerListItemDecoration.java index 1660d7e..7658f15 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/DividerListItemDecoration.java +++ b/filepicker/src/main/java/com/vincent/filepicker/DividerListItemDecoration.java @@ -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; /** diff --git a/filepicker/src/main/java/com/vincent/filepicker/FolderListHelper.java b/filepicker/src/main/java/com/vincent/filepicker/FolderListHelper.java index 697372e..decd484 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/FolderListHelper.java +++ b/filepicker/src/main/java/com/vincent/filepicker/FolderListHelper.java @@ -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; diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java index 1b7976b..e867f47 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java @@ -3,9 +3,9 @@ import android.content.Intent; import android.os.Bundle; import android.provider.MediaStore; -import android.support.annotation.Nullable; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.text.TextUtils; import android.view.View; import android.widget.LinearLayout; diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/BaseActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/BaseActivity.java index 71d5724..4fa43d9 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/BaseActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/BaseActivity.java @@ -2,16 +2,14 @@ import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import android.util.Log; import android.view.View; import com.vincent.filepicker.FolderListHelper; import com.vincent.filepicker.R; -import com.vincent.filepicker.adapter.FolderListAdapter; -import com.vincent.filepicker.filter.entity.Directory; import java.util.List; @@ -19,6 +17,7 @@ import pub.devrel.easypermissions.AppSettingsDialog; import pub.devrel.easypermissions.EasyPermissions; + /** * Created by Vincent Woo * Date: 2016/10/12 diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java index 1611246..cdba8a1 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java @@ -2,10 +2,10 @@ import android.content.Intent; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.view.PagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v7.widget.Toolbar; +import androidx.annotation.Nullable; +import androidx.viewpager.widget.PagerAdapter; +import androidx.viewpager.widget.ViewPager; +import androidx.appcompat.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/ImagePickActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/ImagePickActivity.java index 04ad15d..b1d6d3f 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/ImagePickActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/ImagePickActivity.java @@ -3,8 +3,8 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.text.TextUtils; import android.view.View; import android.widget.LinearLayout; diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/NormalFilePickActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/NormalFilePickActivity.java index ca704b2..7579f6d 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/NormalFilePickActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/NormalFilePickActivity.java @@ -2,14 +2,12 @@ import android.content.Intent; import android.os.Bundle; -import android.os.Handler; -import android.support.annotation.Nullable; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; + +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.appcompat.widget.Toolbar; import android.text.TextUtils; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; import android.widget.LinearLayout; import android.widget.ProgressBar; diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java index fa36965..4cc89f4 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java @@ -3,9 +3,9 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.text.TextUtils; import android.view.View; import android.widget.LinearLayout; diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/AudioPickAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/AudioPickAdapter.java index 97375b2..1220291 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/AudioPickAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/AudioPickAdapter.java @@ -4,8 +4,8 @@ import android.content.Intent; import android.net.Uri; import android.os.Build; -import android.support.v4.content.FileProvider; -import android.support.v7.widget.RecyclerView; +import androidx.core.content.FileProvider; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/BaseAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/BaseAdapter.java index 09f8362..8352727 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/BaseAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/BaseAdapter.java @@ -1,7 +1,7 @@ package com.vincent.filepicker.adapter; import android.content.Context; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.List; diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/FolderListAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/FolderListAdapter.java index e3a3f90..33b1521 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/FolderListAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/FolderListAdapter.java @@ -1,7 +1,7 @@ package com.vincent.filepicker.adapter; import android.content.Context; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -9,10 +9,8 @@ import com.vincent.filepicker.R; import com.vincent.filepicker.filter.entity.Directory; -import com.vincent.filepicker.filter.entity.ImageFile; import java.util.ArrayList; -import java.util.List; /** * Created by Vincent Woo diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java index e35827d..e915997 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java @@ -7,7 +7,7 @@ import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/NormalFilePickAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/NormalFilePickAdapter.java index fef09f3..79d9979 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/NormalFilePickAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/NormalFilePickAdapter.java @@ -1,7 +1,7 @@ package com.vincent.filepicker.adapter; import android.content.Context; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java index f2dbed8..5d1ed45 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java @@ -8,8 +8,8 @@ import android.os.Build; import android.os.Environment; import android.provider.MediaStore; -import android.support.v4.content.FileProvider; -import android.support.v7.widget.RecyclerView; +import androidx.core.content.FileProvider; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/FileFilter.java b/filepicker/src/main/java/com/vincent/filepicker/filter/FileFilter.java index 43725ea..8eb4795 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/FileFilter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/FileFilter.java @@ -1,6 +1,6 @@ package com.vincent.filepicker.filter; -import android.support.v4.app.FragmentActivity; +import androidx.fragment.app.FragmentActivity; import com.vincent.filepicker.filter.callback.FileLoaderCallbacks; import com.vincent.filepicker.filter.callback.FilterResultCallback; diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java b/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java index b07c102..cd2f0e2 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java @@ -2,13 +2,10 @@ import android.content.Context; import android.database.Cursor; -import android.graphics.Bitmap; -import android.media.MediaMetadataRetriever; -import android.media.ThumbnailUtils; import android.os.Bundle; -import android.support.v4.app.LoaderManager; -import android.support.v4.content.CursorLoader; -import android.support.v4.content.Loader; +import androidx.loader.app.LoaderManager; +import androidx.loader.content.CursorLoader; +import androidx.loader.content.Loader; import com.vincent.filepicker.Util; import com.vincent.filepicker.filter.entity.AudioFile; @@ -21,14 +18,9 @@ import com.vincent.filepicker.filter.loader.ImageLoader; import com.vincent.filepicker.filter.loader.VideoLoader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java index f64fd0f..21dae59 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java @@ -3,7 +3,7 @@ import android.content.Context; import android.net.Uri; import android.provider.MediaStore; -import android.support.v4.content.CursorLoader; +import androidx.loader.content.CursorLoader; import static android.provider.MediaStore.MediaColumns.MIME_TYPE; diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/FileLoader.java b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/FileLoader.java index 9059dd2..6ed8160 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/FileLoader.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/FileLoader.java @@ -3,9 +3,7 @@ import android.content.Context; import android.net.Uri; import android.provider.MediaStore; -import android.support.v4.content.CursorLoader; - -import static android.provider.MediaStore.MediaColumns.MIME_TYPE; +import androidx.loader.content.CursorLoader; /** * Created by Vincent Woo diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/ImageLoader.java b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/ImageLoader.java index 26d3f19..67f41e6 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/ImageLoader.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/ImageLoader.java @@ -3,7 +3,7 @@ import android.content.Context; import android.net.Uri; import android.provider.MediaStore; -import android.support.v4.content.CursorLoader; +import androidx.loader.content.CursorLoader; import static android.provider.MediaStore.MediaColumns.MIME_TYPE; diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/VideoLoader.java b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/VideoLoader.java index fe3978c..af6f5c4 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/VideoLoader.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/VideoLoader.java @@ -3,7 +3,7 @@ import android.content.Context; import android.net.Uri; import android.provider.MediaStore; -import android.support.v4.content.CursorLoader; +import androidx.loader.content.CursorLoader; import static android.provider.MediaStore.MediaColumns.MIME_TYPE; diff --git a/filepicker/src/main/res/layout/vw_activity_audio_pick.xml b/filepicker/src/main/res/layout/vw_activity_audio_pick.xml index 01b1746..7b2e31d 100644 --- a/filepicker/src/main/res/layout/vw_activity_audio_pick.xml +++ b/filepicker/src/main/res/layout/vw_activity_audio_pick.xml @@ -6,7 +6,7 @@ - - - - - - - Date: Fri, 28 Feb 2020 23:31:54 +0600 Subject: [PATCH 05/10] update glide --- .gitignore | 1 + filepicker/build.gradle | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 3cecf96..ea94aa6 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ proguard/ # Log Files *.log +.DS_Store # Android Studio Navigation editor temp files .navigation/ diff --git a/filepicker/build.gradle b/filepicker/build.gradle index f698372..0123a3b 100644 --- a/filepicker/build.gradle +++ b/filepicker/build.gradle @@ -44,11 +44,11 @@ dependencies { testImplementation 'junit:junit:4.12' implementation 'androidx.recyclerview:recyclerview:1.1.0' //Glide - implementation ("com.github.bumptech.glide:glide:4.6.1") { + implementation ("com.github.bumptech.glide:glide:4.11.0") { exclude group: "com.android.support" } - implementation 'com.github.bumptech.glide:annotations:4.6.1' - annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1' + 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' From df35394746580aa9e73f142bece544c6838e73f8 Mon Sep 17 00:00:00 2001 From: hugo Date: Fri, 17 Jul 2020 17:53:29 -0300 Subject: [PATCH 06/10] show images on Android 10 fixed --- app/build.gradle | 4 ++-- build.gradle | 2 +- .../activity/ImageBrowserActivity.java | 2 +- .../filepicker/adapter/AudioPickAdapter.java | 18 ++++-------------- .../filepicker/adapter/ImagePickAdapter.java | 2 +- .../filepicker/adapter/VideoPickAdapter.java | 18 +++++------------- .../vincent/filepicker/filter/FileFilter.java | 9 +++++---- .../filter/callback/FileLoaderCallbacks.java | 13 +++++++++++++ .../filepicker/filter/entity/BaseFile.java | 10 ++++++++++ gradle/wrapper/gradle-wrapper.properties | 4 ++-- 10 files changed, 44 insertions(+), 38 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0894159..b160916 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 + compileSdkVersion 29 //buildToolsVersion "26.0.2" defaultConfig { applicationId "com.vincent.filepickersample" minSdkVersion 14 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/build.gradle b/build.gradle index 58563d4..becc81b 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.3' + classpath 'com.android.tools.build:gradle:4.0.0' 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 diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java index cdba8a1..e18dc35 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java @@ -157,7 +157,7 @@ public Object instantiateItem(ViewGroup container, int position) { view.setScaleType(ImageView.ScaleType.CENTER_INSIDE); Glide.with(ImageBrowserActivity.this) - .load(mList.get(position).getPath()) + .load(mList.get(position).getUri()) .transition(withCrossFade()) .into(view); container.addView(view); diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/AudioPickAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/AudioPickAdapter.java index 1220291..9f0c513 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/AudioPickAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/AudioPickAdapter.java @@ -2,22 +2,19 @@ import android.content.Context; import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import androidx.core.content.FileProvider; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import androidx.recyclerview.widget.RecyclerView; + import com.vincent.filepicker.R; import com.vincent.filepicker.ToastUtil; import com.vincent.filepicker.Util; import com.vincent.filepicker.filter.entity.AudioFile; -import java.io.File; import java.util.ArrayList; /** @@ -93,15 +90,8 @@ public void onClick(View v) { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); - Uri uri; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - File f = new File(file.getPath()); - uri = FileProvider.getUriForFile(mContext, mContext.getApplicationContext().getPackageName() + ".provider", f); - }else{ - uri = Uri.parse("file://" + file.getPath()); - } - intent.setDataAndType(uri, "audio/mp3"); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setDataAndType(file.getUri(), "audio/mp3"); if (Util.detectIntent(mContext, intent)) { mContext.startActivity(intent); } else { diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java index e915997..d343dc0 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java @@ -114,7 +114,7 @@ public void onClick(View v) { RequestOptions options = new RequestOptions(); Glide.with(mContext) - .load(file.getPath()) + .load(file.getUri()) .apply(options.centerCrop()) .transition(withCrossFade()) // .transition(new DrawableTransitionOptions().crossFade(500)) diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java index e28786f..ffa7874 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java @@ -5,11 +5,8 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.os.Build; import android.os.Environment; import android.provider.MediaStore; -import androidx.core.content.FileProvider; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -18,6 +15,8 @@ import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.recyclerview.widget.RecyclerView; + import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.vincent.filepicker.R; @@ -122,7 +121,7 @@ public void onClick(View v) { RequestOptions options = new RequestOptions(); Glide.with(mContext) - .load(file.getPath()) + .load(file.getUri()) .apply(options.centerCrop()) .transition(withCrossFade()) // .transition(new DrawableTransitionOptions().crossFade(500)) @@ -167,15 +166,8 @@ public void onClick(View v) { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); - Uri uri; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - File f = new File(file.getPath()); - uri = FileProvider.getUriForFile(mContext, mContext.getApplicationContext().getPackageName() + ".provider", f); - }else{ - uri = Uri.parse("file://" + file.getPath()); - } - intent.setDataAndType(uri, "video/mp4"); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setDataAndType(file.getUri(), "video/mp4"); if (Util.detectIntent(mContext, intent)) { mContext.startActivity(intent); } else { diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/FileFilter.java b/filepicker/src/main/java/com/vincent/filepicker/filter/FileFilter.java index 8eb4795..ec0985c 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/FileFilter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/FileFilter.java @@ -1,6 +1,7 @@ package com.vincent.filepicker.filter; import androidx.fragment.app.FragmentActivity; +import androidx.loader.app.LoaderManager; import com.vincent.filepicker.filter.callback.FileLoaderCallbacks; import com.vincent.filepicker.filter.callback.FilterResultCallback; @@ -22,23 +23,23 @@ public class FileFilter { public static void getImages(FragmentActivity activity, FilterResultCallback callback){ - activity.getSupportLoaderManager().initLoader(0, null, + LoaderManager.getInstance(activity).initLoader(0, null, new FileLoaderCallbacks(activity, callback, TYPE_IMAGE)); } public static void getVideos(FragmentActivity activity, FilterResultCallback callback){ - activity.getSupportLoaderManager().initLoader(1, null, + LoaderManager.getInstance(activity).initLoader(1, null, new FileLoaderCallbacks(activity, callback, TYPE_VIDEO)); } public static void getAudios(FragmentActivity activity, FilterResultCallback callback){ - activity.getSupportLoaderManager().initLoader(2, null, + LoaderManager.getInstance(activity).initLoader(2, null, new FileLoaderCallbacks(activity, callback, TYPE_AUDIO)); } public static void getFiles(FragmentActivity activity, FilterResultCallback callback, String[] suffix){ - activity.getSupportLoaderManager().initLoader(3, null, + LoaderManager.getInstance(activity).initLoader(3, null, new FileLoaderCallbacks(activity, callback, TYPE_FILE, suffix)); } } diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java b/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java index cd2f0e2..02515f2 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java @@ -1,8 +1,12 @@ package com.vincent.filepicker.filter.callback; +import android.content.ContentUris; import android.content.Context; import android.database.Cursor; +import android.net.Uri; import android.os.Bundle; +import android.provider.MediaStore; + import androidx.loader.app.LoaderManager; import androidx.loader.content.CursorLoader; import androidx.loader.content.Loader; @@ -134,6 +138,9 @@ private void onImageResult(Cursor data) { img.setOrientation(data.getInt(data.getColumnIndexOrThrow(ORIENTATION))); + Uri uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, img.getId()); + img.setUri(uri); + //Create a Directory Directory directory = new Directory<>(); directory.setId(img.getBucketId()); @@ -174,6 +181,9 @@ private void onVideoResult(final Cursor data) { video.setDuration(data.getLong(data.getColumnIndexOrThrow(DURATION))); + Uri uri = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, video.getId()); + video.setUri(uri); + //Create a Directory Directory directory = new Directory<>(); directory.setId(video.getBucketId()); @@ -212,6 +222,9 @@ private void onAudioResult(Cursor data) { audio.setDuration(data.getLong(data.getColumnIndexOrThrow(DURATION))); + Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, audio.getId()); + audio.setUri(uri); + //Create a Directory Directory directory = new Directory<>(); directory.setName(Util.extractFileNameWithSuffix(Util.extractPathWithoutSeparator(audio.getPath()))); diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/entity/BaseFile.java b/filepicker/src/main/java/com/vincent/filepicker/filter/entity/BaseFile.java index e760d33..70c7aeb 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/entity/BaseFile.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/entity/BaseFile.java @@ -1,5 +1,6 @@ package com.vincent.filepicker.filter.entity; +import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; @@ -13,6 +14,7 @@ public class BaseFile implements Parcelable { private long id; private String name; private String path; + private Uri uri; private long size; //byte private String bucketId; //Directory ID private String bucketName; //Directory Name @@ -57,6 +59,14 @@ public void setPath(String path) { this.path = path; } + public Uri getUri() { + return uri; + } + + public void setUri(Uri uri) { + this.uri = uri; + } + public long getSize() { return size; } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 696b99c..5cb3f97 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Dec 29 18:00:03 IST 2019 +#Fri Jul 17 11:34:37 BRT 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip From f72bbe24c5050b37a7b664a7ce4ec13b66e92178 Mon Sep 17 00:00:00 2001 From: hugo Date: Tue, 21 Jul 2020 11:58:05 -0300 Subject: [PATCH 07/10] Fixed when using android:requestLegacyExternalStorage="true" generates an error when trying to record video --- .../java/com/vincent/filepicker/adapter/VideoPickAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java index ffa7874..5b271a2 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/VideoPickAdapter.java @@ -91,8 +91,8 @@ public void onClick(View v) { mVideoPath = file.getAbsolutePath(); ContentValues contentValues = new ContentValues(1); - contentValues.put(MediaStore.Images.Media.DATA, mVideoPath); - Uri uri = mContext.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues); + contentValues.put(MediaStore.Video.Media.DATA, mVideoPath); + Uri uri = mContext.getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentValues); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, mVideoQuality); From e18a4da856b316c15cf883815d0133702354b468 Mon Sep 17 00:00:00 2001 From: hugo Date: Thu, 6 Aug 2020 16:46:04 -0300 Subject: [PATCH 08/10] adjusted AudioLoader to get other types of audio --- build.gradle | 2 +- .../filepicker/filter/callback/FileLoaderCallbacks.java | 3 +++ .../vincent/filepicker/filter/loader/AudioLoader.java | 9 +-------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index becc81b..51c4cd0 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + 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 diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java b/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java index 02515f2..c63c475 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/callback/FileLoaderCallbacks.java @@ -264,6 +264,9 @@ private void onFileResult(Cursor data) { file.setMimeType(data.getString(data.getColumnIndexOrThrow(MIME_TYPE))); + Uri uri = ContentUris.withAppendedId(MediaStore.Files.getContentUri("external"), file.getId()); + file.setUri(uri); + //Create a Directory Directory directory = new Directory<>(); directory.setName(Util.extractFileNameWithSuffix(Util.extractPathWithoutSeparator(file.getPath()))); diff --git a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java index c945006..e06fc23 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java +++ b/filepicker/src/main/java/com/vincent/filepicker/filter/loader/AudioLoader.java @@ -34,15 +34,8 @@ public AudioLoader(Context context) { super(context); setProjection(AUDIO_PROJECTION); - setUri(MediaStore.Files.getContentUri("external")); + setUri(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI); setSortOrder(MediaStore.Audio.Media.DATE_ADDED + " DESC"); - setSelection(MIME_TYPE + "=? or " - + MIME_TYPE + "=? or " - + MIME_TYPE + "=? or " - + MIME_TYPE + "=?"); - String[] selectionArgs; - selectionArgs = new String[]{"audio/mpeg", "audio/mp3", "audio/x-ms-wma", "audio/mp4"}; - setSelectionArgs(selectionArgs); } } From 601fb37b1b8ab619441f9d17bade55743feeb3c3 Mon Sep 17 00:00:00 2001 From: Mark van de Korput Date: Fri, 25 Sep 2020 10:57:46 +0200 Subject: [PATCH 09/10] Fixes #70 check getExternalCacheDir for null result --- build.gradle | 2 +- .../activity/VideoPickActivity.java | 21 +++++++++++++------ gradle/wrapper/gradle-wrapper.properties | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 58563d4..51c4cd0 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.3' + 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 diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java index 9def973..9316d4c 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java @@ -105,12 +105,12 @@ public void OnSelectStateChanged(boolean state, VideoFile file) { }); mProgressBar = (ProgressBar) findViewById(R.id.pb_video_pick); - File folder = new File(getExternalCacheDir().getAbsolutePath() + File.separator + THUMBNAIL_PATH); - if (!folder.exists()) { - mProgressBar.setVisibility(View.VISIBLE); - } else { - mProgressBar.setVisibility(View.GONE); - } + + File thumbnailFolderFile = this.getThumbnailFolderFile(); + mProgressBar.setVisibility( + thumbnailFolderFile == null || !thumbnailFolderFile.exists() + ? View.VISIBLE + : View.GONE); rl_done = (RelativeLayout) findViewById(R.id.rl_done); rl_done.setOnClickListener(new View.OnClickListener() { @@ -159,6 +159,15 @@ public void onFolderListClick(Directory directory) { } } + /** + * @return null if there is no external storage available, otherwise a File + * instance referencing to the thumbnail file. + */ + private File getThumbnailFolderFile() { + File f = getExternalCacheDir(); + return f == null ? null : new File(f.getAbsolutePath(), THUMBNAIL_PATH); + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 696b99c..5030579 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Dec 29 18:00:03 IST 2019 +#Fri Sep 25 10:43:54 CEST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip From 8e640d4f90c125d218da18d675ce32c48023f758 Mon Sep 17 00:00:00 2001 From: hugo Date: Fri, 2 Oct 2020 14:21:29 -0300 Subject: [PATCH 10/10] sort files by the date added when you have not selected a folder show the correct image when opening it when you have a folder selected --- filepicker/build.gradle | 5 +++ .../java/com/vincent/filepicker/Constant.java | 1 + .../java/com/vincent/filepicker/Util.java | 18 +++++++--- .../activity/AudioPickActivity.java | 25 +++++++------- .../activity/ImageBrowserActivity.java | 18 +++++++--- .../activity/ImagePickActivity.java | 33 +++++++++++-------- .../activity/NormalFilePickActivity.java | 25 +++++++------- .../activity/VideoPickActivity.java | 33 ++++++++++--------- .../filepicker/adapter/ImagePickAdapter.java | 6 ++++ 9 files changed, 102 insertions(+), 62 deletions(-) diff --git a/filepicker/build.gradle b/filepicker/build.gradle index 0123a3b..d61a0d5 100644 --- a/filepicker/build.gradle +++ b/filepicker/build.gradle @@ -33,6 +33,11 @@ android { lintOptions { disable 'Deprecation' } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + buildToolsVersion '30.0.2' } dependencies { diff --git a/filepicker/src/main/java/com/vincent/filepicker/Constant.java b/filepicker/src/main/java/com/vincent/filepicker/Constant.java index 511b9c8..290e72c 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/Constant.java +++ b/filepicker/src/main/java/com/vincent/filepicker/Constant.java @@ -11,6 +11,7 @@ public class Constant { 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"; diff --git a/filepicker/src/main/java/com/vincent/filepicker/Util.java b/filepicker/src/main/java/com/vincent/filepicker/Util.java index edd6350..28864c3 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/Util.java +++ b/filepicker/src/main/java/com/vincent/filepicker/Util.java @@ -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; /** @@ -131,4 +130,15 @@ public static String extractFileSuffix(String url) { return ""; } } + + public static void sortFileList(List list) { + Collections.sort(list, (c1, c2) -> { + if (c1.getDate() > c2.getDate()) { + return -1; + } else if (c1.getDate() < c2.getDate()) { + return 1; + } + return 0; + }); + } } diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java index ee912f2..7bea7f2 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/AudioPickActivity.java @@ -43,6 +43,7 @@ public class AudioPickActivity extends BaseActivity { private int mMaxNumber; private int mMaxSize = 0; private int mCurrentNumber = 0; + private String selectedDirectory; private RecyclerView mRecyclerView; private AudioPickAdapter mAdapter; private boolean isNeedRecorder; @@ -132,17 +133,11 @@ public void onFolderListClick(Directory directory) { tv_folder.setText(directory.getName()); if (TextUtils.isEmpty(directory.getPath())) { //All - refreshData(mAll); + selectedDirectory = null; } else { - for (Directory dir : mAll) { - if (dir.getPath().equals(directory.getPath())) { - List> list = new ArrayList<>(); - list.add(dir); - refreshData(list); - break; - } - } + selectedDirectory = directory.getPath(); } + refreshData(); } }); } @@ -186,12 +181,12 @@ public void onResult(List> directories) { } mAll = directories; - refreshData(directories); + refreshData(); } }); } - private void refreshData(List> directories) { + private void refreshData() { boolean tryToFindTaken = isTakenAutoSelected; // if auto-select taken file is enabled, make sure requirements are met @@ -201,7 +196,10 @@ private void refreshData(List> directories) { } List list = new ArrayList<>(); - for (Directory directory : directories) { + for (Directory directory : mAll) { + if (selectedDirectory != null && !directory.getPath().equals(selectedDirectory)) { + continue; + } list.addAll(directory.getFiles()); // auto-select taken file? @@ -216,6 +214,9 @@ private void refreshData(List> directories) { list.get(index).setSelected(true); } } + + Util.sortFileList(list); + mAdapter.refresh(list); } diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java index e18dc35..269a00c 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/ImageBrowserActivity.java @@ -2,21 +2,23 @@ import android.content.Intent; import android.os.Bundle; -import androidx.annotation.Nullable; -import androidx.viewpager.widget.PagerAdapter; -import androidx.viewpager.widget.ViewPager; -import androidx.appcompat.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.viewpager.widget.PagerAdapter; +import androidx.viewpager.widget.ViewPager; + import com.bm.library.PhotoView; import com.bumptech.glide.Glide; import com.vincent.filepicker.Constant; import com.vincent.filepicker.R; import com.vincent.filepicker.ToastUtil; +import com.vincent.filepicker.Util; import com.vincent.filepicker.filter.FileFilter; import com.vincent.filepicker.filter.callback.FilterResultCallback; import com.vincent.filepicker.filter.entity.Directory; @@ -38,6 +40,7 @@ public class ImageBrowserActivity extends BaseActivity { public static final String IMAGE_BROWSER_INIT_INDEX = "ImageBrowserInitIndex"; public static final String IMAGE_BROWSER_SELECTED_LIST = "ImageBrowserSelectedList"; private int mMaxNumber; + private String selectedDirectory; private int mCurrentNumber = 0; private int initIndex = 0; private int mCurrentIndex = 0; @@ -57,6 +60,7 @@ void permissionGranted() { protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.vw_activity_image_browser); + selectedDirectory = getIntent().getStringExtra(Constant.DIRECTORY); mMaxNumber = getIntent().getIntExtra(Constant.MAX_NUMBER, DEFAULT_MAX_NUMBER); initIndex = getIntent().getIntExtra(IMAGE_BROWSER_INIT_INDEX, 0); mCurrentIndex = initIndex; @@ -134,7 +138,9 @@ private void loadData() { public void onResult(List> directories) { mList.clear(); for (Directory directory : directories) { - mList.addAll(directory.getFiles()); + if (selectedDirectory == null || directory.getPath().equals(selectedDirectory)) { + mList.addAll(directory.getFiles()); + } } for (ImageFile file : mList) { @@ -143,6 +149,8 @@ public void onResult(List> directories) { } } + Util.sortFileList(mList); + initView(); mViewPager.getAdapter().notifyDataSetChanged(); } diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/ImagePickActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/ImagePickActivity.java index b1d6d3f..83da124 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/ImagePickActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/ImagePickActivity.java @@ -3,17 +3,19 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.text.TextUtils; import android.view.View; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import com.vincent.filepicker.Constant; import com.vincent.filepicker.DividerGridItemDecoration; import com.vincent.filepicker.R; +import com.vincent.filepicker.Util; import com.vincent.filepicker.adapter.FolderListAdapter; import com.vincent.filepicker.adapter.ImagePickAdapter; import com.vincent.filepicker.adapter.OnSelectStateListener; @@ -41,6 +43,7 @@ public class ImagePickActivity extends BaseActivity { public static final int COLUMN_NUMBER = 3; private int mMaxNumber; private int mCurrentNumber = 0; + private String selectedDirectory; private RecyclerView mRecyclerView; private ImagePickAdapter mAdapter; private boolean isNeedCamera; @@ -128,17 +131,13 @@ public void onFolderListClick(Directory directory) { tv_folder.setText(directory.getName()); if (TextUtils.isEmpty(directory.getPath())) { //All - refreshData(mAll); + selectedDirectory = null; + mAdapter.setSelectedDirectory(null); } else { - for (Directory dir : mAll) { - if (dir.getPath().equals(directory.getPath())) { - List> list = new ArrayList<>(); - list.add(dir); - refreshData(list); - break; - } - } + selectedDirectory = directory.getPath(); + mAdapter.setSelectedDirectory(directory.getPath()); } + refreshData(); } }); } @@ -199,12 +198,12 @@ public void onResult(List> directories) { } mAll = directories; - refreshData(directories); + refreshData(); } }); } - private void refreshData(List> directories) { + private void refreshData() { boolean tryToFindTakenImage = isTakenAutoSelected; // if auto-select taken image is enabled, make sure requirements are met @@ -214,7 +213,10 @@ private void refreshData(List> directories) { } List list = new ArrayList<>(); - for (Directory directory : directories) { + for (Directory directory : mAll) { + if (selectedDirectory != null && !directory.getPath().equals(selectedDirectory)) { + continue; + } list.addAll(directory.getFiles()); // auto-select taken images? @@ -229,6 +231,9 @@ private void refreshData(List> directories) { list.get(index).setSelected(true); } } + + Util.sortFileList(list); + mAdapter.refresh(list); } diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/NormalFilePickActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/NormalFilePickActivity.java index 7579f6d..5accf56 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/NormalFilePickActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/NormalFilePickActivity.java @@ -17,6 +17,7 @@ import com.vincent.filepicker.Constant; import com.vincent.filepicker.DividerListItemDecoration; import com.vincent.filepicker.R; +import com.vincent.filepicker.Util; import com.vincent.filepicker.adapter.FolderListAdapter; import com.vincent.filepicker.adapter.NormalFilePickAdapter; import com.vincent.filepicker.adapter.OnSelectStateListener; @@ -39,6 +40,7 @@ public class NormalFilePickActivity extends BaseActivity { public static final String SUFFIX = "Suffix"; private int mMaxNumber; private int mCurrentNumber = 0; + private String selectedDirectory; private RecyclerView mRecyclerView; private NormalFilePickAdapter mAdapter; private ArrayList mSelectedList = new ArrayList<>(); @@ -126,17 +128,11 @@ public void onFolderListClick(Directory directory) { tv_folder.setText(directory.getName()); if (TextUtils.isEmpty(directory.getPath())) { //All - refreshData(mAll); + selectedDirectory = null; } else { - for (Directory dir : mAll) { - if (dir.getPath().equals(directory.getPath())) { - List> list = new ArrayList<>(); - list.add(dir); - refreshData(list); - break; - } - } + selectedDirectory = directory.getPath(); } + refreshData(); } }); } @@ -157,15 +153,18 @@ public void onResult(List> directories) { } mAll = directories; - refreshData(directories); + refreshData(); } }, mSuffix); } - private void refreshData(List> directories) { + private void refreshData() { mProgressBar.setVisibility(View.GONE); List list = new ArrayList<>(); - for (Directory directory : directories) { + for (Directory directory : mAll) { + if (selectedDirectory != null && !directory.getPath().equals(selectedDirectory)) { + continue; + } list.addAll(directory.getFiles()); } @@ -176,6 +175,8 @@ private void refreshData(List> directories) { } } + Util.sortFileList(list); + mAdapter.refresh(list); } } diff --git a/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java b/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java index 9def973..e339bdd 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java +++ b/filepicker/src/main/java/com/vincent/filepicker/activity/VideoPickActivity.java @@ -3,9 +3,6 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.text.TextUtils; import android.view.View; import android.widget.LinearLayout; @@ -13,9 +10,14 @@ import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import com.vincent.filepicker.Constant; import com.vincent.filepicker.DividerGridItemDecoration; import com.vincent.filepicker.R; +import com.vincent.filepicker.Util; import com.vincent.filepicker.adapter.FolderListAdapter; import com.vincent.filepicker.adapter.OnSelectStateListener; import com.vincent.filepicker.adapter.VideoPickAdapter; @@ -46,6 +48,7 @@ public class VideoPickActivity extends BaseActivity { private int mCurrentNumber; private int mMaxVideoDuration = 0; private int mVideoQuality = 1; + private String selectedDirectory; private RecyclerView mRecyclerView; private VideoPickAdapter mAdapter; private boolean isNeedCamera; @@ -143,17 +146,11 @@ public void onFolderListClick(Directory directory) { tv_folder.setText(directory.getName()); if (TextUtils.isEmpty(directory.getPath())) { //All - refreshData(mAll); + selectedDirectory = null; } else { - for (Directory dir : mAll) { - if (dir.getPath().equals(directory.getPath())) { - List> list = new ArrayList<>(); - list.add(dir); - refreshData(list); - break; - } - } + selectedDirectory = directory.getPath(); } + refreshData(); } }); } @@ -193,12 +190,12 @@ public void onResult(List> directories) { } mAll = directories; - refreshData(directories); + refreshData(); } }); } - private void refreshData(List> directories) { + private void refreshData() { boolean tryToFindTaken = isTakenAutoSelected; // if auto-select taken file is enabled, make sure requirements are met @@ -208,7 +205,10 @@ private void refreshData(List> directories) { } List list = new ArrayList<>(); - for (Directory directory : directories) { + for (Directory directory : mAll) { + if (selectedDirectory != null && !directory.getPath().equals(selectedDirectory)) { + continue; + } list.addAll(directory.getFiles()); // auto-select taken file? @@ -223,6 +223,9 @@ private void refreshData(List> directories) { list.get(index).setSelected(true); } } + + Util.sortFileList(list); + mAdapter.refresh(list); } diff --git a/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java b/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java index d343dc0..0a3d08f 100644 --- a/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java +++ b/filepicker/src/main/java/com/vincent/filepicker/adapter/ImagePickAdapter.java @@ -48,6 +48,7 @@ public class ImagePickAdapter extends BaseAdapter(), needCamera, isNeedImagePager, max); @@ -161,6 +162,7 @@ public void onClick(View v) { public void onClick(View v) { Intent intent = new Intent(mContext, ImageBrowserActivity.class); intent.putExtra(Constant.MAX_NUMBER, mMaxNumber); + intent.putExtra(Constant.DIRECTORY, selectedDirectory); intent.putExtra(IMAGE_BROWSER_INIT_INDEX, isNeedCamera ? holder.getAdapterPosition() - 1 : holder.getAdapterPosition()); intent.putParcelableArrayListExtra(IMAGE_BROWSER_SELECTED_LIST, ((ImagePickActivity) mContext).mSelectedList); @@ -218,6 +220,10 @@ public ImagePickViewHolder(View itemView) { } } + public void setSelectedDirectory(String selectedDirectory) { + this.selectedDirectory = selectedDirectory; + } + public boolean isUpToMax() { return mCurrentNumber >= mMaxNumber; }