Skip to content

Commit 4d1e86b

Browse files
author
xausky
committed
修复部分闪退问题,保存补丁需求状态。
1 parent 4869c12 commit 4d1e86b

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

app/src/main/java/io/github/xausky/unitymodmanager/MainActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected Integer doInBackground(Object... params) {
134134
int result = ModUtils.RESULT_STATE_OK;
135135
ModFragment modFragment = (ModFragment) BaseFragment.fragment(R.id.nav_mod);
136136
HomeFragment homeFragment = (HomeFragment) BaseFragment.fragment(R.id.nav_home);
137-
if (modFragment.needPatch) {
137+
if (modFragment.isNeedPatch()) {
138138
result = modFragment.patch(homeFragment.apkPath, homeFragment.baseApkPath);
139139
}
140140
if (result == ModUtils.RESULT_STATE_OK) {
@@ -149,7 +149,7 @@ protected void onPostExecute(Integer result) {
149149
dialog.hide();
150150
ModFragment modFragment = (ModFragment) BaseFragment.fragment(R.id.nav_mod);
151151
if (result == ModUtils.RESULT_STATE_OK) {
152-
modFragment.needPatch = false;
152+
modFragment.setNeedPatch(false);
153153
} else if (result == ModUtils.RESULT_STATE_INTERNAL_ERROR) {
154154
Toast.makeText(modFragment.getBase(), "安装模组失败", Toast.LENGTH_LONG).show();
155155
}

app/src/main/java/io/github/xausky/unitymodmanager/fragment/HomeFragment.java

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ public void run() {
210210
final InstallResult result = VirtualCore.get().installPackage(apkPath, InstallStrategy.UPDATE_IF_EXIST);
211211
final String resultString;
212212
if(result.isSuccess){
213+
modFragment.setNeedPatch(true);
213214
HomeFragment.this.packageName = result.packageName;
214215
HomeFragment.this.baseApkPath = apkPath;
215216
HomeFragment.this.apkPath = VirtualCore.get().getInstalledAppInfo(HomeFragment.this.packageName, 0).apkPath;

app/src/main/java/io/github/xausky/unitymodmanager/fragment/ModFragment.java

+18-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.content.Intent;
5+
import android.content.SharedPreferences;
56
import android.graphics.Bitmap;
67
import android.os.Bundle;
78
import android.support.annotation.NonNull;
@@ -37,12 +38,14 @@
3738

3839
public class ModFragment extends BaseFragment implements ModsAdapter.OnDataChangeListener {
3940
private static final int MOD_FILE_PICKER_RESULT = 1;
41+
private static final String NEED_PATCH_PREFERENCES_KEY = "NEED_PATCH_PREFERENCES_KEY";
4042
private View view;
4143
private RecyclerView recyclerView;
4244
private ModsAdapter adapter;
43-
public boolean needPatch;
45+
private boolean needPatch;
4446
private Context context;
4547
private File storeFile;
48+
private SharedPreferences settingsPreferences;
4649

4750
@Override
4851
public BaseFragment setBase(Context base) {
@@ -52,11 +55,22 @@ public BaseFragment setBase(Context base) {
5255
Toast.makeText(base, R.string.store_mkdir_failed, Toast.LENGTH_LONG).show();
5356
}
5457
}
58+
this.settingsPreferences = base.getSharedPreferences(SettingFragment.SETTINGS_PREFERENCE_NAME, Context.MODE_PRIVATE);
59+
needPatch = settingsPreferences.getBoolean(NEED_PATCH_PREFERENCES_KEY, false);
5560
adapter = new ModsAdapter(storeFile, base);
5661
adapter.setListener(this);
5762
return super.setBase(base);
5863
}
5964

65+
public boolean isNeedPatch() {
66+
return needPatch;
67+
}
68+
69+
public void setNeedPatch(boolean needPatch) {
70+
this.needPatch = needPatch;
71+
settingsPreferences.edit().putBoolean(NEED_PATCH_PREFERENCES_KEY, needPatch).apply();
72+
}
73+
6074
public int getItemCount(){
6175
return adapter.getItemCount();
6276
}
@@ -69,11 +83,9 @@ public int getEnableItemCount(){
6983
@Override
7084
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
7185
this.context = inflater.getContext();
72-
if(view == null){
73-
view = inflater.inflate(R.layout.mod_fragment, container, false);
74-
recyclerView = view.findViewById(R.id.mod_list);
75-
adapter.setRecyclerView(recyclerView);
76-
}
86+
view = inflater.inflate(R.layout.mod_fragment, container, false);
87+
recyclerView = view.findViewById(R.id.mod_list);
88+
adapter.setRecyclerView(recyclerView);
7789
adapter.updateSetting();
7890
return view;
7991
}

app/src/main/java/io/github/xausky/unitymodmanager/fragment/SettingFragment.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected Integer doInBackground(Object... params) {
7272
int result = ModUtils.RESULT_STATE_OK;
7373
ModFragment modFragment = (ModFragment) BaseFragment.fragment(R.id.nav_mod);
7474
HomeFragment homeFragment = (HomeFragment) BaseFragment.fragment(R.id.nav_home);
75-
if (modFragment.needPatch) {
75+
if (modFragment.isNeedPatch()) {
7676
result = modFragment.patch(homeFragment.apkPath, homeFragment.baseApkPath);
7777
}
7878
if (result == ModUtils.RESULT_STATE_OK) {
@@ -92,7 +92,7 @@ protected void onPostExecute(Integer result) {
9292
dialog.hide();
9393
ModFragment modFragment = (ModFragment) BaseFragment.fragment(R.id.nav_mod);
9494
if (result == ModUtils.RESULT_STATE_OK) {
95-
modFragment.needPatch = false;
95+
modFragment.setNeedPatch(false);
9696
String exportPath = Environment.getExternalStorageDirectory() + "/out.apk";
9797
Toast.makeText(modFragment.getBase(), "导出整合包成功=>" + exportPath, Toast.LENGTH_LONG).show();
9898
} else if (result == RESULT_STATE_INTERNAL_ERROR) {

app/src/main/java/io/github/xausky/unitymodmanager/utils/ModUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static int Standardization(File input, File output){
7575
return RESULT_STATE_INTERNAL_ERROR;
7676
}
7777
result += r;
78-
} else if(supportImageType.contains(name.substring(name.length() - 4))){
78+
} else if(name.length() - 4 > 0 && supportImageType.contains(name.substring(name.length() - 4))){
7979
try {
8080
FileUtils.copyFile(file, new File(output + "/images/" + System.currentTimeMillis() + "-" + name));
8181
} catch (IOException e) {

0 commit comments

Comments
 (0)