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
7cbd2914
Commit
7cbd2914
authored
Jan 23, 2025
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加关联卡片检查
优化关联卡片获取逻辑
parent
7fee4fd6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
112 deletions
+104
-112
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
...rc/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
+62
-13
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardSearchFragment.java
...java/cn/garymb/ygomobile/ui/cards/CardSearchFragment.java
+5
-41
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerFragment.java
...ava/cn/garymb/ygomobile/ui/cards/DeckManagerFragment.java
+5
-41
mobile/src/main/res/layout/dialog_cardinfo.xml
mobile/src/main/res/layout/dialog_cardinfo.xml
+32
-17
No files found.
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
View file @
7cbd2914
...
...
@@ -72,6 +72,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
private
final
PackManager
packManager
;
private
final
ImageView
cardImage
;
private
final
TextView
name
;
private
final
TextView
relatable
;
private
final
TextView
desc
;
private
final
TextView
level
;
private
final
TextView
type
;
...
...
@@ -111,6 +112,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
private
Button
btn_redownload
;
private
Button
btn_share
;
private
boolean
isDownloadCardImage
=
true
;
private
List
<
String
>
spanStringList
=
new
ArrayList
<>();
@SuppressLint
(
"HandlerLeak"
)
Handler
handler
=
new
Handler
()
{
...
...
@@ -156,6 +158,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
packName
=
findViewById
(
R
.
id
.
pack_name
);
toggleAnimation
(
packName
);
name
=
findViewById
(
R
.
id
.
text_name
);
relatable
=
findViewById
(
R
.
id
.
relatable
);
desc
=
findViewById
(
R
.
id
.
text_desc
);
close
=
findViewById
(
R
.
id
.
btn_close
);
cardCode
=
findViewById
(
R
.
id
.
card_code
);
...
...
@@ -218,7 +221,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
if
(
cardInfo
==
null
)
{
return
;
}
mListener
.
onGetRelatedCardList
(
cardInfo
);
mListener
.
onGetRelatedCardList
(
relatedCards
(
cardInfo
)
);
}
});
findViewById
(
R
.
id
.
lastone
).
setOnClickListener
((
v
)
->
{
...
...
@@ -313,7 +316,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
public
void
setHighlightTextWithClickableSpans
(
String
text
)
{
SpannableString
spannableString
=
new
SpannableString
(
text
);
spanStringList
.
clear
();
// 清空之前的高亮文本列表
// 解析器状态
QuoteType
currentQuoteType
=
QuoteType
.
NONE
;
Stack
<
Integer
>
stack
=
new
Stack
<>();
...
...
@@ -344,6 +347,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
String
quotedText
=
text
.
substring
(
start
,
i
).
trim
();
// 使用 queryable 方法判断是否高亮
applySpan
(
spannableString
,
start
,
i
,
queryable
(
quotedText
)?
YGOUtil
.
c
(
R
.
color
.
holo_blue_bright
)
:
Color
.
WHITE
);
spanStringList
.
add
(
quotedText
);
currentQuoteType
=
QuoteType
.
NONE
;
}
}
...
...
@@ -355,6 +359,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
if
(
stack
.
isEmpty
())
{
String
quotedText
=
text
.
substring
(
start
,
i
).
trim
();
applySpan
(
spannableString
,
start
,
i
,
queryable
(
quotedText
)?
YGOUtil
.
c
(
R
.
color
.
holo_blue_bright
)
:
Color
.
WHITE
);
spanStringList
.
add
(
quotedText
);
currentQuoteType
=
QuoteType
.
NONE
;
}
else
{
stack
.
push
(
i
);
...
...
@@ -364,10 +369,6 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
break
;
}
}
// 处理未关闭的引号对
if
(!
stack
.
isEmpty
())
{
// Handle unclosed quotes error, e.g., log a warning or throw an exception
}
desc
.
setText
(
spannableString
);
desc
.
setMovementMethod
(
LinkMovementMethod
.
getInstance
());
}
...
...
@@ -415,17 +416,13 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
matchingCards
.
add
(
card
);
}
}
// 获取当前卡片信息
Card
currentCard
=
getCardInfo
();
// 检查匹配结果
if
(
matchingCards
.
isEmpty
())
{
return
false
;
// 如果没有找到匹配的卡片,返回 false
}
else
if
(
matchingCards
.
size
()
==
1
)
{
// 如果只有一个匹配项,检查是否是当前卡片
Card
matchedCard
=
matchingCards
.
get
(
0
);
if
(
currentCard
!=
null
&&
currentCard
.
equals
(
matchedCard
))
{
if
(
getCardInfo
()
!=
null
&&
getCardInfo
()
.
equals
(
matchedCard
))
{
return
false
;
// 如果是当前卡片,返回 false
}
else
{
return
true
;
// 否则返回 true
...
...
@@ -435,6 +432,57 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
}
}
private
boolean
relatable
(
Card
cardInfo
)
{
List
<
Card
>
matchingCards
=
relatedCards
(
cardInfo
);
if
(!
matchingCards
.
isEmpty
())
return
true
;
return
false
;
}
private
List
<
Card
>
relatedCards
(
Card
cardInfo
)
{
SparseArray
<
Card
>
cards
=
cardManager
.
getAllCards
();
// 新创建一个表避免外部修改原本的表
List
<
String
>
highlightedTexts
=
new
ArrayList
<>(
spanStringList
);
// 使用 ArrayList 来保存匹配的卡片
List
<
Card
>
matchingCards
=
new
ArrayList
<>();
// 将 cardInfo 的 setCode 转换为 List<Long>
List
<
Long
>
cardInfoSetCodes
=
new
ArrayList
<>();
for
(
long
setCode
:
cardInfo
.
getSetCode
())
{
if
(
setCode
!=
0
)
cardInfoSetCodes
.
add
(
setCode
);
}
Log
.
w
(
"cc cardInfoSetCodes"
,
cardInfoSetCodes
.
toString
());
for
(
int
i
=
0
;
i
<
cards
.
size
();
i
++)
{
Card
card
=
cards
.
valueAt
(
i
);
// 检查卡片名或描述是否包含给定卡片的名字
if
(!
card
.
Name
.
equals
(
cardInfo
.
Name
)
&&
(
card
.
Name
.
contains
(
cardInfo
.
Name
)
||
card
.
Desc
.
contains
(
cardInfo
.
Name
)))
{
// 检查卡片是否已经存在于匹配列表中
if
(!
matchingCards
.
contains
(
card
))
matchingCards
.
add
(
card
);
continue
;
// 如果名称或描述匹配,则跳过系列代码检查
}
// 获取卡片的字段并检查是否有相同的字段
for
(
long
setCode
:
card
.
getSetCode
())
{
if
(
cardInfoSetCodes
.
contains
(
setCode
))
{
if
(!
matchingCards
.
contains
(
card
))
matchingCards
.
add
(
card
);
break
;
// 如果已经找到匹配,可以跳出内层循环
}
}
for
(
String
keyword
:
highlightedTexts
)
{
if
((
card
.
Name
!=
null
&&
card
.
Name
.
equals
(
keyword
))
//和关键词完全一致的视为关联卡
||
(
card
.
Desc
!=
null
&&
(
card
.
Desc
.
contains
(
"「"
+
keyword
+
"」"
)
||
card
.
Desc
.
contains
(
"\""
+
keyword
+
"\""
))))
{
//描述中关键词指向的字段一致的视为关联卡
if
(!
matchingCards
.
contains
(
card
))
matchingCards
.
add
(
card
);
break
;
// 如果找到匹配项,则跳出内层循环
}
}
}
return
matchingCards
;
}
private
void
setCardInfo
(
Card
cardInfo
,
View
view
)
{
if
(
cardInfo
==
null
)
return
;
mCardInfo
=
cardInfo
;
...
...
@@ -446,6 +494,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
packName
.
setText
(
packManager
.
findPackNameById
(
cardInfo
.
Alias
!=
0
?
cardInfo
.
Alias
:
cardInfo
.
Code
));
name
.
setText
(
cardInfo
.
Name
);
setHighlightTextWithClickableSpans
(
cardInfo
.
Name
.
equals
(
"Unknown"
)
?
context
.
getString
(
R
.
string
.
tip_card_info_diff
)
:
cardInfo
.
Desc
);
relatable
.
setVisibility
(
relatable
(
mCardInfo
)
?
View
.
VISIBLE
:
View
.
GONE
);
cardCode
.
setText
(
String
.
format
(
"%08d"
,
cardInfo
.
getCode
()));
if
(
cardInfo
.
isType
(
CardType
.
Token
))
{
faq
.
setVisibility
(
View
.
INVISIBLE
);
...
...
@@ -735,7 +784,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
void
onSearchKeyWord
(
String
keyword
);
void
onGetRelatedCardList
(
Card
cardInfo
);
void
onGetRelatedCardList
(
List
<
Card
>
cardList
);
void
onClose
();
}
...
...
@@ -769,7 +818,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
}
@Override
public
void
onGetRelatedCardList
(
Card
cardInfo
)
{
public
void
onGetRelatedCardList
(
List
<
Card
>
cardList
)
{
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardSearchFragment.java
View file @
7cbd2914
...
...
@@ -314,8 +314,8 @@ public class CardSearchFragment extends BaseFragemnt implements CardLoader.CallB
}
@Override
public
void
onGetRelatedCardList
(
Card
cardInfo
)
{
getRelatedCardList
(
cardInfo
);
public
void
onGetRelatedCardList
(
List
<
Card
>
cardList
)
{
showCardList
(
cardList
,
true
);
}
@Override
...
...
@@ -360,45 +360,9 @@ public class CardSearchFragment extends BaseFragemnt implements CardLoader.CallB
mCardLoader
.
search
(
searchInfo
);
}
private
void
getRelatedCardList
(
Card
cardInfo
)
{
SparseArray
<
Card
>
cards
=
mCardManager
.
getAllCards
();
// 使用 ArrayList 来保存匹配的卡片
List
<
Card
>
matchingCards
=
new
ArrayList
<>();
// 将 cardInfo 的 setCode 转换为 List<Long>
List
<
Long
>
cardInfoSetCodes
=
new
ArrayList
<>();
for
(
long
setCode
:
cardInfo
.
getSetCode
())
{
if
(
setCode
!=
0
)
cardInfoSetCodes
.
add
(
setCode
);
}
Log
.
w
(
"cc cardInfoSetCodes"
,
cardInfoSetCodes
.
toString
());
for
(
int
i
=
0
;
i
<
cards
.
size
();
i
++)
{
Card
card
=
cards
.
valueAt
(
i
);
// 检查卡片是否已经存在于匹配列表中
if
(!
matchingCards
.
contains
(
card
))
{
// 检查卡片名或描述是否包含给定卡片的名字
if
(!
card
.
Name
.
equals
(
cardInfo
.
Name
)
&&
(
card
.
Name
.
contains
(
cardInfo
.
Name
)
||
card
.
Desc
.
contains
(
cardInfo
.
Name
)))
{
matchingCards
.
add
(
card
);
continue
;
// 如果名称或描述匹配,则跳过系列代码检查
}
// 获取卡片的系列代码并检查是否有相同的系列代码
for
(
long
setCode
:
card
.
getSetCode
())
{
if
(
cardInfoSetCodes
.
contains
(
setCode
))
{
matchingCards
.
add
(
card
);
break
;
// 如果已经找到匹配,可以跳出内层循环
}
}
}
}
// 日志输出匹配的卡片数量
Log
.
w
(
"cc related cards"
,
"Found "
+
matchingCards
.
size
()
+
" related cards."
);
// 确保 matchingCards 不为空时调用 onSearchResult
if
(!
matchingCards
.
isEmpty
())
{
onSearchResult
(
mCardLoader
.
sort
(
matchingCards
),
false
);
//为了整齐需要,调用CardLoader的sort方法排序List<Card>
private
void
showCardList
(
List
<
Card
>
cardList
,
boolean
sort
)
{
if
(!
cardList
.
isEmpty
())
{
onSearchResult
(
sort
?
mCardLoader
.
sort
(
cardList
)
:
cardList
,
false
);
//根据情况不同,判断是否调用CardLoader的sort方法排序List<Card>
}
else
{
Log
.
w
(
"cc"
,
"No related card found"
);
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerFragment.java
View file @
7cbd2914
...
...
@@ -572,8 +572,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
}
@Override
public
void
onGetRelatedCardList
(
Card
cardInfo
)
{
getRelatedCardList
(
cardInfo
);
public
void
onGetRelatedCardList
(
List
<
Card
>
cardList
)
{
showCardList
(
cardList
,
true
);
}
@Override
...
...
@@ -629,45 +629,9 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
mCardLoader
.
search
(
searchInfo
);
}
private
void
getRelatedCardList
(
Card
cardInfo
)
{
SparseArray
<
Card
>
cards
=
mCardManager
.
getAllCards
();
// 使用 ArrayList 来保存匹配的卡片
List
<
Card
>
matchingCards
=
new
ArrayList
<>();
// 将 cardInfo 的 setCode 转换为 List<Long>
List
<
Long
>
cardInfoSetCodes
=
new
ArrayList
<>();
for
(
long
setCode
:
cardInfo
.
getSetCode
())
{
if
(
setCode
!=
0
)
cardInfoSetCodes
.
add
(
setCode
);
}
Log
.
w
(
"cc cardInfoSetCodes"
,
cardInfoSetCodes
.
toString
());
for
(
int
i
=
0
;
i
<
cards
.
size
();
i
++)
{
Card
card
=
cards
.
valueAt
(
i
);
// 检查卡片是否已经存在于匹配列表中
if
(!
matchingCards
.
contains
(
card
))
{
// 检查卡片名或描述是否包含给定卡片的名字
if
(!
card
.
Name
.
equals
(
cardInfo
.
Name
)
&&
(
card
.
Name
.
contains
(
cardInfo
.
Name
)
||
card
.
Desc
.
contains
(
cardInfo
.
Name
)))
{
matchingCards
.
add
(
card
);
continue
;
// 如果名称或描述匹配,则跳过系列代码检查
}
// 获取卡片的系列代码并检查是否有相同的系列代码
for
(
long
setCode
:
card
.
getSetCode
())
{
if
(
cardInfoSetCodes
.
contains
(
setCode
))
{
matchingCards
.
add
(
card
);
break
;
// 如果已经找到匹配,可以跳出内层循环
}
}
}
}
// 日志输出匹配的卡片数量
Log
.
w
(
"cc related cards"
,
"Found "
+
matchingCards
.
size
()
+
" related cards."
);
// 确保 matchingCards 不为空时调用 onSearchResult
if
(!
matchingCards
.
isEmpty
())
{
onSearchResult
(
matchingCards
,
false
);
private
void
showCardList
(
List
<
Card
>
cardList
,
boolean
sort
)
{
if
(!
cardList
.
isEmpty
())
{
onSearchResult
(
sort
?
mCardLoader
.
sort
(
cardList
)
:
cardList
,
false
);
//根据情况不同,判断是否调用CardLoader的sort方法排序List<Card>
}
else
{
Log
.
w
(
"cc"
,
"No related card found"
);
}
...
...
mobile/src/main/res/layout/dialog_cardinfo.xml
View file @
7cbd2914
...
...
@@ -92,24 +92,39 @@
app:srcCompat=
"@drawable/ic_close_black_24dp"
/>
</LinearLayout>
<
cn.garymb.ygomobile.ui.widget.AlwaysMarqueeTextView
android:id=
"@+id/
text
_name"
<
LinearLayout
android:id=
"@+id/
ll
_name"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"5dp"
android:gravity=
"center_vertical"
android:maxLines=
"1"
android:minHeight=
"@dimen/label_height"
android:paddingLeft=
"4dp"
android:shadowColor=
"@color/black"
android:shadowDx=
"1"
android:shadowDy=
"2"
android:shadowRadius=
"2"
android:singleLine=
"true"
android:textAppearance=
"@style/TextAppearance.AppCompat.Title"
android:textColor=
"@color/item_title"
android:textIsSelectable=
"true"
tools:text=
"name"
/>
android:orientation=
"horizontal"
>
<cn.garymb.ygomobile.ui.widget.AlwaysMarqueeTextView
android:id=
"@+id/text_name"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"5dp"
android:gravity=
"center_vertical"
android:maxLines=
"1"
android:minHeight=
"@dimen/label_height"
android:paddingLeft=
"4dp"
android:shadowColor=
"@color/black"
android:shadowDx=
"1"
android:shadowDy=
"2"
android:shadowRadius=
"2"
android:singleLine=
"true"
android:textAppearance=
"@style/TextAppearance.AppCompat.Title"
android:textColor=
"@color/item_title"
android:textIsSelectable=
"true"
tools:text=
"name"
/>
<TextView
android:id=
"@+id/relatable"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"☆"
android:visibility=
"gone"
/>
</LinearLayout>
<LinearLayout
android:layout_width=
"match_parent"
...
...
@@ -206,7 +221,7 @@
<ImageView
android:layout_width=
"15dp"
android:layout_height=
"15dp"
android:src=
"@drawable/ic_search"
/>
android:src=
"@drawable/ic_search"
/>
</LinearLayout>
</LinearLayout>
...
...
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