Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fallenstardust
YGOMobile
Commits
6f75eaf1
Commit
6f75eaf1
authored
May 24, 2022
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
getDeckFirstCode
parent
44ce1006
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
123 additions
and
11 deletions
+123
-11
mobile/src/main/java/cn/garymb/ygomobile/bean/events/DeckFile.java
...c/main/java/cn/garymb/ygomobile/bean/events/DeckFile.java
+23
-0
mobile/src/main/java/cn/garymb/ygomobile/utils/DeckUtil.java
mobile/src/main/java/cn/garymb/ygomobile/utils/DeckUtil.java
+100
-11
No files found.
mobile/src/main/java/cn/garymb/ygomobile/bean/events/DeckFile.java
View file @
6f75eaf1
...
...
@@ -3,11 +3,15 @@ package cn.garymb.ygomobile.bean.events;
import
java.io.File
;
import
cn.garymb.ygomobile.bean.TextSelect
;
import
cn.garymb.ygomobile.utils.DeckUtil
;
public
class
DeckFile
extends
TextSelect
{
private
final
File
path
;
private
final
String
fullName
;
//
private
String
typeName
;
private
int
firstCode
;
public
DeckFile
(
String
path
)
{
this
(
new
File
(
path
));
...
...
@@ -21,10 +25,29 @@ public class DeckFile extends TextSelect {
if
(
index
>
0
)
{
name
=
name
.
substring
(
0
,
index
);
}
typeName
=
DeckUtil
.
getDeckTypeName
(
path
.
getAbsolutePath
());
firstCode
=
DeckUtil
.
getFirstCardCode
(
path
.
getAbsolutePath
());
super
.
setName
(
name
);
setObject
(
this
);
}
public
int
getFirstCode
()
{
return
firstCode
;
}
public
void
setFirstCode
(
int
firstCode
)
{
this
.
firstCode
=
firstCode
;
}
public
String
getTypeName
()
{
return
typeName
;
}
public
void
setTypeName
(
String
typeName
)
{
this
.
typeName
=
typeName
;
}
public
String
getFileName
()
{
return
fullName
;
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/DeckUtil.java
View file @
6f75eaf1
package
cn.garymb.ygomobile.utils
;
import
android.content.Context
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
...
...
@@ -18,9 +23,36 @@ import cn.garymb.ygomobile.Constants;
import
cn.garymb.ygomobile.bean.DeckType
;
import
cn.garymb.ygomobile.bean.events.DeckFile
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckItemType
;
public
class
DeckUtil
{
private
final
static
Comparator
<
DeckFile
>
nameCom
=
new
Comparator
<
DeckFile
>()
{
@Override
public
int
compare
(
DeckFile
ydk1
,
DeckFile
ydk2
)
{
if
(!
ydk1
.
getTypeName
().
equals
(
YGOUtil
.
s
(
R
.
string
.
category_Uncategorized
))
&&
ydk2
.
getTypeName
().
equals
(
YGOUtil
.
s
(
R
.
string
.
category_Uncategorized
)))
return
1
;
else
if
(
ydk1
.
getTypeName
().
equals
(
YGOUtil
.
s
(
R
.
string
.
category_Uncategorized
))
&&
!
ydk2
.
getTypeName
().
equals
(
YGOUtil
.
s
(
R
.
string
.
category_Uncategorized
)))
return
-
1
;
int
id
=
ydk1
.
getTypeName
().
compareTo
(
ydk2
.
getTypeName
());
if
(
id
==
0
)
return
ydk1
.
getName
().
compareTo
(
ydk2
.
getName
());
else
return
id
;
}
};
private
final
static
Comparator
<
DeckFile
>
dateCom
=
new
Comparator
<
DeckFile
>()
{
@Override
public
int
compare
(
DeckFile
ydk1
,
DeckFile
ydk2
)
{
return
ydk2
.
getDate
().
compareTo
(
ydk1
.
getDate
());
}
};
public
static
List
<
DeckType
>
getDeckTypeList
(
Context
context
)
{
List
<
DeckType
>
deckTypeList
=
new
ArrayList
<>();
deckTypeList
.
add
(
new
DeckType
(
YGOUtil
.
s
(
R
.
string
.
category_pack
),
AppsSettings
.
get
().
getPackDeckDir
()));
...
...
@@ -56,6 +88,39 @@ public class DeckUtil {
return
deckList
;
}
public
static
List
<
DeckFile
>
getDeckAllList
()
{
return
getDeckAllList
(
AppsSettings
.
get
().
getDeckDir
());
}
public
static
List
<
DeckFile
>
getDeckAllList
(
String
path
)
{
return
getDeckAllList
(
path
,
false
);
}
public
static
List
<
DeckFile
>
getDeckAllList
(
String
path
,
boolean
isDir
)
{
List
<
DeckFile
>
deckList
=
new
ArrayList
<>();
File
[]
files
=
new
File
(
path
).
listFiles
();
if
(
files
!=
null
)
{
for
(
File
file
:
files
)
{
if
(
file
.
isDirectory
())
{
deckList
.
addAll
(
getDeckAllList
(
file
.
getAbsolutePath
(),
true
));
}
if
(
file
.
isFile
()
&&
file
.
getName
().
endsWith
(
".ydk"
))
{
deckList
.
add
(
new
DeckFile
(
file
));
}
}
}
if
(!
isDir
)
{
Log
.
e
(
"DeckUtil"
,
"路径 "
+
path
);
Log
.
e
(
"DeckUtil"
,
"路径1 "
+
AppsSettings
.
get
().
getPackDeckDir
());
if
(
path
.
equals
(
AppsSettings
.
get
().
getPackDeckDir
()))
{
Collections
.
sort
(
deckList
,
dateCom
);
}
else
{
Collections
.
sort
(
deckList
,
nameCom
);
}
}
return
deckList
;
}
/**
* 根据卡组绝对路径获取卡组分类名称
* @param deckPath
...
...
@@ -120,18 +185,42 @@ public class DeckUtil {
return
deckList
;
}
private
final
static
Comparator
<
DeckFile
>
nameCom
=
new
Comparator
<
DeckFile
>()
{
@Override
public
int
compare
(
DeckFile
ydk1
,
DeckFile
ydk2
)
{
return
ydk1
.
getName
().
compareTo
(
ydk2
.
getName
());
public
static
int
getFirstCardCode
(
String
deckPath
)
{
InputStreamReader
in
=
null
;
try
{
in
=
new
InputStreamReader
(
new
FileInputStream
(
new
File
(
deckPath
)),
"utf-8"
);
BufferedReader
reader
=
new
BufferedReader
(
in
);
String
line
=
null
;
DeckItemType
type
=
DeckItemType
.
Space
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
if
(
line
.
startsWith
(
"!side"
))
{
type
=
DeckItemType
.
SideCard
;
continue
;
}
if
(
line
.
startsWith
(
"#"
))
{
if
(
line
.
startsWith
(
"#main"
))
{
type
=
DeckItemType
.
MainCard
;
}
else
if
(
line
.
startsWith
(
"#extra"
))
{
type
=
DeckItemType
.
ExtraCard
;
}
continue
;
}
line
=
line
.
trim
();
if
(
line
.
length
()
==
0
||
!
TextUtils
.
isDigitsOnly
(
line
))
{
if
(
Constants
.
DEBUG
)
Log
.
w
(
"kk"
,
"read not number "
+
line
);
continue
;
}
Integer
id
=
Integer
.
parseInt
(
line
);
return
id
;
}
}
catch
(
IOException
e
)
{
Log
.
e
(
"deckreader"
,
"read 2"
,
e
);
}
finally
{
IOUtils
.
close
(
in
);
}
};
private
final
static
Comparator
<
DeckFile
>
dateCom
=
new
Comparator
<
DeckFile
>()
{
@Override
public
int
compare
(
DeckFile
ydk1
,
DeckFile
ydk2
)
{
return
ydk2
.
getDate
().
compareTo
(
ydk1
.
getDate
());
}
};
return
-
1
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment