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
d26e8a1d
Commit
d26e8a1d
authored
Apr 18, 2025
by
wangfugui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善卡组上传功能
parent
5436c3a1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
185 additions
and
19 deletions
+185
-19
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareApiUtil.java
...va/cn/garymb/ygomobile/deck_square/DeckSquareApiUtil.java
+19
-5
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareFileUtil.java
...a/cn/garymb/ygomobile/deck_square/DeckSquareFileUtil.java
+28
-12
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareMyDeckFragment.java
...arymb/ygomobile/deck_square/DeckSquareMyDeckFragment.java
+1
-0
mobile/src/main/java/cn/garymb/ygomobile/deck_square/MyDeckDetailDialog.java
...a/cn/garymb/ygomobile/deck_square/MyDeckDetailDialog.java
+12
-2
mobile/src/main/java/cn/garymb/ygomobile/deck_square/api_response/DeckIdResponse.java
...mb/ygomobile/deck_square/api_response/DeckIdResponse.java
+9
-0
mobile/src/main/java/cn/garymb/ygomobile/deck_square/api_response/PushCardJson.java
...rymb/ygomobile/deck_square/api_response/PushCardJson.java
+116
-0
No files found.
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareApiUtil.java
View file @
d26e8a1d
...
...
@@ -11,6 +11,7 @@ import java.util.Map;
import
cn.garymb.ygomobile.deck_square.api_response.DeckIdResponse
;
import
cn.garymb.ygomobile.deck_square.api_response.DownloadDeckResponse
;
import
cn.garymb.ygomobile.deck_square.api_response.MyDeckResponse
;
import
cn.garymb.ygomobile.deck_square.api_response.PushCardJson
;
import
cn.garymb.ygomobile.utils.LogUtil
;
import
cn.garymb.ygomobile.utils.OkhttpUtil
;
import
cn.garymb.ygomobile.utils.YGOUtil
;
...
...
@@ -85,7 +86,7 @@ public class DeckSquareApiUtil {
}
//首先获取卡组id,之后将卡组id设置到ydk中,之后将其上传
public
static
void
pushDeck
(
String
deckPath
,
Integer
userId
)
{
public
static
void
pushDeck
(
String
deckPath
,
String
deckName
,
Integer
userId
)
{
String
url
=
"http://rarnu.xyz:38383/api/mdpro3/sync/single"
;
String
getDeckIdUrl
=
"http://rarnu.xyz:38383/api/mdpro3/deck/deckId"
;
...
...
@@ -101,15 +102,30 @@ public class DeckSquareApiUtil {
Gson
gson
=
new
Gson
();
// Convert JSON to Java object using Gson
deckIdResult
=
gson
.
fromJson
(
responseBodyString
,
DeckIdResponse
.
class
);
LogUtil
.
i
(
TAG
,
"deck id result:"
+
deckIdResult
.
toString
());
}
String
deckId
=
deckIdResult
.
getDeckId
();
//从服务器获取
DeckSquareFileUtil
.
setDeckId
(
deckPath
,
userId
,
deckId
);
String
deckContent
=
DeckSquareFileUtil
.
setDeckId
(
deckPath
,
userId
,
deckId
);
PushCardJson
pushCardJson
=
new
PushCardJson
();
pushCardJson
.
setDeckContributor
(
userId
.
toString
());
pushCardJson
.
setUserId
(
userId
);
PushCardJson
.
DeckData
deckData
=
new
PushCardJson
.
DeckData
();
deckData
.
setDeckId
(
deckId
);
deckData
.
setDeckName
(
deckName
);
deckData
.
setDelete
(
false
);
deckData
.
setDeckYdk
(
deckContent
);
pushCardJson
.
setDeck
(
deckData
);
Gson
gson
=
new
Gson
();
String
json
=
gson
.
toJson
(
pushCardJson
);
//todo 构造卡组的json
OkhttpUtil
.
postJson
(
url
,
null
,
headers
,
1000
,
new
Callback
()
{
OkhttpUtil
.
postJson
(
url
,
json
,
headers
,
1000
,
new
Callback
()
{
@Override
public
void
onFailure
(
Call
call
,
IOException
e
)
{
...
...
@@ -124,8 +140,6 @@ public class DeckSquareApiUtil {
});
Gson
gson
=
new
Gson
();
// Convert JSON to Java object using Gson
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareFileUtil.java
View file @
d26e8a1d
...
...
@@ -34,6 +34,8 @@ public class DeckSquareFileUtil {
// 使用示例
// Path logPath = Paths.get(context.getFilesDir().getAbsolutePath(), "log.txt");
// List<String> lastTwo = readLastLinesWithNIO(logPath, 2);
//读取file指定的ydk文件,返回其内包含的deckId。如果不包含deckId,返回null
public
static
String
getId
(
File
file
)
{
String
deckId
=
null
;
Integer
userId
;
...
...
@@ -68,6 +70,7 @@ public class DeckSquareFileUtil {
return
deckId
;
}
//查询卡组目录下的所有ydk文件,返回File[]
public
static
File
[]
getAllYdk
()
{
File
dir
=
new
File
(
AppsSettings
.
get
().
getResourcePath
(),
Constants
.
CORE_DECK_PATH
);
File
[]
files
=
dir
.
listFiles
((
file
,
s
)
->
s
.
toLowerCase
(
Locale
.
US
).
endsWith
(
Constants
.
YDK_FILE_EX
));
...
...
@@ -75,6 +78,7 @@ public class DeckSquareFileUtil {
return
files
;
}
//读取卡组目录下的所有ydk文件,解析ydk文件,生成List<MyDeckItem>解析结果
public
static
List
<
MyDeckItem
>
getMyDeckItem
()
{
List
<
MyDeckItem
>
result
=
new
ArrayList
<>();
File
[]
files
=
getAllYdk
();
...
...
@@ -95,11 +99,14 @@ public class DeckSquareFileUtil {
return
result
;
}
//将卡组id、用户id设置到卡组文件上
//下载卡组后,保存之前将其原有id清除
//上传卡组前,填入新的卡组id、用户id
// 读取deckPath对应的卡组文件到string,将卡组id、用户id设置到string中
//注意,不更改ydk文件内容
//下载卡组后,保存卡组之前
//上传卡组前,对于未存在卡组id的卡组,自动填入新的卡组id、用户id
public
static
String
setDeckId
(
String
deckPath
,
Integer
userId
,
String
deckId
)
{
StringBuilder
contentBuilder
=
new
StringBuilder
();
boolean
userIdFlag
=
false
;
boolean
deckIdFlag
=
false
;
FileInputStream
inputStream
=
null
;
try
{
...
...
@@ -111,9 +118,17 @@ public class DeckSquareFileUtil {
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
/* 如果文件中已经存在deckId,则将其替换 */
if
(
line
.
contains
(
"##"
)
&&
!
line
.
contains
(
"###"
))
{
deckIdFlag
=
true
;
line
=
"##"
+
deckId
;
}
else
if
(
line
.
contains
(
"###"
))
{
//存在userId,将其替换
userIdFlag
=
true
;
line
=
"###"
+
userId
;
}
contentBuilder
.
append
(
line
);
contentBuilder
.
append
(
'\n'
);
// Add line break
}
String
content
=
contentBuilder
.
toString
();
}
catch
(
Exception
e
)
{
LogUtil
.
e
(
TAG
,
"read 1"
,
e
);
...
...
@@ -121,16 +136,17 @@ public class DeckSquareFileUtil {
IOUtils
.
close
(
inputStream
);
}
String
content
=
contentBuilder
.
toString
();
//先替换XXX用户id
//后替换XX卡组id
String
original
=
"这是##测试1\r\n的内容,还有##测试2\r\n等其他部分"
;
String
modified
=
original
.
replaceAll
(
"##(.*?)\r\n"
,
"##替换后的内容\r\n"
);
if
(!
userIdFlag
)
{
//原始ydk中不存在userId,添加userId行
contentBuilder
.
append
(
"\n"
);
contentBuilder
.
append
(
"##"
+
userId
);
}
if
(!
deckIdFlag
)
{
//原始ydk中不存在deckId,添加deckId行
contentBuilder
.
append
(
"\n"
);
contentBuilder
.
append
(
"###"
+
deckId
);
}
System
.
out
.
println
(
"修改前: "
+
original
);
System
.
out
.
println
(
"修改后: "
+
modified
);
String
content
=
contentBuilder
.
toString
();
return
content
;
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/deck_square/DeckSquareMyDeckFragment.java
View file @
d26e8a1d
...
...
@@ -45,6 +45,7 @@ public class DeckSquareMyDeckFragment extends Fragment {
});
//点击“我的卡组”中的某个卡组后,弹出dialog,dialog根据卡组的同步情况自动显示对应的下载/上传按钮
deckListAdapter
.
setOnItemClickListener
(
(
adapter
,
view
,
position
)
->
{
// Handle item click
...
...
mobile/src/main/java/cn/garymb/ygomobile/deck_square/MyDeckDetailDialog.java
View file @
d26e8a1d
...
...
@@ -66,7 +66,7 @@ public class MyDeckDetailDialog extends Dialog {
}
else
if
(
item
.
getDeckSouce
()
==
1
)
{
//来自服务器
downloadLayout
.
setVisibility
(
View
.
VISIBLE
);
uploadLayout
.
setVisibility
(
View
.
GONE
);
}
else
if
(
item
.
getDeckSouce
()
==
2
)
{
//
来自服务器
}
else
if
(
item
.
getDeckSouce
()
==
2
)
{
//
本地、服务器均存在
downloadLayout
.
setVisibility
(
View
.
VISIBLE
);
uploadLayout
.
setVisibility
(
View
.
VISIBLE
);
}
...
...
@@ -75,13 +75,23 @@ public class MyDeckDetailDialog extends Dialog {
Integer
userId
=
SharedPreferenceUtil
.
getServerUserId
();
if
(
userId
==
null
)
{
YGOUtil
.
showTextToast
(
"Please login first!"
);
return
;
}
VUiKit
.
defer
().
when
(()
->
{
DeckSquareApiUtil
.
pushDeck
(
item
.
getDeckPath
(),
userId
);
DeckSquareApiUtil
.
pushDeck
(
item
.
getDeckPath
(),
item
.
getDeckName
(),
userId
);
});
//.done();
});
btnDownload
.
setOnClickListener
(
v
->
{
Integer
userId
=
SharedPreferenceUtil
.
getServerUserId
();
if
(
userId
==
null
)
{
YGOUtil
.
showTextToast
(
"Please login first!"
);
return
;
}
VUiKit
.
defer
().
when
(()
->
{
DownloadDeckResponse
response
=
DeckSquareApiUtil
.
getDeckById
(
item
.
getDeckId
());
...
...
mobile/src/main/java/cn/garymb/ygomobile/deck_square/api_response/DeckIdResponse.java
View file @
d26e8a1d
...
...
@@ -38,4 +38,13 @@ public class DeckIdResponse {
public
void
setDeckId
(
String
deckId
)
{
this
.
deckId
=
deckId
;
}
@Override
public
String
toString
()
{
return
"DeckIdResponse{"
+
"code="
+
code
+
", message='"
+
message
+
'\''
+
", deckId='"
+
deckId
+
'\''
+
'}'
;
}
}
mobile/src/main/java/cn/garymb/ygomobile/deck_square/api_response/PushCardJson.java
0 → 100644
View file @
d26e8a1d
package
cn.garymb.ygomobile.deck_square.api_response
;
public
class
PushCardJson
{
private
String
deckContributor
;
private
Integer
userId
;
private
DeckData
deck
;
public
String
getDeckContributor
()
{
return
deckContributor
;
}
public
void
setDeckContributor
(
String
deckContributor
)
{
this
.
deckContributor
=
deckContributor
;
}
public
Integer
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
Integer
userId
)
{
this
.
userId
=
userId
;
}
public
DeckData
getDeck
()
{
return
deck
;
}
public
void
setDeck
(
DeckData
deck
)
{
this
.
deck
=
deck
;
}
public
static
class
DeckData
{
private
String
deckId
;
private
String
deckName
;
private
Integer
deckCoverCard1
=
0
;
private
Integer
deckCoverCard2
=
0
;
private
Integer
deckCoverCard3
=
0
;
private
Integer
deckCase
=
0
;
private
Integer
deckProtector
=
0
;
private
String
deckYdk
;
private
boolean
isDelete
=
false
;
public
String
getDeckId
()
{
return
deckId
;
}
public
void
setDeckId
(
String
deckId
)
{
this
.
deckId
=
deckId
;
}
public
String
getDeckName
()
{
return
deckName
;
}
public
void
setDeckName
(
String
deckName
)
{
this
.
deckName
=
deckName
;
}
public
Integer
getDeckCoverCard1
()
{
return
deckCoverCard1
;
}
public
void
setDeckCoverCard1
(
Integer
deckCoverCard1
)
{
this
.
deckCoverCard1
=
deckCoverCard1
;
}
public
Integer
getDeckCoverCard2
()
{
return
deckCoverCard2
;
}
public
void
setDeckCoverCard2
(
Integer
deckCoverCard2
)
{
this
.
deckCoverCard2
=
deckCoverCard2
;
}
public
Integer
getDeckCoverCard3
()
{
return
deckCoverCard3
;
}
public
void
setDeckCoverCard3
(
Integer
deckCoverCard3
)
{
this
.
deckCoverCard3
=
deckCoverCard3
;
}
public
Integer
getDeckCase
()
{
return
deckCase
;
}
public
void
setDeckCase
(
Integer
deckCase
)
{
this
.
deckCase
=
deckCase
;
}
public
Integer
getDeckProtector
()
{
return
deckProtector
;
}
public
void
setDeckProtector
(
Integer
deckProtector
)
{
this
.
deckProtector
=
deckProtector
;
}
public
String
getDeckYdk
()
{
return
deckYdk
;
}
public
void
setDeckYdk
(
String
deckYdk
)
{
this
.
deckYdk
=
deckYdk
;
}
public
boolean
isDelete
()
{
return
isDelete
;
}
public
void
setDelete
(
boolean
delete
)
{
isDelete
=
delete
;
}
}
}
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