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
b88c7908
Commit
b88c7908
authored
Jan 22, 2020
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
不是自带数据库卡片不做下载
parent
709702ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
89 deletions
+92
-89
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
...rc/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
+36
-33
mobile/src/main/java/ocgcore/CardManager.java
mobile/src/main/java/ocgcore/CardManager.java
+56
-56
No files found.
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
View file @
b88c7908
...
...
@@ -32,6 +32,7 @@ import cn.garymb.ygomobile.utils.CardUtils;
import
cn.garymb.ygomobile.utils.DownloadUtil
;
import
cn.garymb.ygomobile.utils.FileUtils
;
import
cn.garymb.ygomobile.utils.YGOUtil
;
import
ocgcore.CardManager
;
import
ocgcore.StringManager
;
import
ocgcore.data.Card
;
import
ocgcore.enums.CardType
;
...
...
@@ -311,7 +312,6 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
});
photoView
.
setOnLongClickListener
(
new
View
.
OnLongClickListener
()
{
@Override
public
boolean
onLongClick
(
View
v
)
{
if
(!
isDownloadCardImage
)
...
...
@@ -356,43 +356,46 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
private
void
downloadCardImage
(
int
code
,
File
file
)
{
isDownloadCardImage
=
false
;
DownloadUtil
.
get
().
download
(
YGOUtil
.
getCardImageDetailUrl
(
code
),
file
.
getParent
(),
file
.
getName
(),
new
DownloadUtil
.
OnDownloadListener
()
{
@Override
public
void
onDownloadSuccess
(
File
file
)
{
if
(
file
.
length
()
<
50
*
1024
)
{
FileUtils
.
deleteFile
(
file
);
Message
message
=
new
Message
();
message
.
what
=
TYPE_DOWNLOAD_CARD_IMAGE_EXCEPTION
;
message
.
obj
=
context
.
getString
(
R
.
string
.
download_image_error
);
handler
.
sendMessage
(
message
);
}
else
{
CardManager
cdb
=
new
CardManager
(
file
.
getAbsolutePath
(),
null
);
if
(
cdb
.
getCard
(
code
)
!=
null
)
{
DownloadUtil
.
get
().
download
(
YGOUtil
.
getCardImageDetailUrl
(
code
),
file
.
getParent
(),
file
.
getName
(),
new
DownloadUtil
.
OnDownloadListener
()
{
@Override
public
void
onDownloadSuccess
(
File
file
)
{
if
(
file
.
length
()
<
50
*
1024
)
{
FileUtils
.
deleteFile
(
file
);
Message
message
=
new
Message
();
message
.
what
=
TYPE_DOWNLOAD_CARD_IMAGE_EXCEPTION
;
message
.
obj
=
context
.
getString
(
R
.
string
.
download_image_error
);
handler
.
sendMessage
(
message
);
}
else
{
Message
message
=
new
Message
();
message
.
what
=
TYPE_DOWNLOAD_CARD_IMAGE_OK
;
message
.
arg1
=
code
;
handler
.
sendMessage
(
message
);
}
}
@Override
public
void
onDownloading
(
int
progress
)
{
Message
message
=
new
Message
();
message
.
what
=
TYPE_DOWNLOAD_CARD_IMAGE_
OK
;
message
.
arg1
=
code
;
message
.
what
=
TYPE_DOWNLOAD_CARD_IMAGE_
ING
;
message
.
arg1
=
progress
;
handler
.
sendMessage
(
message
);
}
}
@Override
public
void
onDownloading
(
int
progress
)
{
Message
message
=
new
Message
();
message
.
what
=
TYPE_DOWNLOAD_CARD_IMAGE_ING
;
message
.
arg1
=
progress
;
handler
.
sendMessage
(
message
);
}
@Override
public
void
onDownloadFailed
(
Exception
e
)
{
//下载失败后删除下载的文件
FileUtils
.
deleteFile
(
file
);
downloadCardImage
(
code
,
file
);
@Override
public
void
onDownloadFailed
(
Exception
e
)
{
//下载失败后删除下载的文件
FileUtils
.
deleteFile
(
file
);
downloadCardImage
(
code
,
file
);
Message
message
=
new
Message
();
message
.
what
=
TYPE_DOWNLOAD_CARD_IMAGE_EXCEPTION
;
message
.
obj
=
e
.
toString
();
handler
.
sendMessage
(
message
);
}
});
Message
message
=
new
Message
();
message
.
what
=
TYPE_DOWNLOAD_CARD_IMAGE_EXCEPTION
;
message
.
obj
=
e
.
toString
();
handler
.
sendMessage
(
message
);
}
});
}
}
public
void
onPreCard
()
{
...
...
mobile/src/main/java/ocgcore/CardManager.java
View file @
b88c7908
...
...
@@ -30,64 +30,15 @@ import ocgcore.data.Card;
public
class
CardManager
{
private
String
dbDir
,
exDbPath
;
private
static
int
cdbNum
=
0
;
private
final
SparseArray
<
Card
>
cardDataHashMap
=
new
SparseArray
<>();
private
static
int
cdbNum
=
0
;
private
String
dbDir
,
exDbPath
;
public
CardManager
(
String
dbDir
,
String
exPath
)
{
this
.
dbDir
=
dbDir
;
this
.
exDbPath
=
exPath
;
}
public
Card
getCard
(
int
code
)
{
return
cardDataHashMap
.
get
(
Integer
.
valueOf
(
code
));
}
public
int
getCount
()
{
return
cardDataHashMap
.
size
();
}
public
SparseArray
<
Card
>
getAllCards
()
{
return
cardDataHashMap
;
}
@WorkerThread
public
void
loadCards
()
{
cardDataHashMap
.
clear
();
int
count
=
readAllCards
(
AppsSettings
.
get
().
getDataBaseFile
(),
cardDataHashMap
);
Log
.
i
(
"Irrlicht"
,
"load defualt cdb:"
+
count
);
if
(
AppsSettings
.
get
().
isReadExpansions
())
{
File
dir
=
new
File
(
exDbPath
);
if
(
dir
.
exists
())
{
File
[]
files
=
dir
.
listFiles
(
new
FilenameFilter
()
{
@Override
public
boolean
accept
(
File
dir
,
String
name
)
{
File
file
=
new
File
(
dir
,
name
);
return
file
.
isFile
()
&&
(
name
.
endsWith
(
".cdb"
)||
name
.
endsWith
(
".zip"
));
}
});
//读取全部卡片
if
(
files
!=
null
)
{
for
(
File
file
:
files
)
{
if
(
file
.
getName
().
endsWith
(
".cdb"
)){
count
=
readAllCards
(
file
,
cardDataHashMap
);
}
else
if
(
file
.
getName
().
endsWith
(
".zip"
)){
Log
.
e
(
"CardManager"
,
"读取压缩包"
);
try
{
for
(
File
file1:
readZipCdb
(
file
.
getAbsolutePath
())){
count
=
readAllCards
(
file1
,
cardDataHashMap
);
}
}
catch
(
IOException
e
)
{
Log
.
e
(
"CardManager"
,
"读取压缩包错误"
+
e
);
}
}
Log
.
i
(
"Irrlicht"
,
"load "
+
count
+
" cdb:"
+
file
);
}
}
}
}
}
private
static
SQLiteDatabase
openDatabase
(
String
file
)
{
return
SQLiteDatabase
.
openDatabase
(
file
,
null
,
SQLiteDatabase
.
NO_LOCALIZED_COLLATORS
|
SQLiteDatabase
.
OPEN_READONLY
);
...
...
@@ -124,21 +75,21 @@ public class CardManager {
}
public
static
List
<
File
>
readZipCdb
(
String
zipPath
)
throws
IOException
{
String
savePath
=
App
.
get
().
getExternalCacheDir
().
getAbsolutePath
();
List
<
File
>
fileList
=
new
ArrayList
<>();
String
savePath
=
App
.
get
().
getExternalCacheDir
().
getAbsolutePath
();
List
<
File
>
fileList
=
new
ArrayList
<>();
ZipFile
zf
=
new
ZipFile
(
zipPath
,
"GBK"
);
ZipFile
zf
=
new
ZipFile
(
zipPath
,
"GBK"
);
InputStream
in
=
new
BufferedInputStream
(
new
FileInputStream
(
zipPath
));
ZipInputStream
zin
=
new
ZipInputStream
(
in
);
ZipEntry
ze
;
Enumeration
<
ZipEntry
>
entris
=
zf
.
getEntries
();
while
(
entris
.
hasMoreElements
())
{
ze
=
entris
.
nextElement
();
ze
=
entris
.
nextElement
();
if
(
ze
.
isDirectory
())
{
//Do nothing
}
else
{
if
(
ze
.
getName
().
endsWith
(
".cdb"
))
{
File
file
=
new
File
(
savePath
,
"cards"
+
cdbNum
+
".cdb"
);
File
file
=
new
File
(
savePath
,
"cards"
+
cdbNum
+
".cdb"
);
InputStream
inputStream
=
zf
.
getInputStream
(
ze
);
OutputStream
os
=
new
FileOutputStream
(
file
);
int
bytesRead
=
0
;
...
...
@@ -157,6 +108,55 @@ public class CardManager {
return
fileList
;
}
public
Card
getCard
(
int
code
)
{
return
cardDataHashMap
.
get
(
Integer
.
valueOf
(
code
));
}
public
int
getCount
()
{
return
cardDataHashMap
.
size
();
}
public
SparseArray
<
Card
>
getAllCards
()
{
return
cardDataHashMap
;
}
@WorkerThread
public
void
loadCards
()
{
cardDataHashMap
.
clear
();
int
count
=
readAllCards
(
AppsSettings
.
get
().
getDataBaseFile
(),
cardDataHashMap
);
Log
.
i
(
"Irrlicht"
,
"load defualt cdb:"
+
count
);
if
(
AppsSettings
.
get
().
isReadExpansions
())
{
File
dir
=
new
File
(
exDbPath
);
if
(
dir
.
exists
())
{
File
[]
files
=
dir
.
listFiles
(
new
FilenameFilter
()
{
@Override
public
boolean
accept
(
File
dir
,
String
name
)
{
File
file
=
new
File
(
dir
,
name
);
return
file
.
isFile
()
&&
(
name
.
endsWith
(
".cdb"
)
||
name
.
endsWith
(
".zip"
));
}
});
//读取全部卡片
if
(
files
!=
null
)
{
for
(
File
file
:
files
)
{
if
(
file
.
getName
().
endsWith
(
".cdb"
))
{
count
=
readAllCards
(
file
,
cardDataHashMap
);
}
else
if
(
file
.
getName
().
endsWith
(
".zip"
))
{
Log
.
e
(
"CardManager"
,
"读取压缩包"
);
try
{
for
(
File
file1
:
readZipCdb
(
file
.
getAbsolutePath
()))
{
count
=
readAllCards
(
file1
,
cardDataHashMap
);
}
}
catch
(
IOException
e
)
{
Log
.
e
(
"CardManager"
,
"读取压缩包错误"
+
e
);
}
}
Log
.
i
(
"Irrlicht"
,
"load "
+
count
+
" cdb:"
+
file
);
}
}
}
}
}
@WorkerThread
protected
int
readAllCards
(
File
file
,
SparseArray
<
Card
>
cardMap
)
{
if
(!
file
.
exists
())
{
...
...
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