Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Performances fixes #64

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ android {
}
}
}
buildToolsVersion '29.0.2'
compileSdkVersion 29
buildToolsVersion '30.0.2'
compileSdkVersion 30
defaultConfig {
applicationId "com.jaiselrahman.filepickersample"
minSdkVersion 14
targetSdkVersion 29
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -35,13 +35,13 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.10.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
implementation 'com.github.bumptech.glide:glide:4.11.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test:runner:1.3.1-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0-alpha02'
implementation project(':filepicker')
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ protected void onCreate(Bundle savedInstanceState) {
fileListAdapter = new FileListAdapter(mediaFiles);
recyclerView.setAdapter(fileListAdapter);

final ActivityResultLauncher<Configurations> pickImage = registerForActivityResult(new PickFile().throughDir(true), new ActivityResultCallback<List<MediaFile>>() {
final ActivityResultLauncher<Configurations> pickImage = registerForActivityResult(
new PickFile().throughDir(true), new ActivityResultCallback<List<MediaFile>>() {
@Override
public void onActivityResult(List<MediaFile> result) {
if (result != null)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:4.1.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
27 changes: 14 additions & 13 deletions filepicker/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 29
buildToolsVersion '29.0.2'
compileSdkVersion 30
buildToolsVersion '30.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 29
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
versionName '1.0'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
vectorDrawables.useSupportLibrary = true
}

Expand All @@ -22,17 +22,18 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

implementation 'androidx.paging:paging-runtime:2.1.2'

implementation 'com.github.bumptech.glide:glide:4.10.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'

implementation "androidx.activity:activity:1.2.0-alpha04"
implementation 'androidx.activity:activity:1.2.0-beta01'
implementation 'androidx.fragment:fragment:1.3.0-beta01'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test:runner:1.3.1-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0-alpha02'
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ private Configurations(Builder builder) {
this.portraitSpanCount = builder.portraitSpanCount;
this.rootPath = builder.rootPath;
this.suffixes = builder.suffixes;
this.selectedMediaFiles = builder.selectedMediaFiles;
if (builder.selectedMediaFiles != null) {
this.selectedMediaFiles = builder.selectedMediaFiles;
} else {
this.selectedMediaFiles = new ArrayList<>();
}
setIgnorePathMatchers(builder.ignorePaths);
this.ignoreNoMedia = builder.ignoreNoMedia;
this.ignoreHiddenFile = builder.ignoreHiddenFile;
Expand Down Expand Up @@ -132,7 +136,7 @@ public boolean isSkipZeroSizeFiles() {
}

public ArrayList<MediaFile> getSelectedMediaFiles() {
return selectedMediaFiles;
return selectedMediaFiles != null ? selectedMediaFiles : new ArrayList<MediaFile>();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ private List<Dir> getDirsQ(int offset) {
selection, selectionArgs,
sortOrder, null);

return DirLoader.getDirs(data, configs);
List<Dir> dirs = DirLoader.getDirs(data, configs);
data.close();
return dirs;
}

private static String[] getDirProjection() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -157,11 +158,23 @@ public void loadRange(@NonNull LoadRangeParams params, @NonNull LoadRangeCallbac
}

private List<MediaFile> getMediaFiles(int offset, int limit) {
Cursor data = ContentResolverCompat.query(contentResolver, uri, projection,
selection, selectionArgs,
sortOrder + " LIMIT " + limit + " OFFSET " + offset, null);
Cursor data;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Bundle bundle = new Bundle();
bundle.putInt(ContentResolver.QUERY_ARG_LIMIT, limit);
bundle.putInt(ContentResolver.QUERY_ARG_OFFSET, offset);
bundle.putString(ContentResolver.QUERY_ARG_SQL_SELECTION, selection);
bundle.putStringArray(ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS, selectionArgs);
data = contentResolver.query(uri, projection, bundle, null);
} else {
data = ContentResolverCompat.query(contentResolver, uri, projection,
selection, selectionArgs,
sortOrder + " LIMIT " + limit + " OFFSET " + offset, null);
}

return MediaFileLoader.asMediaFiles(data, configs);
List<MediaFile> mediaFiles = MediaFileLoader.asMediaFiles(data, configs);
data.close();
return mediaFiles;
}

private static boolean canUseAlbumId(Configurations configs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import com.jaiselrahman.filepicker.config.Configurations;

import java.io.File;
import java.util.HashSet;
import java.util.regex.Matcher;

import static java.io.File.separatorChar;

public class FileUtils {
private static HashSet<String> traversedPaths = new HashSet<>();
public static boolean toIgnoreFolder(String path, Configurations configs) {
String parent = getParent(path);
if (configs.isIgnoreHiddenFile() && getName(parent).startsWith(".")) return true;
Expand All @@ -37,8 +39,18 @@ public static boolean toIgnoreFolder(String path, Configurations configs) {
}
}
if (configs.isIgnoreNoMediaDir()) {
while (!parent.isEmpty() && !new File(parent, MediaStore.MEDIA_IGNORE_FILENAME).exists()) {
while (!parent.isEmpty()) {
if (traversedPaths.contains(parent)) {
parent = "";
break;
}
traversedPaths.add(parent);
boolean exists = new File(parent, MediaStore.MEDIA_IGNORE_FILENAME).exists();
if (exists) {
break;
}
parent = getParent(parent);
break;
}
return !parent.isEmpty();
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Jun 10 13:16:39 IST 2018
#Fri Dec 04 20:02:42 CET 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.5-all.zip