Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Commit 1a46308

Browse files
- Support for android 11+
- Fixed many under the hood bugs
1 parent f29e8fb commit 1a46308

20 files changed

Lines changed: 304 additions & 344 deletions

app/build.gradle

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 29
4+
compileSdkVersion 31
55
buildToolsVersion "29.0.3"
66
defaultConfig {
77
applicationId "com.spse.javamodsoptimiser"
88
minSdkVersion 24
9-
targetSdkVersion 29
9+
targetSdkVersion 31
1010
versionCode 3
1111
versionName "2.0"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -23,25 +23,24 @@ android {
2323

2424
maven { url "https://jitpack.io" }
2525
}
26+
27+
compileOptions {
28+
sourceCompatibility JavaVersion.VERSION_1_8
29+
targetCompatibility JavaVersion.VERSION_1_8
30+
}
2631
}
2732

2833
dependencies {
2934
implementation fileTree(dir: 'libs', include: ['*.jar'])
3035
implementation 'androidx.preference:preference:1.1.1'
31-
implementation 'androidx.appcompat:appcompat:1.2.0'
32-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
33-
implementation 'androidx.recyclerview:recyclerview:1.1.0'
34-
implementation 'com.google.android.material:material:1.3.0'
36+
implementation 'androidx.appcompat:appcompat:1.3.1'
37+
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
38+
implementation 'com.google.android.material:material:1.4.0'
3539

36-
implementation 'com.github.codekidX:storage-chooser:2.0.4.4'
3740

3841
implementation project(':pngquant-android')
3942
implementation project(path: ':mobile-ffmpeg')
4043
implementation project(path: ':minify-1.0.0')
41-
implementation 'androidx.navigation:navigation-fragment:2.3.4'
42-
implementation 'androidx.navigation:navigation-ui:2.3.4'
43-
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
44-
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
4544

4645
testImplementation 'junit:junit:4.13'
4746
androidTestImplementation 'androidx.test.ext:junit:1.1.2'

app/src/main/AndroidManifest.xml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,33 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.spse.javamodsoptimiser">
44

5-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
6-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
75
<uses-permission android:name="android.permission.WAKE_LOCK" />
86
<application
9-
android:requestLegacyExternalStorage="true"
10-
android:allowBackup="true"
117
android:icon="@mipmap/ic_launcher"
128
android:label="@string/app_name"
139
android:roundIcon="@mipmap/ic_launcher_round"
1410
android:supportsRtl="true"
1511
android:theme="@style/AppTheme">
16-
<activity android:name=".MainActivity">
12+
<provider
13+
android:name="androidx.core.content.FileProvider"
14+
android:authorities="${applicationId}.provider"
15+
android:exported="false"
16+
android:grantUriPermissions="true">
17+
<meta-data
18+
android:name="android.support.FILE_PROVIDER_PATHS"
19+
android:resource="@xml/provider_paths"/>
20+
</provider>
21+
<activity android:name=".MainActivity"
22+
android:exported="true"
23+
android:screenOrientation="sensorPortrait"
24+
android:configChanges="orientation|screenSize">
1725
<intent-filter>
1826
<action android:name="android.intent.action.MAIN" />
1927

2028
<category android:name="android.intent.category.LAUNCHER" />
2129
</intent-filter>
30+
31+
2232
</activity>
2333
<meta-data
2434
android:name="preloaded_fonts"

app/src/main/java/com/spse/javamodsoptimiser/FileManager.java

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package com.spse.javamodsoptimiser;
22

3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.database.Cursor;
6+
import android.net.Uri;
7+
import android.provider.OpenableColumns;
38
import android.util.Log;
9+
import android.webkit.MimeTypeMap;
410

511
import java.io.File;
612
import java.io.IOException;
713

8-
import static com.spse.javamodsoptimiser.MainActivity.TEMP_PATH;
9-
14+
/**
15+
* Class for everything related to interacting with files
16+
*/
1017
public class FileManager {
11-
//Class related to everything related to files
12-
1318

1419
public static boolean removeFile(String inputPath, String inputFile){
1520
return removeFile(inputPath + inputFile);
@@ -50,17 +55,11 @@ public static boolean fileExists(String absolutePath){
5055
public static boolean createFolder(String absolutePathToFolder){
5156
File file = new File(absolutePathToFolder);
5257
if(!file.exists()){
53-
return file.mkdir();
58+
return file.mkdirs();
5459
}
5560
return true;
5661
}
5762

58-
public static void removeLeftOvers(){
59-
//Remove anything within the TEMP_PATH
60-
61-
walkAndRemove(TEMP_PATH);
62-
}
63-
6463
public static boolean compareFileSize(String fileOne, String fileTwo) throws IOException {
6564
//return true if file1 > file2
6665
File file1 = new File(fileOne);
@@ -75,23 +74,71 @@ public static boolean compareFileSize(String fileOne, String fileTwo) throws IOE
7574
return file1.length() > file2.length();
7675
}
7776

78-
private static void walkAndRemove(String path) {
79-
77+
/**
78+
* Remove everything inside a folder. Works recursively.
79+
* @param path The path to start from.
80+
*/
81+
public static void removeEverything(String path) {
8082
File root = new File(path);
8183
File[] list = root.listFiles();
8284

8385
if (list == null) return;
8486

8587
for (File f : list) {
8688
if (f.isDirectory()) {
87-
walkAndRemove(f.getAbsolutePath());
88-
}else{
89-
removeFile(f.getAbsolutePath());
90-
return;
89+
removeEverything(f.getAbsolutePath());
9190
}
92-
removeFile(f.getAbsolutePath());
91+
f.delete();
9392
}
9493
}
9594

95+
/**
96+
* Tries to get an Uri from the various sources
97+
*/
98+
public static Uri[] getUriData(Intent intent){
99+
Uri[] mUriData = new Uri[]{intent.getData()};
100+
if(mUriData[0] != null) return mUriData;
101+
try {
102+
mUriData = new Uri[intent.getClipData().getItemCount()];
103+
for(int i=0; i < mUriData.length; ++i){
104+
mUriData[i] = intent.getClipData().getItemAt(i).getUri();
105+
}
106+
}catch (Exception ignored){}
107+
return mUriData;
108+
}
109+
110+
/**
111+
* Extract the file name from an Uri
112+
* @param ctx Context
113+
* @param uri The Uri to extract from
114+
* @return The file name
115+
*/
116+
public static String getFileName(Context ctx, Uri uri){
117+
Cursor returnCursor =
118+
ctx.getContentResolver().query(uri, null, null, null, null);
119+
120+
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
121+
returnCursor.moveToFirst();
122+
String fileName = returnCursor.getString(nameIndex);
123+
returnCursor.close();
124+
return fileName;
125+
}
126+
127+
/**
128+
* Extract the file size from an Uri
129+
* @param ctx Context
130+
* @param uri The Uri to extract from
131+
* @return The file name
132+
*/
133+
public static long getFileSize(Context ctx, Uri uri){
134+
Cursor returnCursor =
135+
ctx.getContentResolver().query(uri, null, null, null, null);
136+
137+
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
138+
returnCursor.moveToFirst();
139+
long fileSize = returnCursor.getLong(sizeIndex);
140+
returnCursor.close();
141+
return fileSize;
142+
}
96143

97144
}

0 commit comments

Comments
 (0)