Code clean up

This commit is contained in:
ZaneYork 2020-03-05 00:06:29 +08:00
parent cdae2ebde1
commit ef0639797e
12 changed files with 31 additions and 57 deletions

View File

@ -36,7 +36,7 @@ public class MainActivity extends AppCompatActivity {
@BindView(R.id.nav_view) @BindView(R.id.nav_view)
NavigationView navigationView; NavigationView navigationView;
public void requestPermissions() private void requestPermissions()
{ {
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {

View File

@ -1,8 +1,8 @@
package com.zane.smapiinstaller.constant; package com.zane.smapiinstaller.constant;
public class Constants { public class Constants {
public static String MOD_PATH = "StardewValley/Mods"; public static final String MOD_PATH = "StardewValley/Mods";
public static String LOG_PATH = "StardewValley/ErrorLogs/SMAPI-latest.txt"; public static final String LOG_PATH = "StardewValley/ErrorLogs/SMAPI-latest.txt";
public static String TARGET_PACKAGE_NAME = "com.zane.stardewvalley"; public static final String TARGET_PACKAGE_NAME = "com.zane.stardewvalley";
} }

View File

@ -44,9 +44,9 @@ public class ApkPatcher {
private static final String PASSWORD = "android"; private static final String PASSWORD = "android";
private Context context; private final Context context;
private static String TAG = "PATCHER"; private static final String TAG = "PATCHER";
public ApkPatcher(Context context) { public ApkPatcher(Context context) {
this.context = context; this.context = context;

View File

@ -10,11 +10,9 @@ import android.util.Log;
import android.view.View; import android.view.View;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import com.google.common.io.CharStreams; import com.google.common.io.CharStreams;
import com.google.common.io.Files;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.zane.smapiinstaller.R; import com.zane.smapiinstaller.R;
@ -24,7 +22,6 @@ import org.zeroturnaround.zip.ZipUtil;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -109,26 +106,20 @@ public class CommonLogic {
public static void showAlertDialog(View view, int title, String message) { public static void showAlertDialog(View view, int title, String message) {
Activity activity = getActivityFromView(view); Activity activity = getActivityFromView(view);
if(activity != null && !activity.isFinishing()) { if(activity != null && !activity.isFinishing()) {
activity.runOnUiThread(()->{ activity.runOnUiThread(()-> new MaterialDialog.Builder(activity).title(title).content(message).positiveText(R.string.ok).show());
new MaterialDialog.Builder(activity).title(title).content(message).positiveText(R.string.ok).show();
});
} }
} }
public static void showAlertDialog(View view, int title, int message) { public static void showAlertDialog(View view, int title, int message) {
Activity activity = getActivityFromView(view); Activity activity = getActivityFromView(view);
if(activity != null && !activity.isFinishing()) { if(activity != null && !activity.isFinishing()) {
activity.runOnUiThread(()->{ activity.runOnUiThread(()-> new MaterialDialog.Builder(activity).title(title).content(message).positiveText(R.string.ok).show());
new MaterialDialog.Builder(activity).title(title).content(message).positiveText(R.string.ok).show();
});
} }
} }
public static void showConfirmDialog(View view, int title, int message, MaterialDialog.SingleButtonCallback callback) { public static void showConfirmDialog(View view, int title, int message, MaterialDialog.SingleButtonCallback callback) {
Activity activity = getActivityFromView(view); Activity activity = getActivityFromView(view);
if(activity != null && !activity.isFinishing()) { if(activity != null && !activity.isFinishing()) {
activity.runOnUiThread(()->{ activity.runOnUiThread(()-> new MaterialDialog.Builder(activity).title(title).content(message).positiveText(R.string.confirm).negativeText(R.string.cancel).onAny(callback).show());
new MaterialDialog.Builder(activity).title(title).content(message).positiveText(R.string.confirm).negativeText(R.string.cancel).onAny(callback).show();
});
} }
} }

View File

@ -11,7 +11,7 @@ import com.zane.smapiinstaller.constant.Constants;
public class GameLauncher { public class GameLauncher {
private View root; private final View root;
public GameLauncher(View root) { public GameLauncher(View root) {
this.root = root; this.root = root;

View File

@ -1,13 +1,12 @@
package com.zane.smapiinstaller.logic; package com.zane.smapiinstaller.logic;
import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import pxb.android.axml.NodeVisitor; import pxb.android.axml.NodeVisitor;
public class ManifestTagVisitor extends NodeVisitor { class ManifestTagVisitor extends NodeVisitor {
private Predicate<AttrArgs> attrProcessLogic; private final Predicate<AttrArgs> attrProcessLogic;
public ManifestTagVisitor(NodeVisitor nv, Predicate<AttrArgs> attrProcessLogic) { public ManifestTagVisitor(NodeVisitor nv, Predicate<AttrArgs> attrProcessLogic) {
super(nv); super(nv);
@ -33,7 +32,7 @@ public class ManifestTagVisitor extends NodeVisitor {
int type; int type;
Object obj; Object obj;
public AttrArgs(String ns, String name, int resourceId, int type, Object obj) { AttrArgs(String ns, String name, int resourceId, int type, Object obj) {
this.ns = ns; this.ns = ns;
this.name = name; this.name = name;
this.resourceId = resourceId; this.resourceId = resourceId;

View File

@ -26,9 +26,9 @@ import java.util.concurrent.ConcurrentLinkedQueue;
public class ModAssetsManager { public class ModAssetsManager {
private View root; private final View root;
private static String TAG = "MANAGER"; private static final String TAG = "MANAGER";
public ModAssetsManager(View root) { public ModAssetsManager(View root) {
this.root = root; this.root = root;

View File

@ -4,11 +4,9 @@ import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -16,10 +14,6 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import com.zane.smapiinstaller.R; import com.zane.smapiinstaller.R;
import com.zane.smapiinstaller.entity.ModManifestEntry;
import com.zane.smapiinstaller.logic.ModAssetsManager;
import java.util.List;
public class ConfigFragment extends Fragment { public class ConfigFragment extends Fragment {

View File

@ -1,20 +1,17 @@
package com.zane.smapiinstaller.ui.config; package com.zane.smapiinstaller.ui.config;
import android.content.Context;
import android.view.View; import android.view.View;
import com.zane.smapiinstaller.entity.ModManifestEntry; import com.zane.smapiinstaller.entity.ModManifestEntry;
import com.zane.smapiinstaller.logic.ModAssetsManager; import com.zane.smapiinstaller.logic.ModAssetsManager;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
public class ConfigViewModel extends ViewModel { class ConfigViewModel extends ViewModel {
private MutableLiveData<List<ModManifestEntry>> modList; private MutableLiveData<List<ModManifestEntry>> modList;

View File

@ -1,13 +1,12 @@
package com.zane.smapiinstaller.ui.config; package com.zane.smapiinstaller.ui.config;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import com.afollestad.materialdialogs.DialogAction;
import com.zane.smapiinstaller.R; import com.zane.smapiinstaller.R;
import com.zane.smapiinstaller.entity.ModManifestEntry; import com.zane.smapiinstaller.entity.ModManifestEntry;
import com.zane.smapiinstaller.logic.CommonLogic; import com.zane.smapiinstaller.logic.CommonLogic;
@ -51,7 +50,7 @@ public class ModManifestAdapter extends RecyclerView.Adapter<ModManifestAdapter.
static class ViewHolder extends RecyclerView.ViewHolder{ static class ViewHolder extends RecyclerView.ViewHolder{
private String modPath; private String modPath;
public void setModPath(String modPath) { void setModPath(String modPath) {
this.modPath = modPath; this.modPath = modPath;
File file = new File(modPath, "config.json"); File file = new File(modPath, "config.json");
if(!file.exists()) { if(!file.exists()) {
@ -73,13 +72,11 @@ public class ModManifestAdapter extends RecyclerView.Adapter<ModManifestAdapter.
} }
@OnClick(R.id.button_remove_mod) void removeMod() { @OnClick(R.id.button_remove_mod) void removeMod() {
CommonLogic.showConfirmDialog(itemView, R.string.confirm, R.string.confirm_delete_mod, (dialog, which)->{ CommonLogic.showConfirmDialog(itemView, R.string.confirm, R.string.confirm_delete_mod, (dialog, which)->{
switch (which){ if (which == DialogAction.POSITIVE) {
case POSITIVE: File file = new File(modPath);
File file = new File(modPath); if (file.exists()) {
if(file.exists()) { file.delete();
file.delete(); }
}
break;
} }
}); });
} }

View File

@ -5,20 +5,18 @@ import android.os.Environment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.navigation.NavController; import androidx.navigation.NavController;
import androidx.navigation.Navigation; import androidx.navigation.Navigation;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import com.afollestad.materialdialogs.DialogAction;
import com.zane.smapiinstaller.R; import com.zane.smapiinstaller.R;
import com.zane.smapiinstaller.constant.Constants; import com.zane.smapiinstaller.constant.Constants;
import com.zane.smapiinstaller.logic.CommonLogic; import com.zane.smapiinstaller.logic.CommonLogic;
import com.zane.smapiinstaller.ui.config.ConfigFragmentDirections;
import java.io.File; import java.io.File;
@ -38,12 +36,10 @@ public class HelpFragment extends Fragment {
} }
@OnClick(R.id.button_release) void release() { @OnClick(R.id.button_release) void release() {
CommonLogic.showConfirmDialog(this.getView(), R.string.confirm, R.string.test_message, (dialog, which)-> { CommonLogic.showConfirmDialog(this.getView(), R.string.confirm, R.string.test_message, (dialog, which)-> {
switch (which) { if (which == DialogAction.POSITIVE) {
case POSITIVE: if (this.getString(R.string.test_message).contains("860453392")) {
if(this.getString(R.string.test_message).contains("860453392")) { CommonLogic.openUrl(this.getContext(), "mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D" + "AAflCLHiWw1haM1obu_f-CpGsETxXc6b");
CommonLogic.openUrl(this.getContext(), "mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D" + "AAflCLHiWw1haM1obu_f-CpGsETxXc6b"); }
}
break;
} }
}); });
} }

View File

@ -4,7 +4,7 @@ import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
public class HelpViewModel extends ViewModel { class HelpViewModel extends ViewModel {
private MutableLiveData<String> mText; private MutableLiveData<String> mText;