Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile-Cn-Ko-En
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-Cn-Ko-En
Commits
2c7d8c68
Commit
2c7d8c68
authored
Jul 04, 2025
by
wangfugui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复bug
parent
e36c905e
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
289 additions
and
168 deletions
+289
-168
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareApiUtil.java
...va/cn/garymb/ygomobile/deck_square/DeckSquareApiUtil.java
+169
-99
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareFileUtil.java
...a/cn/garymb/ygomobile/deck_square/DeckSquareFileUtil.java
+42
-20
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareMyDeckFragment.java
...arymb/ygomobile/deck_square/DeckSquareMyDeckFragment.java
+2
-2
mobile/src/main/java/cn/garymb/ygomobile/deck_square/api_response/DeckMultiIdResponse.java
...omobile/deck_square/api_response/DeckMultiIdResponse.java
+52
-0
mobile/src/main/java/cn/garymb/ygomobile/deck_square/api_response/SyncDecksResponse.java
...ygomobile/deck_square/api_response/SyncDecksResponse.java
+0
-38
mobile/src/main/java/cn/garymb/ygomobile/deck_square/bo/SyncMutliDeckResult.java
.../garymb/ygomobile/deck_square/bo/SyncMutliDeckResult.java
+22
-8
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerFragment.java
...ava/cn/garymb/ygomobile/ui/cards/DeckManagerFragment.java
+2
-1
No files found.
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareApiUtil.java
View file @
2c7d8c68
...
...
@@ -20,6 +20,7 @@ import cn.garymb.ygomobile.bean.DeckType;
import
cn.garymb.ygomobile.bean.events.DeckFile
;
import
cn.garymb.ygomobile.deck_square.api_response.BasicResponse
;
import
cn.garymb.ygomobile.deck_square.api_response.DeckIdResponse
;
import
cn.garymb.ygomobile.deck_square.api_response.DeckMultiIdResponse
;
import
cn.garymb.ygomobile.deck_square.api_response.DownloadDeckResponse
;
import
cn.garymb.ygomobile.deck_square.api_response.GetSquareDeckCondition
;
import
cn.garymb.ygomobile.deck_square.api_response.LoginRequest
;
...
...
@@ -32,7 +33,6 @@ import cn.garymb.ygomobile.deck_square.api_response.PushDeckResponse;
import
cn.garymb.ygomobile.deck_square.api_response.PushMultiDeck
;
import
cn.garymb.ygomobile.deck_square.api_response.PushSingleDeck
;
import
cn.garymb.ygomobile.deck_square.api_response.SquareDeckResponse
;
import
cn.garymb.ygomobile.deck_square.api_response.SyncDecksResponse
;
import
cn.garymb.ygomobile.deck_square.bo.MyDeckItem
;
import
cn.garymb.ygomobile.deck_square.bo.SyncMutliDeckResult
;
import
cn.garymb.ygomobile.utils.LogUtil
;
...
...
@@ -172,51 +172,8 @@ public class DeckSquareApiUtil {
}
/**
* 阻塞方法,推送新卡组的内容时使用。首先从服务器请求一个新的卡组id,之后将卡组上传到服务器
* 首先调用服务端api获取卡组id,之后将卡组id设置到ydk中,之后调用服务器api将卡组上传
*
* @param deckFile
* @param loginToken
*/
public
static
PushDeckResponse
requestIdAndPushDeck
(
DeckFile
deckFile
,
LoginToken
loginToken
)
throws
IOException
{
if
(
loginToken
==
null
)
{
return
null
;
}
String
getDeckIdUrl
=
"http://rarnu.xyz:38383/api/mdpro3/deck/deckId"
;
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"ReqSource"
,
"MDPro3"
);
headers
.
put
(
"token"
,
loginToken
.
getServerToken
());
Gson
gson
=
new
Gson
();
DeckIdResponse
deckIdResult
=
null
;
Response
response
=
OkhttpUtil
.
synchronousGet
(
getDeckIdUrl
,
null
,
headers
);
String
responseBodyString
=
response
.
body
().
string
();
// Convert JSON to Java object using Gson
deckIdResult
=
gson
.
fromJson
(
responseBodyString
,
DeckIdResponse
.
class
);
LogUtil
.
i
(
TAG
,
"deck id result:"
+
deckIdResult
.
toString
());
if
(
deckIdResult
==
null
)
{
return
null
;
}
String
deckId
=
deckIdResult
.
getDeckId
();
//从服务器获取
if
(
deckId
==
null
)
{
return
null
;
}
return
pushDeck
(
deckFile
,
loginToken
,
deckId
);
}
/**
* 阻塞方法,将对应于deckId、deckName的卡组内容json推送到服务器。
* 如果在服务器上不存在deckId、deckName对应的记录,则创建新卡组
* 如果在服务器存在deckId相同的记录,则更新卡组,deckName会覆盖服务器上的卡组名
* 如果在服务器存在deckName相同、deckId不同的记录,则更新失败
*
...
...
@@ -259,55 +216,132 @@ public class DeckSquareApiUtil {
return
result
;
}
/**
* 批量同步卡组到云,入参为DeckData
* 阻塞方法,将对应于deckDataList、deckIdList的卡组内容json推送到服务器。
* 如果在服务器存在deckId相同的记录,则更新卡组,deckName会覆盖服务器上的卡组名
* 如果在服务器存在deckName相同、deckId不同的记录,则更新失败
*
* @param deckDataList
* @param loginToken
* @param deckIdList
* @return
* @throws IOException
*/
public
static
SyncDecksResponse
syncDecks
(
List
<
PushMultiDeck
.
DeckData
>
deckDataList
,
LoginToken
loginToken
)
throws
IOException
{
SyncDecksResponse
result
=
null
;
String
url
=
"http://rarnu.xyz:38383/api/mdpro3/sync/multi"
;
private
static
PushDeckResponse
pushDecks
(
List
<
MyDeckItem
>
deckDataList
,
LoginToken
loginToken
,
List
<
String
>
deckIdList
)
throws
IOException
{
List
<
PushMultiDeck
.
DeckData
>
decks
=
new
ArrayList
<>();
List
<
String
>
deckContents
=
new
ArrayList
<>();
if
(
deckDataList
.
size
()
!=
deckIdList
.
size
())
{
return
null
;
}
for
(
int
i
=
0
;
i
<
deckDataList
.
size
();
i
++)
{
MyDeckItem
myDeckItem
=
deckDataList
.
get
(
i
);
String
deckContent
=
DeckSquareFileUtil
.
setDeckId
(
myDeckItem
.
getDeckPath
(),
loginToken
.
getUserId
(),
deckIdList
.
get
(
i
));
PushMultiDeck
.
DeckData
data
=
new
PushMultiDeck
.
DeckData
();
data
.
setDeckYdk
(
deckContent
);
data
.
setDeckName
(
myDeckItem
.
getDeckName
());
data
.
setDeckId
(
deckIdList
.
get
(
i
));
decks
.
add
(
data
);
}
return
pushMultiDecks
(
decks
,
loginToken
);
}
/**
* 阻塞方法,推送新卡组的内容时使用。首先从服务器请求一个新的卡组id,之后将卡组上传到服务器
* 首先调用服务端api获取卡组id,之后将卡组id设置到ydk中,之后调用服务器api将卡组上传
*
* @param deckFile
* @param loginToken
*/
public
static
PushDeckResponse
requestIdAndPushNewDeck
(
DeckFile
deckFile
,
LoginToken
loginToken
)
throws
IOException
{
if
(
loginToken
==
null
)
{
return
null
;
}
String
getDeckIdUrl
=
"http://rarnu.xyz:38383/api/mdpro3/deck/deckId"
;
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"ReqSource"
,
"MDPro3"
);
headers
.
put
(
"token"
,
loginToken
.
getServerToken
());
Gson
gson
=
new
Gson
();
PushMultiDeck
pushMultiDeck
=
new
PushMultiDeck
();
pushMultiDeck
.
setDeckContributor
(
loginToken
.
getUserId
().
toString
());
pushMultiDeck
.
setUserId
(
loginToken
.
getUserId
());
pushMultiDeck
.
setDecks
(
deckDataList
);
String
json
=
gson
.
toJson
(
pushMultiDeck
);
Response
response
=
OkhttpUtil
.
postJson
(
url
,
json
,
headers
);
DeckIdResponse
deckIdResult
=
null
;
Response
response
=
OkhttpUtil
.
synchronousGet
(
getDeckIdUrl
,
null
,
headers
);
String
responseBodyString
=
response
.
body
().
string
();
// Convert JSON to Java object using Gson
deckIdResult
=
gson
.
fromJson
(
responseBodyString
,
DeckIdResponse
.
class
);
LogUtil
.
i
(
TAG
,
"deck id result:"
+
deckIdResult
.
toString
());
result
=
gson
.
fromJson
(
responseBodyString
,
SyncDecksResponse
.
class
);
LogUtil
.
i
(
TAG
,
"push deck response:"
+
responseBodyString
);
return
result
;
if
(
deckIdResult
==
null
)
{
return
null
;
}
String
deckId
=
deckIdResult
.
getDeckId
();
//从服务器获取
if
(
deckId
==
null
)
{
return
null
;
}
return
pushDeck
(
deckFile
,
loginToken
,
deckId
);
}
/**
* 批量同步卡组到云,入参为MyDeckItem
* 阻塞方法,推送新卡组的内容时使用。首先从服务器请求一个新的卡组id,之后将卡组上传到服务器
* 首先调用服务端api获取卡组id,之后将卡组id设置到ydk中,之后调用服务器api将卡组上传
* 首先获取卡组id,之后上传新卡组
*
* @param deckDataList
* @param loginToken
* @return
* @throws IOException
*/
public
static
SyncDecksResponse
syncMyDecks
(
List
<
MyDeckItem
>
deckDataList
,
LoginToken
loginToken
)
throws
IOException
{
SyncDecksResponse
result
=
null
;
String
url
=
"http://rarnu.xyz:38383/api/mdpro3/sync/multi"
;
public
static
PushDeckResponse
requestIdAndPushNewDecks
(
List
<
MyDeckItem
>
deckDataList
,
LoginToken
loginToken
)
throws
IOException
{
if
(
loginToken
==
null
)
{
return
null
;
}
Gson
gson
=
new
Gson
();
String
getDeckIdUrl
=
"http://rarnu.xyz:38383/api/mdpro3/deck/deckIds"
;
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"ReqSource"
,
"MDPro3"
);
headers
.
put
(
"token"
,
loginToken
.
getServerToken
());
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"count"
,
deckDataList
.
size
());
Response
response
=
OkhttpUtil
.
synchronousGet
(
getDeckIdUrl
,
paramMap
,
headers
);
DeckMultiIdResponse
deckIdResult
=
gson
.
fromJson
(
response
.
body
().
string
(),
DeckMultiIdResponse
.
class
);
if
(
deckIdResult
==
null
)
{
return
null
;
}
List
<
String
>
deckId
=
deckIdResult
.
getDeckId
();
//从服务器获取
if
(
deckId
==
null
)
{
return
null
;
}
return
pushDecks
(
deckDataList
,
loginToken
,
deckId
);
}
/**
* 批量上传已经在云上存在的卡组
*
* @param deckItems
* @param loginToken
* @return
* @throws IOException
*/
public
static
PushDeckResponse
syncMyDecks
(
List
<
MyDeckItem
>
deckItems
,
LoginToken
loginToken
)
throws
IOException
{
/* 构造json */
List
<
PushMultiDeck
.
DeckData
>
dataList
=
new
ArrayList
<>();
for
(
MyDeckItem
item
:
deck
DataList
)
{
for
(
MyDeckItem
item
:
deck
Items
)
{
PushMultiDeck
.
DeckData
data
=
new
PushMultiDeck
.
DeckData
();
data
.
setDeckId
(
item
.
getDeckId
());
data
.
setDeckName
(
item
.
getDeckName
());
...
...
@@ -318,6 +352,18 @@ public class DeckSquareApiUtil {
data
.
setDeckYdk
(
deckContent
);
dataList
.
add
(
data
);
}
return
pushMultiDecks
(
dataList
,
loginToken
);
}
public
static
PushDeckResponse
pushMultiDecks
(
List
<
PushMultiDeck
.
DeckData
>
dataList
,
LoginToken
loginToken
)
throws
IOException
{
String
url
=
"http://rarnu.xyz:38383/api/mdpro3/sync/multi"
;
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"ReqSource"
,
"MDPro3"
);
headers
.
put
(
"token"
,
loginToken
.
getServerToken
());
PushDeckResponse
result
=
null
;
Gson
gson
=
new
Gson
();
PushMultiDeck
pushMultiDeck
=
new
PushMultiDeck
();
...
...
@@ -329,7 +375,7 @@ public class DeckSquareApiUtil {
Response
response
=
OkhttpUtil
.
postJson
(
url
,
json
,
headers
);
String
responseBodyString
=
response
.
body
().
string
();
result
=
gson
.
fromJson
(
responseBodyString
,
SyncDecks
Response
.
class
);
result
=
gson
.
fromJson
(
responseBodyString
,
PushDeck
Response
.
class
);
LogUtil
.
i
(
TAG
,
"push deck response:"
+
responseBodyString
);
return
result
;
...
...
@@ -364,7 +410,8 @@ public class DeckSquareApiUtil {
*
* @param deckId
*/
public
static
BasicResponse
setDeckPublic
(
String
deckId
,
LoginToken
loginToken
,
boolean
publicState
)
throws
IOException
{
public
static
BasicResponse
setDeckPublic
(
String
deckId
,
LoginToken
loginToken
,
boolean
publicState
)
throws
IOException
{
BasicResponse
result
=
null
;
...
...
@@ -436,7 +483,8 @@ public class DeckSquareApiUtil {
}
public
static
PushDeckResponse
deleteDeck
(
String
deckId
,
LoginToken
loginToken
)
throws
IOException
{
public
static
PushDeckResponse
deleteDeck
(
String
deckId
,
LoginToken
loginToken
)
throws
IOException
{
PushDeckResponse
result
=
null
;
String
url
=
"http://rarnu.xyz:38383/api/mdpro3/sync/single"
;
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
...
...
@@ -478,13 +526,13 @@ public class DeckSquareApiUtil {
public
static
SyncMutliDeckResult
synchronizeDecksV2
()
throws
IOException
,
ParseException
{
SyncMutliDeckResult
r
esult
=
new
SyncMutliDeckResult
();
SyncMutliDeckResult
autoSyncR
esult
=
new
SyncMutliDeckResult
();
// 检查用户是否登录
LoginToken
loginToken
=
DeckSquareApiUtil
.
getLoginData
();
if
(
loginToken
==
null
)
{
r
esult
.
setFlag
(
false
);
r
esult
.
setInfo
(
"need login"
);
return
r
esult
;
autoSyncR
esult
.
setFlag
(
false
);
autoSyncR
esult
.
setInfo
(
"need login"
);
return
autoSyncR
esult
;
}
// 获取本地卡组列表
...
...
@@ -492,9 +540,9 @@ public class DeckSquareApiUtil {
// 获取在线卡组列表
MyDeckResponse
onlineDecksResponse
=
DeckSquareApiUtil
.
getUserDecks
(
loginToken
);
if
(
onlineDecksResponse
==
null
||
onlineDecksResponse
.
getData
()
==
null
)
{
r
esult
.
setFlag
(
false
);
r
esult
.
setInfo
(
"no online decks"
);
return
r
esult
;
autoSyncR
esult
.
setFlag
(
false
);
autoSyncR
esult
.
setInfo
(
"no online decks"
);
return
autoSyncR
esult
;
}
List
<
MyOnlineDeckDetail
>
onlineDecks
=
onlineDecksResponse
.
getData
();
...
...
@@ -504,18 +552,28 @@ public class DeckSquareApiUtil {
for
(
MyOnlineDeckDetail
onlineDeck
:
onlineDecks
)
{
onlineDeckProcessed
.
put
(
onlineDeck
.
getDeckName
(),
false
);
}
List
<
MyDeckItem
>
toUploadDecks
=
new
ArrayList
<>();
// 用于标记本地卡组是否在在线有对应
/* Map<String, Boolean> localDeckProcessed = new HashMap<>();
for (MyDeckItem localDeck : localDecks) {
String deckName = localDeck.getDeckName().replace(Constants.YDK_FILE_EX, "");
localDeckProcessed.put(deckName, false);
}*/
List
<
MyDeckItem
>
syncUploadDecks
=
new
ArrayList
<>();
List
<
MyDeckItem
>
newPushDecks
=
new
ArrayList
<>();
// 遍历本地卡组,处理同名卡组的情况
for
(
MyDeckItem
localDeck
:
localDecks
)
{
boolean
foundOnlineDeck
=
false
;
String
localDeckName
=
localDeck
.
getDeckName
();
// localDeckName = localDeckName.replace(".ydk", "");
for
(
MyOnlineDeckDetail
onlineDeck
:
onlineDecks
)
{
if
(
localDeckName
.
equals
(
onlineDeck
.
getDeckName
()))
{
// 标记该在线卡组已处理
onlineDeckProcessed
.
put
(
onlineDeck
.
getDeckName
(),
true
);
// 标记该本地卡组已处理
foundOnlineDeck
=
true
;
// 比对更新时间
long
localUpdateDate
=
localDeck
.
getUpdateTimestamp
();
...
...
@@ -526,6 +584,7 @@ public class DeckSquareApiUtil {
// 在线卡组更新时间更晚,下载在线卡组覆盖本地卡组
LogUtil
.
w
(
TAG
,
"sync-download deck: "
+
localDeck
.
getDeckName
());
autoSyncResult
.
syncDownload
.
add
(
localDeck
);
downloadOnlineDeck
(
onlineDeck
,
localDeck
.
getDeckPath
(),
onlineUpdateDate
);
}
else
if
(
onlineUpdateDate
==
localUpdateDate
)
{
...
...
@@ -537,28 +596,40 @@ public class DeckSquareApiUtil {
LogUtil
.
w
(
TAG
,
"sync-upload deck: "
+
localDeck
.
getDeckName
());
localDeck
.
setDeckId
(
onlineDeck
.
getDeckId
());
to
UploadDecks
.
add
(
localDeck
);
result
.
to
Upload
.
add
(
localDeck
);
sync
UploadDecks
.
add
(
localDeck
);
autoSyncResult
.
sync
Upload
.
add
(
localDeck
);
}
break
;
}
}
// 本地卡组在在线列表中不存在,则需要获取新的deckid来直接上传
if
(!
foundOnlineDeck
)
{
newPushDecks
.
add
(
localDeck
);
autoSyncResult
.
newUpload
.
add
(
localDeck
);
}
}
SyncDecksResponse
response
=
syncMyDecks
(
toUploadDecks
,
loginToken
);
result
.
pushResponse
=
response
;
PushDeckResponse
response
=
syncMyDecks
(
syncUploadDecks
,
loginToken
);
autoSyncResult
.
pushResponse
=
response
;
if
(!
newPushDecks
.
isEmpty
())
{
PushDeckResponse
pushNewRes
=
requestIdAndPushNewDecks
(
newPushDecks
,
loginToken
);
}
// 处理只存在于在线的卡组(即本地没有同名卡组)
for
(
MyOnlineDeckDetail
onlineDeck
:
onlineDecks
)
{
if
(!
onlineDeckProcessed
.
get
(
onlineDeck
.
getDeckName
()))
{
result
.
d
ownload
.
add
(
onlineDeck
);
autoSyncResult
.
newD
ownload
.
add
(
onlineDeck
);
LogUtil
.
w
(
TAG
,
"sync-download new deck: "
+
onlineDeck
.
getDeckName
());
SyncMutliDeckResult
.
DownloadResult
downloadResult
=
downloadMissingDeckToLocal
(
onlineDeck
,
convertToUnixTimestamp
(
onlineDeck
.
getDeckUpdateDate
()));
r
esult
.
downloadResponse
.
add
(
downloadResult
);
autoSyncR
esult
.
downloadResponse
.
add
(
downloadResult
);
}
}
return
r
esult
;
return
autoSyncR
esult
;
}
...
...
@@ -568,7 +639,8 @@ public class DeckSquareApiUtil {
List
<
MyOnlineDeckDetail
>
onlineDecks
;
}
private
static
SyncMutliDeckResult
.
DownloadResult
downloadMissingDeckToLocal
(
MyOnlineDeckDetail
onlineDeck
,
Long
onlineUpdateDate
)
{
private
static
SyncMutliDeckResult
.
DownloadResult
downloadMissingDeckToLocal
(
MyOnlineDeckDetail
onlineDeck
,
Long
onlineUpdateDate
)
{
try
{
// 根据卡组ID查询在线卡组详情
DownloadDeckResponse
deckResponse
=
DeckSquareApiUtil
.
getDeckById
(
onlineDeck
.
getDeckId
());
...
...
@@ -577,8 +649,6 @@ public class DeckSquareApiUtil {
return
new
SyncMutliDeckResult
.
DownloadResult
(
false
,
onlineDeck
.
getDeckId
(),
"Failed to get deck details for: "
+
onlineDeck
.
getDeckName
());
}
MyOnlineDeckDetail
deckDetail
=
deckResponse
.
getData
();
String
deckContent
=
deckDetail
.
getDeckYdk
();
// 构建本地文件路径
String
deckDirectory
=
AppsSettings
.
get
().
getDeckDir
();
...
...
@@ -597,21 +667,21 @@ public class DeckSquareApiUtil {
fileName
+=
Constants
.
YDK_FILE_EX
;
}
String
filePath
=
deckDirectory
+
"/"
+
fileName
;
String
file
Full
Path
=
deckDirectory
+
"/"
+
fileName
;
// 保存在线卡组到本地
boolean
saved
=
DeckSquareFileUtil
.
saveFileToPath
(
deckDirectory
,
fileName
,
deckResponse
.
getData
().
getDeckYdk
(),
onlineUpdateDate
);
boolean
saved
=
DeckSquareFileUtil
.
saveFileToPath
(
fileFullPath
,
deckResponse
.
getData
().
getDeckYdk
(),
onlineUpdateDate
);
if
(!
saved
)
{
LogUtil
.
e
(
TAG
,
"Failed to save deck file: "
+
filePath
);
return
new
SyncMutliDeckResult
.
DownloadResult
(
false
,
onlineDeck
.
getDeckId
(),
"Failed to save deck file: "
+
filePath
);
LogUtil
.
e
(
TAG
,
"Failed to save deck file: "
+
file
Full
Path
);
return
new
SyncMutliDeckResult
.
DownloadResult
(
false
,
onlineDeck
.
getDeckId
(),
"Failed to save deck file: "
+
file
Full
Path
);
}
LogUtil
.
i
(
TAG
,
"Deck saved to: "
+
filePath
);
LogUtil
.
i
(
TAG
,
"Deck saved to: "
+
file
Full
Path
);
// 更新本地卡组列表
MyDeckItem
newLocalDeck
=
new
MyDeckItem
();
newLocalDeck
.
setDeckName
(
fileName
);
newLocalDeck
.
setDeckPath
(
filePath
);
newLocalDeck
.
setDeckPath
(
file
Full
Path
);
newLocalDeck
.
setDeckId
(
onlineDeck
.
getDeckId
());
newLocalDeck
.
setIdUploaded
(
2
);
// 已上传状态
newLocalDeck
.
setUpdateDate
(
onlineDeck
.
getDeckUpdateDate
());
...
...
@@ -624,7 +694,8 @@ public class DeckSquareApiUtil {
}
}
private
static
boolean
downloadOnlineDeck
(
MyOnlineDeckDetail
onlineDeck
,
String
localPath
,
Long
onlineUpdateDate
)
{
private
static
boolean
downloadOnlineDeck
(
MyOnlineDeckDetail
onlineDeck
,
String
fileFullPath
,
Long
onlineUpdateDate
)
{
try
{
// 根据卡组ID查询在线卡组详情
DownloadDeckResponse
deckResponse
=
DeckSquareApiUtil
.
getDeckById
(
onlineDeck
.
getDeckId
());
...
...
@@ -636,15 +707,13 @@ public class DeckSquareApiUtil {
MyOnlineDeckDetail
deckDetail
=
deckResponse
.
getData
();
String
deckContent
=
deckDetail
.
getDeckYdk
();
// 保存在线卡组到本地
String
fileName
=
onlineDeck
.
getDeckName
()
+
Constants
.
YDK_FILE_EX
;
// 保存在线卡组到本地
boolean
saved
=
DeckSquareFileUtil
.
saveFileToPath
(
localPath
,
onlineDeck
.
getDeckName
(),
deckContent
,
onlineUpdateDate
);
boolean
saved
=
DeckSquareFileUtil
.
saveFileToPath
(
fileFullPath
,
deckContent
,
onlineUpdateDate
);
if
(!
saved
)
{
LogUtil
.
e
(
TAG
,
"Failed to save deck file: "
+
loca
lPath
);
LogUtil
.
e
(
TAG
,
"Failed to save deck file: "
+
fileFul
lPath
);
return
false
;
}
LogUtil
.
i
(
TAG
,
"Deck updated: "
+
loca
lPath
);
LogUtil
.
i
(
TAG
,
"Deck updated: "
+
fileFul
lPath
);
return
true
;
}
catch
(
Exception
e
)
{
LogUtil
.
e
(
TAG
,
"Error downloading deck: "
+
e
.
getMessage
());
...
...
@@ -661,7 +730,8 @@ public class DeckSquareApiUtil {
* @param loginToken
* @return
*/
private
static
boolean
uploadLocalDeck
(
MyDeckItem
localDeck
,
String
onlineDeckId
,
LoginToken
loginToken
)
{
private
static
boolean
uploadLocalDeck
(
MyDeckItem
localDeck
,
String
onlineDeckId
,
LoginToken
loginToken
)
{
try
{
DeckFile
deckFile
=
new
DeckFile
(
localDeck
.
getDeckPath
(),
DeckType
.
ServerType
.
MY_SQUARE
);
deckFile
.
setName
(
localDeck
.
getDeckName
());
...
...
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareFileUtil.java
View file @
2c7d8c68
...
...
@@ -26,7 +26,8 @@ import ocgcore.data.Card;
public
class
DeckSquareFileUtil
{
//
private
static
final
String
TAG
=
DeckSquareListAdapter
.
class
.
getSimpleName
();
private
static
final
String
TAG
=
"seesee decksquareApiUtil"
;
//private static final String TAG = DeckSquareListAdapter.class.getSimpleName();
// public static List<String> readLastLinesWithNIO(File file, int numLines) {
// try {
...
...
@@ -57,7 +58,7 @@ public class DeckSquareFileUtil {
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
LogUtil
.
i
(
TAG
,
line
);
//
LogUtil.i(TAG, line);
if
(
line
.
startsWith
(
"###"
))
{
//注意,先判断###,后判断##。因为###会包括##的情况
try
{
String
data
=
line
.
replace
(
"#"
,
""
);
...
...
@@ -207,20 +208,10 @@ public class DeckSquareFileUtil {
return
content
;
}
/**
* 保存文件到指定路径,并设置指定的最后修改时间
*
* @param path 保存路径
* @param fileName 文件名
* @param content 文件内容
* @param modificationTime 期望的最后修改时间(毫秒时间戳)
* @return 保存是否成功
*/
public
static
boolean
saveFileToPath
(
String
path
,
String
fileName
,
String
content
,
long
modificationTime
)
{
public
static
boolean
saveFile
(
File
file
,
String
content
,
long
modificationTime
)
{
FileOutputStream
fos
=
null
;
try
{
// 创建文件对象
File
file
=
new
File
(
path
,
fileName
);
fos
=
new
FileOutputStream
(
file
);
// 创建文件输出流
// 写入内容
...
...
@@ -251,6 +242,33 @@ public class DeckSquareFileUtil {
return
true
;
}
/**
*
* @param fileFullPath 文件的完整路径
* @param content
* @param modificationTime
* @return
*/
public
static
boolean
saveFileToPath
(
String
fileFullPath
,
String
content
,
long
modificationTime
)
{
File
file
=
new
File
(
fileFullPath
);
return
saveFile
(
file
,
content
,
modificationTime
);
}
/**
* 保存文件到指定路径,并设置指定的最后修改时间
*
* @param fileParentPath 保存文件的父目录路径
* @param fileName 文件名
* @param content 文件内容
* @param modificationTime 最后修改时间(毫秒时间戳)
* @return 保存是否成功
*/
public
static
boolean
saveFileToPath
(
String
fileParentPath
,
String
fileName
,
String
content
,
long
modificationTime
)
{
File
file
=
new
File
(
fileParentPath
,
fileName
);
return
saveFile
(
file
,
content
,
modificationTime
);
}
public
static
List
<
Card
>
convertTempDeckYdk
(
String
deckYdk
)
{
String
[]
deckLine
=
deckYdk
.
split
(
"\r\n|\r|\n"
);
...
...
@@ -277,13 +295,17 @@ public class DeckSquareFileUtil {
}
public
static
long
convertToUnixTimestamp
(
String
dateTimeStr
)
throws
ParseException
{
public
static
long
convertToUnixTimestamp
(
String
dateTimeStr
)
{
try
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss"
);
sdf
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
sdf
.
setLenient
(
false
);
Date
date
=
sdf
.
parse
(
dateTimeStr
);
return
date
.
getTime
();
}
catch
(
ParseException
e
){
e
.
printStackTrace
();
}
return
0
;
}
}
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareMyDeckFragment.java
View file @
2c7d8c68
...
...
@@ -128,7 +128,7 @@ public class DeckSquareMyDeckFragment extends Fragment {
LogUtil
.
i
(
TAG
,
"Sync decks fail"
+
e
.
getMessage
());
}).
done
((
result
)
->
{
String
info
=
"sync decks: upload "
+
result
.
toUpload
.
size
()
+
", download "
+
result
.
d
ownload
.
size
();
String
info
=
"sync decks: upload "
+
result
.
syncUpload
.
size
()
+
", download "
+
result
.
newD
ownload
.
size
();
YGOUtil
.
showTextToast
(
info
,
Toast
.
LENGTH_LONG
);
});
...
...
@@ -216,7 +216,7 @@ public class DeckSquareMyDeckFragment extends Fragment {
YGOUtil
.
showTextToast
(
"Sync decks fail"
,
Toast
.
LENGTH_LONG
);
LogUtil
.
i
(
TAG
,
"Sync decks fail"
+
e
.
getMessage
());
}).
done
((
result
)
->
{
String
info
=
"sync decks: upload "
+
result
.
toUpload
.
size
()
+
", download "
+
result
.
d
ownload
.
size
();
String
info
=
"sync decks: upload "
+
result
.
syncUpload
.
size
()
+
", download "
+
result
.
newD
ownload
.
size
();
YGOUtil
.
showTextToast
(
info
,
Toast
.
LENGTH_LONG
);
});
...
...
mobile/src/main/java/cn/garymb/ygomobile/deck_square/api_response/DeckMultiIdResponse.java
0 → 100644
View file @
2c7d8c68
package
cn.garymb.ygomobile.deck_square.api_response
;
import
com.google.gson.annotations.Expose
;
import
com.google.gson.annotations.SerializedName
;
import
java.util.List
;
public
class
DeckMultiIdResponse
{
@Expose
public
int
code
;
@Expose
public
String
message
;
@Expose
@SerializedName
(
"data"
)
public
List
<
String
>
deckId
;
public
int
getCode
()
{
return
code
;
}
public
void
setCode
(
int
code
)
{
this
.
code
=
code
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
List
<
String
>
getDeckId
()
{
return
deckId
;
}
public
void
setDeckId
(
List
<
String
>
deckId
)
{
this
.
deckId
=
deckId
;
}
@Override
public
String
toString
()
{
return
"DeckMultiIdResponse{"
+
"code="
+
code
+
", message='"
+
message
+
'\''
+
", deckId="
+
deckId
+
'}'
;
}
}
mobile/src/main/java/cn/garymb/ygomobile/deck_square/api_response/SyncDecksResponse.java
deleted
100644 → 0
View file @
e36c905e
package
cn.garymb.ygomobile.deck_square.api_response
;
/* 同步卡组响应体类*/
public
class
SyncDecksResponse
{
private
Integer
code
;
private
String
message
;
private
Integer
data
;
public
SyncDecksResponse
(
Integer
code
,
String
message
,
Integer
data
)
{
this
.
code
=
code
;
this
.
message
=
message
;
this
.
data
=
data
;
}
// getters and setters
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
Integer
code
)
{
this
.
code
=
code
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
Integer
getData
()
{
return
data
;
}
public
void
setData
(
Integer
data
)
{
this
.
data
=
data
;
}
}
mobile/src/main/java/cn/garymb/ygomobile/deck_square/bo/SyncMutliDeckResult.java
View file @
2c7d8c68
package
cn.garymb.ygomobile.deck_square.bo
;
import
org.minidns.record.A
;
import
java.util.ArrayList
;
import
java.util.List
;
import
cn.garymb.ygomobile.deck_square.api_response.MyOnlineDeckDetail
;
import
cn.garymb.ygomobile.deck_square.api_response.
SyncDecks
Response
;
import
cn.garymb.ygomobile.deck_square.api_response.
PushDeck
Response
;
public
class
SyncMutliDeckResult
{
boolean
flag
=
false
;
String
info
=
null
;
public
SyncDecks
Response
pushResponse
;
public
PushDeck
Response
pushResponse
;
public
List
<
MyDeckItem
>
toUpload
;
//用于记录已推送的卡组
public
List
<
MyOnlineDeckDetail
>
download
;
public
List
<
MyDeckItem
>
syncUpload
;
//用于记录已推送的卡组
public
List
<
MyDeckItem
>
newUpload
;
//用于记录第一次推送到云的卡组
public
List
<
MyDeckItem
>
syncDownload
;
//用于记录已推送的卡组
public
List
<
MyOnlineDeckDetail
>
newDownload
;
public
List
<
DownloadResult
>
downloadResponse
;
public
static
class
DownloadResult
{
...
...
@@ -37,16 +41,20 @@ public class SyncMutliDeckResult {
public
SyncMutliDeckResult
()
{
flag
=
true
;
downloadResponse
=
new
ArrayList
<>();
download
=
new
ArrayList
<>();
toUpload
=
new
ArrayList
<>();
newDownload
=
new
ArrayList
<>();
syncUpload
=
new
ArrayList
<>();
newUpload
=
new
ArrayList
<>();
syncDownload
=
new
ArrayList
<>();
}
public
SyncMutliDeckResult
(
boolean
flag
,
String
info
)
{
this
.
flag
=
flag
;
this
.
info
=
info
;
downloadResponse
=
new
ArrayList
<>();
download
=
new
ArrayList
<>();
toUpload
=
new
ArrayList
<>();
newDownload
=
new
ArrayList
<>();
syncUpload
=
new
ArrayList
<>();
newUpload
=
new
ArrayList
<>();
syncDownload
=
new
ArrayList
<>();
}
public
boolean
isFlag
()
{
...
...
@@ -64,4 +72,10 @@ public class SyncMutliDeckResult {
public
void
setInfo
(
String
info
)
{
this
.
info
=
info
;
}
public
String
getMessage
()
{
String
info
=
"sync decks: "
+
syncUpload
.
size
()
+
", push new:"
+
newUpload
.
size
()
+
", download "
+
newDownload
.
size
();
return
info
;
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerFragment.java
View file @
2c7d8c68
...
...
@@ -4,6 +4,7 @@ import static android.content.Context.CLIPBOARD_SERVICE;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
ORI_DECK
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
YDK_FILE_EX
;
import
static
cn
.
garymb
.
ygomobile
.
core
.
IrrlichtBridge
.
ACTION_SHARE_FILE
;
import
static
cn
.
garymb
.
ygomobile
.
deck_square
.
DeckSquareFileUtil
.
convertToUnixTimestamp
;
import
android.content.ClipData
;
import
android.content.ClipboardManager
;
...
...
@@ -1351,7 +1352,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
String
fileFullName
=
deckData
.
getDeckName
()
+
".ydk"
;
File
dir
=
new
File
(
getActivity
().
getApplicationInfo
().
dataDir
,
"cache"
);
//将卡组存到cache缓存目录中
boolean
result
=
DeckSquareFileUtil
.
saveFileToPath
(
dir
.
getPath
(),
fileFullName
,
deckData
.
getDeckYdk
(),
Long
.
valueOf
(
deckData
.
getDeckUpdateDate
()));
boolean
result
=
DeckSquareFileUtil
.
saveFileToPath
(
dir
.
getPath
(),
fileFullName
,
deckData
.
getDeckYdk
(),
convertToUnixTimestamp
(
deckData
.
getDeckUpdateDate
()));
if
(
result
)
{
//存储成功,使用预加载功能
LogUtil
.
i
(
TAG
,
"square deck detail done"
);
//File file = new File(dir, fileFullName);
...
...
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