Skip to content

Commit

Permalink
gradle update and some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Praharsh Jain committed Jan 29, 2022
1 parent 3ffb870 commit 1d51618
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 44 deletions.
20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 31
buildToolsVersion '30.0.3'
compileSdkVersion 32
buildToolsVersion '32.0.0'

defaultConfig {
applicationId "com.praharsh.vudit"
minSdkVersion 17
targetSdkVersion 31
targetSdkVersion 32
versionCode 1
versionName "1.0"
}
Expand All @@ -23,12 +23,12 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.6.0-alpha01'
implementation 'com.github.bumptech.glide:glide:4.10.0'
implementation 'com.github.piasy:BigImageViewer:1.6.2'
implementation 'com.github.piasy:ProgressPieIndicator:1.6.2'
implementation 'com.github.piasy:GlideImageLoader:1.6.2'
implementation 'com.github.piasy:GlideImageViewFactory:1.6.2'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0-alpha02'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'com.github.piasy:BigImageViewer:1.8.1'
implementation 'com.github.piasy:ProgressPieIndicator:1.8.1'
implementation 'com.github.piasy:GlideImageLoader:1.8.1'
implementation 'com.github.piasy:GlideImageViewFactory:1.8.1'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
}
58 changes: 37 additions & 21 deletions app/src/main/java/com/praharsh/vudit/FileViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Stack;
Expand Down Expand Up @@ -1498,21 +1499,22 @@ private void listMediaFiles(int type) {
String toolbarTitle = "";
String selectionQuery = null;
String[] selectionArgs = null;
ArrayList<File> fileList = null;
uri = MediaStore.Files.getContentUri("external");
switch (type) {
case 1: //images
uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
toolbarTitle = "Pictures";
fileList = getFileListFromQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selectionQuery, selectionArgs);
break;
case 2: //audio
uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
toolbarTitle = "Music";
fileList = getFileListFromQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, selectionQuery, selectionArgs);
break;
case 3: //video
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
toolbarTitle = "Videos";
fileList = getFileListFromQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, selectionQuery, selectionArgs);
break;
case 4: //documents
uri = MediaStore.Files.getContentUri("external");
toolbarTitle = "Documents";
List<String> extList = new ArrayList<>(Util.doc_ext);
extList.addAll(Util.xl_ext);
Expand All @@ -1521,38 +1523,35 @@ private void listMediaFiles(int type) {
extList.add("pdf");
selectionArgs = Util.getMimeTypeQueryArgs(extList);
selectionQuery = Util.getMimeTypeQuery(selectionArgs);
fileList = getFileListFromQuery(uri, selectionQuery, selectionArgs);
uri = MediaStore.Files.getContentUri("internal");
fileList.addAll(getFileListFromQuery(uri, selectionQuery, selectionArgs));
break;
case 5: //archives
uri = MediaStore.Files.getContentUri("external");
toolbarTitle = "Archives";
selectionArgs = Util.getMimeTypeQueryArgs(Util.archive_ext);
selectionQuery = Util.getMimeTypeQuery(selectionArgs);
fileList = getFileListFromQuery(uri, selectionQuery, selectionArgs);
uri = MediaStore.Files.getContentUri("internal");
fileList.addAll(getFileListFromQuery(uri, selectionQuery, selectionArgs));
break;
case 6: //text files
uri = MediaStore.Files.getContentUri("external");
toolbarTitle = "Text files";
selectionArgs = Util.getMimeTypeQueryArgs(Util.txt_ext);
selectionQuery = Util.getMimeTypeQuery(selectionArgs);
fileList = getFileListFromQuery(uri, selectionQuery, selectionArgs);
uri = MediaStore.Files.getContentUri("internal");
fileList.addAll(getFileListFromQuery(uri, selectionQuery, selectionArgs));
break;
case 7: //apk files
uri = MediaStore.Files.getContentUri("external");
toolbarTitle = "Apps";
selectionArgs = Util.getMimeTypeQueryArgs(Arrays.asList("apk"));
selectionArgs = Util.getMimeTypeQueryArgs(Collections.singletonList("apk"));
selectionQuery = Util.getMimeTypeQuery(selectionArgs);
uri = MediaStore.Files.getContentUri("external");
fileList = getFileListFromQuery(uri, selectionQuery, selectionArgs);
uri = MediaStore.Files.getContentUri("internal");
fileList.addAll(getFileListFromQuery(uri, selectionQuery, selectionArgs));
}
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(uri, null, selectionQuery, selectionArgs, null);
ArrayList<File> fileList = new ArrayList<>();
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String data = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
File f = new File(data);
if (f != null && f.exists()) {
fileList.add(f);
}
}
}
cursor.close();
files = new File[fileList.size()];
files = fileList.toArray(files);
if (files != null) {
Expand All @@ -1569,6 +1568,23 @@ private void listMediaFiles(int type) {
}
}

private ArrayList<File> getFileListFromQuery( Uri uri, String selectionQuery, String[] selectionArgs) {
Cursor cursor = getContentResolver().query(uri, null, selectionQuery, selectionArgs, null);
int colIndex = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
ArrayList<File> fileList = new ArrayList<>();
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String data = cursor.getString(colIndex);
File f = new File(data);
if (f != null && f.exists()) {
fileList.add(f);
}
}
}
cursor.close();
return fileList;
}

private void requestSDCardPermissions(String cardPath) {
if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
startActivityForResult(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), SDCARD_WRITE_PERMISSION_REQUEST_CODE);
Expand Down
16 changes: 7 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

buildscript {
repositories {
maven {
url "http://dl.bintray.com/piasy/maven"
}
jcenter()
mavenLocal()
mavenCentral()
google()
maven { url "https://dl.bintray.com/piasy/maven" }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.android.tools.build:gradle:7.1.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -18,11 +17,10 @@ buildscript {

allprojects {
repositories {
maven {
url "http://dl.bintray.com/piasy/maven"
}
jcenter()
mavenLocal()
mavenCentral()
google()
maven { url "https://dl.bintray.com/piasy/maven" }
}
}

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
android.useAndroidX=true
org.gradle.unsafe.configuration-cache=true
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Oct 14 14:47:07 IST 2020
#Fri Jan 28 22:12:24 IST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
zipStoreBase=GRADLE_USER_HOME

0 comments on commit 1d51618

Please sign in to comment.