Commit bdc86ae0 authored by fallenstardust's avatar fallenstardust

arrange code

parent 953529a3
package cn.garymb.ygomobile; package cn.garymb.ygomobile;
import android.app.Activity; import android.app.Activity;
import android.content.ContentUris;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import androidx.documentfile.provider.DocumentFile;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.util.Locale; import java.util.Locale;
...@@ -41,7 +47,7 @@ public class GameUriManager { ...@@ -41,7 +47,7 @@ public class GameUriManager {
} }
public boolean doIntent(Intent intent) { public boolean doIntent(Intent intent) {
Log.i("ygo", "doIntent"); Log.i(Constants.TAG, "doIntent");
if (ACTION_OPEN_DECK.equals(intent.getAction())) { if (ACTION_OPEN_DECK.equals(intent.getAction())) {
if (intent.getData() != null) { if (intent.getData() != null) {
doUri(intent.getData()); doUri(intent.getData());
...@@ -79,7 +85,7 @@ public class GameUriManager { ...@@ -79,7 +85,7 @@ public class GameUriManager {
private String getPathName(String path, boolean withOutEx) { private String getPathName(String path, boolean withOutEx) {
Log.d("ygo", "path=" + path); Log.d(Constants.TAG, "path=" + path);
if (path != null) { if (path != null) {
int index = path.lastIndexOf("/"); int index = path.lastIndexOf("/");
if (index > 0) { if (index > 0) {
...@@ -98,7 +104,7 @@ public class GameUriManager { ...@@ -98,7 +104,7 @@ public class GameUriManager {
} }
private File getDeckFile(File dir, String name) { private File getDeckFile(File dir, String name) {
File file = new File(dir, name + ".ydk"); File file = new File(dir, name);
if (file.exists()) { if (file.exists()) {
for (int i = 2; i < 10; i++) { for (int i = 2; i < 10; i++) {
file = new File(dir, name + "(" + i + ").ydk"); file = new File(dir, name + "(" + i + ").ydk");
...@@ -140,11 +146,11 @@ public class GameUriManager { ...@@ -140,11 +146,11 @@ public class GameUriManager {
} }
try { try {
if (!remoteFile.canRead()) { if (!remoteFile.canRead()) {
Log.w("ygo", "don't read file " + remoteFile.getAbsolutePath()); Log.w(Constants.TAG, "don't read file " + remoteFile.getAbsolutePath());
return null; return null;
} }
} catch (Throwable e) { } catch (Throwable e) {
Log.e("ygo", "don't read file " + remoteFile.getAbsolutePath(), e); Log.e(Constants.TAG, "don't read file " + remoteFile.getAbsolutePath(), e);
return null; return null;
} }
} }
...@@ -152,7 +158,7 @@ public class GameUriManager { ...@@ -152,7 +158,7 @@ public class GameUriManager {
File local; File local;
if (name.toLowerCase(Locale.US).endsWith(".ydk")) { if (name.toLowerCase(Locale.US).endsWith(".ydk")) {
File dir = Constants.COPY_YDK_FILE ? new File(AppsSettings.get().getDeckDir()) : new File(getActivity().getApplicationInfo().dataDir, "cache"); File dir = Constants.COPY_YDK_FILE ? new File(AppsSettings.get().getDeckDir()) : new File(getActivity().getApplicationInfo().dataDir, "cache");
local = getDeckFile(dir, name); local = getDeckFile(dir, getPathName(path, true));
} else if (name.toLowerCase(Locale.US).endsWith(".ypk")) { } else if (name.toLowerCase(Locale.US).endsWith(".ypk")) {
local = new File(AppsSettings.get().getExpansionsPath(), name); local = new File(AppsSettings.get().getExpansionsPath(), name);
} else if (name.toLowerCase(Locale.US).endsWith(".yrp")) { } else if (name.toLowerCase(Locale.US).endsWith(".yrp")) {
...@@ -163,11 +169,11 @@ public class GameUriManager { ...@@ -163,11 +169,11 @@ public class GameUriManager {
local = new File(AppsSettings.get().getResourcePath() + "/temp", name); local = new File(AppsSettings.get().getResourcePath() + "/temp", name);
} }
if (local.exists()) { if (local.exists()) {
Log.w("ygo", "Overwrite file " + local.getAbsolutePath()); Log.w(Constants.TAG, "Overwrite file "+local.getAbsolutePath());
} }
if (remoteFile != null && TextUtils.equals(remoteFile.getAbsolutePath(), local.getAbsolutePath())) { if (remoteFile != null && TextUtils.equals(remoteFile.getAbsolutePath(), local.getAbsolutePath())) {
//is same path //is same path
Log.i("ygo", "is same file " + remoteFile.getAbsolutePath() + "==" + local.getAbsolutePath()); Log.i(Constants.TAG, "is same file " + remoteFile.getAbsolutePath() + "==" + local.getAbsolutePath());
return local; return local;
} }
//copy //copy
...@@ -186,7 +192,7 @@ public class GameUriManager { ...@@ -186,7 +192,7 @@ public class GameUriManager {
FileUtils.copyFile(input, local); FileUtils.copyFile(input, local);
} }
} catch (Throwable e) { } catch (Throwable e) {
Log.w("ygo", "copy file " + path + "->" + local.getAbsolutePath(), e); Log.w(Constants.TAG, "copy file " + path + "->" + local.getAbsolutePath(), e);
return null; return null;
} finally { } finally {
IOUtils.close(input); IOUtils.close(input);
...@@ -207,11 +213,9 @@ public class GameUriManager { ...@@ -207,11 +213,9 @@ public class GameUriManager {
boolean isYpk = file.getName().toLowerCase(Locale.US).endsWith(".ypk"); boolean isYpk = file.getName().toLowerCase(Locale.US).endsWith(".ypk");
boolean isYrp = file.getName().toLowerCase(Locale.US).endsWith(".yrp"); boolean isYrp = file.getName().toLowerCase(Locale.US).endsWith(".yrp");
boolean isLua = file.getName().toLowerCase(Locale.US).endsWith(".lua"); boolean isLua = file.getName().toLowerCase(Locale.US).endsWith(".lua");
Log.i("ygo", "open file:" + uri + "->" + file.getAbsolutePath()); Log.i(Constants.TAG, "open file:" + uri + "->" + file.getAbsolutePath());
if (isYdk) { if (isYdk) {
Intent intent = new Intent(getActivity(), DeckManagerActivity.getDeckManager()); DeckManagerActivity.start(activity, file.getAbsolutePath());
intent.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath());
activity.startActivity(intent);
} else if (isYpk) { } else if (isYpk) {
if (!AppsSettings.get().isReadExpansions()) { if (!AppsSettings.get().isReadExpansions()) {
activity.startActivity(startSeting); activity.startActivity(startSeting);
...@@ -225,14 +229,14 @@ public class GameUriManager { ...@@ -225,14 +229,14 @@ public class GameUriManager {
YGOStarter.startGame(getActivity(), null, "-r", file.getName()); YGOStarter.startGame(getActivity(), null, "-r", file.getName());
Toast.makeText(activity, activity.getString(R.string.file_installed), Toast.LENGTH_LONG).show(); Toast.makeText(activity, activity.getString(R.string.file_installed), Toast.LENGTH_LONG).show();
} else { } else {
Log.w("ygo", "game is running"); Log.w(Constants.TAG, "game is running");
} }
} else if (isLua) { } else if (isLua) {
if (!YGOStarter.isGameRunning(getActivity())) { if (!YGOStarter.isGameRunning(getActivity())) {
YGOStarter.startGame(getActivity(), null, "-s", file.getName()); YGOStarter.startGame(getActivity(), null, "-s", file.getName());
Toast.makeText(activity, "load single lua file", Toast.LENGTH_LONG).show(); Toast.makeText(activity, "load single lua file", Toast.LENGTH_LONG).show();
} else { } else {
Log.w("ygo", "game is running"); Log.w(Constants.TAG, "game is running");
} }
} }
} else { } else {
...@@ -247,9 +251,7 @@ public class GameUriManager { ...@@ -247,9 +251,7 @@ public class GameUriManager {
} else { } else {
Deck deckInfo = new Deck(uri); Deck deckInfo = new Deck(uri);
File file = deckInfo.saveTemp(AppsSettings.get().getDeckDir()); File file = deckInfo.saveTemp(AppsSettings.get().getDeckDir());
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager()); DeckManagerActivity.start(activity, file.getAbsolutePath());
startdeck.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath());
activity.startActivity(startdeck);
} }
} }
// else if (PATH_ROOM.equals(path)) { // else if (PATH_ROOM.equals(path)) {
...@@ -277,9 +279,7 @@ public class GameUriManager { ...@@ -277,9 +279,7 @@ public class GameUriManager {
} }
} }
if (deck != null && deck.exists()) { if (deck != null && deck.exists()) {
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager()); DeckManagerActivity.start(activity, deck.getAbsolutePath());
startdeck.putExtra(Intent.EXTRA_TEXT, deck.getAbsolutePath());
activity.startActivity(startdeck);
} else { } else {
Log.w("kk", "no find " + name); Log.w("kk", "no find " + name);
activity.finish(); activity.finish();
......
...@@ -244,7 +244,7 @@ public class FileActivity extends BaseActivity implements AdapterView.OnItemClic ...@@ -244,7 +244,7 @@ public class FileActivity extends BaseActivity implements AdapterView.OnItemClic
} else { } else {
mFileAdapter.setPath(mFileOpenInfo.getDefPath()); mFileAdapter.setPath(mFileOpenInfo.getDefPath());
} }
mFileAdapter.setFilefilter(mFileOpenInfo.getFileFilter()); mFileAdapter.setFileFilter(mFileOpenInfo.getFileFilter());
mFileAdapter.setOnlyFolder(mFileOpenInfo.getType() == FileOpenType.SelectFolder); mFileAdapter.setOnlyFolder(mFileOpenInfo.getType() == FileOpenType.SelectFolder);
mFileAdapter.loadFiles(); mFileAdapter.loadFiles();
} }
......
...@@ -42,17 +42,17 @@ class FileAdapter extends BaseAdapterPlus<File> { ...@@ -42,17 +42,17 @@ class FileAdapter extends BaseAdapterPlus<File> {
public FileAdapter(Context context) { public FileAdapter(Context context) {
super(context); super(context);
rootPath = getRootPath(); try {
rootPath = Environment.getExternalStorageDirectory().getAbsolutePath();
} catch (Exception e) {
rootPath = "/";
}
} }
public void setOnPathChangedListener(OnPathChangedListener onPathChangedListener) { public void setOnPathChangedListener(OnPathChangedListener onPathChangedListener) {
mOnPathChangedListener = onPathChangedListener; mOnPathChangedListener = onPathChangedListener;
} }
private String getRootPath() {
return "/";
}
public File getCurPath() { public File getCurPath() {
return mCurPath; return mCurPath;
} }
...@@ -101,7 +101,7 @@ class FileAdapter extends BaseAdapterPlus<File> { ...@@ -101,7 +101,7 @@ class FileAdapter extends BaseAdapterPlus<File> {
mShowHide = showHide; mShowHide = showHide;
} }
public void setFilefilter(String filefilter) { public void setFileFilter(String filefilter) {
mFilefilter = filefilter; mFilefilter = filefilter;
} }
......
...@@ -82,9 +82,9 @@ public class StringManager implements Closeable { ...@@ -82,9 +82,9 @@ public class StringManager implements Closeable {
InputStreamReader in = null; InputStreamReader in = null;
try { try {
in = new InputStreamReader(inputStream, "utf-8"); in = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(in); BufferedReader reader = new BufferedReader(in);
String line = null; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
if (line.startsWith("#") || (!line.startsWith(PRE_SYSTEM) && !line.startsWith(PRE_SETNAME))) { if (line.startsWith("#") || (!line.startsWith(PRE_SYSTEM) && !line.startsWith(PRE_SETNAME))) {
continue; continue;
...@@ -133,7 +133,7 @@ public class StringManager implements Closeable { ...@@ -133,7 +133,7 @@ public class StringManager implements Closeable {
inputStream = new FileInputStream(file); inputStream = new FileInputStream(file);
in = new InputStreamReader(inputStream, StandardCharsets.UTF_8); in = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(in); BufferedReader reader = new BufferedReader(in);
String line = null; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
if (line.startsWith("#") || (!line.startsWith(PRE_SYSTEM) && !line.startsWith(PRE_SETNAME))) { if (line.startsWith("#") || (!line.startsWith(PRE_SYSTEM) && !line.startsWith(PRE_SETNAME))) {
continue; continue;
......
...@@ -4,6 +4,8 @@ package ocgcore.data; ...@@ -4,6 +4,8 @@ package ocgcore.data;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import androidx.annotation.NonNull;
import ocgcore.enums.CardType; import ocgcore.enums.CardType;
public class Card extends CardData implements Parcelable { public class Card extends CardData implements Parcelable {
...@@ -137,6 +139,7 @@ public class Card extends CardData implements Parcelable { ...@@ -137,6 +139,7 @@ public class Card extends CardData implements Parcelable {
return c.Code == this.Code || c.Alias == this.Code || c.Code == this.Alias; return c.Code == this.Code || c.Alias == this.Code || c.Code == this.Alias;
} }
@NonNull
@Override @Override
public String toString() { public String toString() {
return "Card{" + return "Card{" +
......
...@@ -3,10 +3,9 @@ package ocgcore.data; ...@@ -3,10 +3,9 @@ package ocgcore.data;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import ocgcore.enums.CardAttribute; import androidx.annotation.NonNull;
import ocgcore.enums.CardOt;
public class CardData implements Parcelable{ public class CardData implements Parcelable {
public CardData() { public CardData() {
} }
...@@ -14,6 +13,7 @@ public class CardData implements Parcelable{ ...@@ -14,6 +13,7 @@ public class CardData implements Parcelable{
public CardData(int code) { public CardData(int code) {
Code = code; Code = code;
} }
public int Code; public int Code;
public int Ot; public int Ot;
public int Alias; public int Alias;
...@@ -28,6 +28,7 @@ public class CardData implements Parcelable{ ...@@ -28,6 +28,7 @@ public class CardData implements Parcelable{
public int RightScale; public int RightScale;
public long Category; public long Category;
@NonNull
@Override @Override
public String toString() { public String toString() {
return "CardData{" + return "CardData{" +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment