1. use XXPermissions to fix permission issue

This commit is contained in:
ZaneYork 2022-10-16 22:24:26 +08:00
parent b36c14de99
commit 073027a130
13 changed files with 112 additions and 68 deletions

View File

@ -4,6 +4,6 @@
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
</annotationProcessing>
<bytecodeTargetLevel target="1.8" />
<bytecodeTargetLevel target="11" />
</component>
</project>

View File

@ -12,6 +12,6 @@
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-04-05T09:52:51.228626400Z" />
<timeTargetWasSelectedWithDropDown value="2022-04-08T14:55:17.414545500Z" />
</component>
</project>

View File

@ -7,13 +7,13 @@
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="11" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -2,18 +2,18 @@ apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 30
compileSdkVersion 32
defaultConfig {
applicationId "com.zane.smapiinstaller"
minSdkVersion 19
//noinspection ExpiringTargetSdkVersion
targetSdkVersion 30
versionCode 72
versionName "3.7.6.10"
versionCode 73
versionName "3.7.6.11"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
@ -53,6 +53,7 @@ android {
buildFeatures {
viewBinding true
}
namespace 'com.zane.smapiinstaller'
}
greendao {
@ -62,22 +63,23 @@ greendao {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.navigation:navigation-fragment:2.3.1"
implementation "androidx.navigation:navigation-ui:2.3.1"
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.navigation:navigation-fragment-ktx:2.5.2"
implementation "androidx.navigation:navigation-ui-ktx:2.5.2"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.webkit:webkit:1.3.0'
//noinspection GradleDynamicVersion,GradleDependency
implementation 'androidx.webkit:webkit:1.4.+'
implementation "androidx.documentfile:documentfile:1.0.1"
// https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.65.01'
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.67'
implementation 'com.afollestad.material-dialogs:core:3.3.0'
implementation 'com.afollestad.material-dialogs:input:3.3.0'
implementation 'com.afollestad.material-dialogs:lifecycle:3.3.0'
implementation 'com.lmntrx.android.library.livin.missme:missme:0.1.5'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
// https://mvnrepository.com/artifact/com.google.guava/guava
implementation group: 'com.google.guava', name: 'guava', version: '30.1-android'
// https://mvnrepository.com/artifact/org.zeroturnaround/zt-zip
@ -93,6 +95,7 @@ dependencies {
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.12.1'
// https://mvnrepository.com/artifact/org.lz4/lz4-pure-java
implementation group: 'org.lz4', name: 'lz4-pure-java', version: '1.7.0'
implementation 'com.github.getActivity:XXPermissions:16.2'
implementation 'com.github.didikee:AndroidDonate:0.1.0'
implementation 'com.hjq:language:6.0'
@ -101,8 +104,8 @@ dependencies {
api 'org.greenrobot:greendao-generator:3.3.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.android.support:multidex:1.0.3'
def appCenterSdkVersion = '3.0.0'
@ -111,5 +114,5 @@ dependencies {
compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.6'
}

View File

@ -1,15 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto"
package="com.zane.smapiinstaller">
android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<queries>
<package android:name="com.chucklefish.stardewvalley"/>
<package android:name="com.zane.stardewvalley"/>
@ -30,7 +29,6 @@
android:configChanges="orientation|keyboard|screenSize"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme"
android:preserveLegacyExternalStorage="true"
android:requestLegacyExternalStorage="true"
tools:ignore="UnusedAttribute"
android:largeHeap="true">

View File

@ -15,6 +15,9 @@ import android.view.View;
import android.widget.Toast;
import com.hjq.language.MultiLanguages;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.lmntrx.android.library.livin.missme.ProgressDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
@ -43,6 +46,7 @@ import com.zane.smapiinstaller.utils.TranslateUtil;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.util.List;
import java.util.Locale;
import androidx.annotation.NonNull;
@ -73,10 +77,10 @@ public class MainActivity extends AppCompatActivity {
if (!haveInstallPermission) {
DialogUtils.showConfirmDialog(MainActivity.instance, R.string.confirm, R.string.request_unknown_source_permission, ((dialog, dialogAction) -> {
if (dialogAction == DialogAction.POSITIVE) {
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
intent.setData(Uri.parse("package:" + this.getPackageName()));
ActivityResultHandler.registerListener(ActivityResultHandler.REQUEST_CODE_APP_INSTALL, (resultCode, data) -> this.requestPermissions());
MainActivity.instance.startActivityForResult(intent, ActivityResultHandler.REQUEST_CODE_APP_INSTALL);
XXPermissions.with(this).permission(Permission.REQUEST_INSTALL_PACKAGES)
.request(getPermissionCallback());
} else {
this.finish();
}
}));
return;
@ -87,14 +91,8 @@ public class MainActivity extends AppCompatActivity {
if (!Environment.isExternalStorageManager()) {
DialogUtils.showConfirmDialog(MainActivity.instance, R.string.confirm, R.string.request_all_files_access_permission, ((dialog, dialogAction) -> {
if (dialogAction == DialogAction.POSITIVE) {
ActivityResultHandler.registerListener(ActivityResultHandler.REQUEST_CODE_ALL_FILES_ACCESS_PERMISSION, (resultCode, data) -> {
if (!Environment.isExternalStorageManager()) {
this.finish();
} else {
requestPermissions();
}
});
CommonLogic.openPermissionSetting(this);
XXPermissions.with(this).permission(Permission.MANAGE_EXTERNAL_STORAGE)
.request(getPermissionCallback());
} else {
this.finish();
}
@ -102,13 +100,44 @@ public class MainActivity extends AppCompatActivity {
return;
}
}
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
} else {
initView();
}
XXPermissions.with(this)
.permission(Permission.MANAGE_EXTERNAL_STORAGE)
.permission(Permission.REQUEST_INSTALL_PACKAGES)
.request(new OnPermissionCallback() {
@Override
public void onGranted(List<String> permissions, boolean all) {
if (!all) {
requestPermissions();
return;
}
initView();
}
@Override
public void onDenied(List<String> permissions, boolean never) {
if (never) {
XXPermissions.startPermissionActivity(instance, permissions);
}
requestPermissions();
}
});
}
@NonNull
private OnPermissionCallback getPermissionCallback() {
return new OnPermissionCallback() {
@Override
public void onGranted(List<String> permissions, boolean all) {
requestPermissions();
}
@Override
public void onDenied(List<String> permissions, boolean never) {
if (never) {
XXPermissions.startPermissionActivity(instance, permissions);
}
requestPermissions();
}
};
}
@Override
@ -118,6 +147,7 @@ public class MainActivity extends AppCompatActivity {
} else {
this.finish();
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@Override
@ -284,7 +314,7 @@ public class MainActivity extends AppCompatActivity {
appConfig.setValue(String.valueOf(item.isChecked()));
ConfigUtils.saveConfig((MainApplication) getApplication(), appConfig);
startActivity(new Intent(this, MainActivity.class));
overridePendingTransition(R.anim.fragment_fade_enter, R.anim.fragment_fade_exit);
// overridePendingTransition(R.anim.fragment_fade_enter, R.anim.fragment_fade_exit);
finish();
} else {
return super.onOptionsItemSelected(item);
@ -370,7 +400,7 @@ public class MainActivity extends AppCompatActivity {
if (restart) {
// 我们可以充分运用 Activity 跳转动画在跳转的时候设置一个渐变的效果
startActivity(new Intent(this, MainActivity.class));
overridePendingTransition(R.anim.fragment_fade_enter, R.anim.fragment_fade_exit);
// overridePendingTransition(R.anim.fragment_fade_enter, R.anim.fragment_fade_exit);
finish();
}
});

View File

@ -329,7 +329,7 @@ public class DialogUtils {
public static void showSingleChoiceDialog(View view, int title, int items, int index, BiConsumer<MaterialDialog, Integer> callback) {
CommonLogic.runOnUiThread(CommonLogic.getActivityFromView(view), (activity) -> {
MaterialDialog materialDialog = new MaterialDialog(activity, MaterialDialog.getDEFAULT_BEHAVIOR()).title(title, null);
materialDialog = DialogSingleChoiceExtKt.listItemsSingleChoice(materialDialog, items, null, null, index, false, (dialog, position, text) -> {
materialDialog = DialogSingleChoiceExtKt.listItemsSingleChoice(materialDialog, items, null, null, index, false, -1, -1, (dialog, position, text) -> {
callback.accept(dialog, position);
return null;
});

View File

@ -1,16 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://jitpack.io' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.1"
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.5.2"
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0'
// NOTE: Do not place your application dependencies here; they belong
@ -18,15 +17,6 @@ buildscript {
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

View File

@ -6,12 +6,17 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
android.enableJetifier=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true

Binary file not shown.

View File

@ -1,6 +1,6 @@
#Mon Feb 01 14:39:47 CST 2021
#Sun Oct 09 22:26:32 CST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
zipStoreBase=GRADLE_USER_HOME

View File

@ -1,2 +1,20 @@
pluginManagement {
repositories {
gradlePluginPortal()
google()
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://jitpack.io' }
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://jitpack.io' }
mavenCentral()
}
}
rootProject.name='SMAPI Installer'
include ':app'