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
52701420
Commit
52701420
authored
Jan 19, 2025
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
判断截取词的搜索结果是否唯一指向这张卡而区分高亮颜色
parent
123aaf1e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
19 deletions
+57
-19
mobile/src/main/java/cn/garymb/ygomobile/loader/CardLoader.java
.../src/main/java/cn/garymb/ygomobile/loader/CardLoader.java
+1
-1
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
...rc/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
+56
-18
No files found.
mobile/src/main/java/cn/garymb/ygomobile/loader/CardLoader.java
View file @
52701420
...
@@ -158,7 +158,7 @@ public class CardLoader implements ICardSearcher {
...
@@ -158,7 +158,7 @@ public class CardLoader implements ICardSearcher {
ArrayList
<
Card
>
noting
=
new
ArrayList
<
Card
>();
ArrayList
<
Card
>
noting
=
new
ArrayList
<
Card
>();
mCallBack
.
onSearchResult
(
noting
,
false
);
mCallBack
.
onSearchResult
(
noting
,
false
);
}
}
LogUtil
.
e
(
"
kk
"
,
"search"
,
e
);
LogUtil
.
e
(
"
cc
"
,
"search"
,
e
);
//wait.dismiss();
//wait.dismiss();
}).
done
((
tmp
)
->
{
}).
done
((
tmp
)
->
{
if
(
mCallBack
!=
null
)
{
if
(
mCallBack
!=
null
)
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
View file @
52701420
package
cn.garymb.ygomobile.ui.cards
;
package
cn.garymb.ygomobile.ui.cards
;
import
static
android
.
text
.
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
;
import
static
cn
.
garymb
.
ygomobile
.
core
.
IrrlichtBridge
.
ACTION_SHARE_FILE
;
import
static
cn
.
garymb
.
ygomobile
.
core
.
IrrlichtBridge
.
ACTION_SHARE_FILE
;
import
android.annotation.SuppressLint
;
import
android.annotation.SuppressLint
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.os.Handler
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.os.Message
;
import
android.graphics.Color
;
import
android.text.SpannableString
;
import
android.text.SpannableString
;
import
android.text.
style.ForegroundColorSpan
;
import
android.text.
TextPaint
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.text.method.LinkMovementMethod
;
import
android.text.style.ClickableSpan
;
import
android.text.style.ClickableSpan
;
import
android.text.style.ForegroundColorSpan
;
import
android.util.Log
;
import
android.util.Log
;
import
android.util.SparseArray
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.view.Window
;
import
android.view.Window
;
...
@@ -31,16 +33,14 @@ import com.bm.library.PhotoView;
...
@@ -31,16 +33,14 @@ import com.bm.library.PhotoView;
import
com.feihua.dialogutils.util.DialogUtils
;
import
com.feihua.dialogutils.util.DialogUtils
;
import
java.io.File
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Stack
;
import
java.util.Stack
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.loader.CardKeyWord
;
import
cn.garymb.ygomobile.loader.CardSearchInfo
;
import
cn.garymb.ygomobile.loader.ImageLoader
;
import
cn.garymb.ygomobile.loader.ImageLoader
;
import
cn.garymb.ygomobile.ui.activities.BaseActivity
;
import
cn.garymb.ygomobile.ui.activities.BaseActivity
;
import
cn.garymb.ygomobile.ui.adapters.BaseAdapterPlus
;
import
cn.garymb.ygomobile.ui.adapters.BaseAdapterPlus
;
...
@@ -231,7 +231,6 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
...
@@ -231,7 +231,6 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
});
});
}
}
public
void
toggleAnimation
(
ShimmerTextView
target
)
{
public
void
toggleAnimation
(
ShimmerTextView
target
)
{
if
(
shimmer
!=
null
&&
shimmer
.
isAnimating
())
{
if
(
shimmer
!=
null
&&
shimmer
.
isAnimating
())
{
shimmer
.
cancel
();
shimmer
.
cancel
();
...
@@ -332,7 +331,9 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
...
@@ -332,7 +331,9 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
}
else
if
(
c
==
'」'
&&
!
stack
.
isEmpty
())
{
}
else
if
(
c
==
'」'
&&
!
stack
.
isEmpty
())
{
stack
.
pop
();
stack
.
pop
();
if
(
stack
.
isEmpty
())
{
if
(
stack
.
isEmpty
())
{
applySpan
(
spannableString
,
start
,
i
,
YGOUtil
.
c
(
R
.
color
.
holo_blue_bright
));
String
quotedText
=
text
.
substring
(
start
,
i
).
trim
();
// 使用 queryable 方法判断是否高亮
applySpan
(
spannableString
,
start
,
i
,
queryable
(
quotedText
)?
YGOUtil
.
c
(
R
.
color
.
holo_blue_bright
)
:
Color
.
WHITE
);
currentQuoteType
=
QuoteType
.
NONE
;
currentQuoteType
=
QuoteType
.
NONE
;
}
}
}
}
...
@@ -342,7 +343,10 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
...
@@ -342,7 +343,10 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
if
(
c
==
'"'
&&
!
stack
.
isEmpty
())
{
if
(
c
==
'"'
&&
!
stack
.
isEmpty
())
{
stack
.
pop
();
stack
.
pop
();
if
(
stack
.
isEmpty
())
{
if
(
stack
.
isEmpty
())
{
applySpan
(
spannableString
,
start
,
i
,
YGOUtil
.
c
(
R
.
color
.
holo_blue_bright
));
String
quotedText
=
text
.
substring
(
start
,
i
).
trim
();
if
(
queryable
(
quotedText
))
{
// 使用 queryable 方法判断是否高亮
applySpan
(
spannableString
,
start
,
i
,
queryable
(
quotedText
)?
YGOUtil
.
c
(
R
.
color
.
holo_blue_bright
)
:
Color
.
WHITE
);
}
currentQuoteType
=
QuoteType
.
NONE
;
currentQuoteType
=
QuoteType
.
NONE
;
}
else
{
}
else
{
stack
.
push
(
i
);
stack
.
push
(
i
);
...
@@ -357,7 +361,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
...
@@ -357,7 +361,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
// Handle unclosed quotes error, e.g., log a warning or throw an exception
// Handle unclosed quotes error, e.g., log a warning or throw an exception
}
}
desc
.
setText
(
spannableString
);
desc
.
setText
(
spannableString
);
desc
.
setMovementMethod
(
android
.
text
.
method
.
LinkMovementMethod
.
getInstance
());
desc
.
setMovementMethod
(
LinkMovementMethod
.
getInstance
());
}
}
private
void
applySpan
(
SpannableString
spannableString
,
int
start
,
int
end
,
int
color
)
{
private
void
applySpan
(
SpannableString
spannableString
,
int
start
,
int
end
,
int
color
)
{
...
@@ -367,25 +371,58 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
...
@@ -367,25 +371,58 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
spannableString
.
setSpan
(
new
ClickableSpan
()
{
spannableString
.
setSpan
(
new
ClickableSpan
()
{
@Override
@Override
public
void
onClick
(
View
widget
)
{
public
void
onClick
(
View
widget
)
{
// 获取被点击的文本内容
if
(
color
!=
Color
.
WHITE
)
{
String
clickedText
=
((
TextView
)
widget
).
getText
().
subSequence
(
start
,
end
).
toString
();
// 获取被点击的文本内容
mListener
.
onSearchKeyWord
(
clickedText
);
String
clickedText
=
((
TextView
)
widget
).
getText
().
subSequence
(
start
,
end
).
toString
();
mListener
.
onSearchKeyWord
(
clickedText
);
}
else
{
YGOUtil
.
showTextToast
(
context
.
getString
(
R
.
string
.
searchresult
)
+
context
.
getString
(
R
.
string
.
already_end
));
}
}
}
@Override
@Override
public
void
updateDrawState
(
android
.
text
.
TextPaint
ds
)
{
public
void
updateDrawState
(
TextPaint
ds
)
{
// 可以在这里自定义点击状态下的样式,如去掉下划线
// 可以在这里自定义点击状态下的样式,如去掉下划线
ds
.
setUnderlineText
(
true
);
ds
.
setUnderlineText
(
true
);
}
}
},
start
,
end
,
SpannableString
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
},
start
,
end
,
SpannableString
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
}
private
boolean
queryable
(
String
keyword
)
{
SparseArray
<
Card
>
cards
=
cardManager
.
getAllCards
();
//创建一个新的列表来保存匹配的卡片
List
<
Card
>
matchingCards
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
cards
.
size
();
i
++)
{
Card
card
=
cards
.
valueAt
(
i
);
if
(
card
.
Name
.
contains
(
keyword
)
||
card
.
Desc
.
contains
(
keyword
))
{
matchingCards
.
add
(
card
);
}
}
// 检查匹配结果
if
(
matchingCards
.
isEmpty
())
{
return
false
;
}
else
if
(
matchingCards
.
size
()
==
1
)
{
// 如果只有一个匹配项,检查是否是当前卡片
for
(
Card
card
:
matchingCards
)
{
if
(
getCardInfo
()
!=
null
&&
getCardInfo
().
equals
(
card
))
{
return
false
;
}
}
return
true
;
}
else
{
return
true
;
}
}
private
void
setCardInfo
(
Card
cardInfo
,
View
view
)
{
private
void
setCardInfo
(
Card
cardInfo
,
View
view
)
{
if
(
cardInfo
==
null
)
return
;
if
(
cardInfo
==
null
)
return
;
mCardInfo
=
cardInfo
;
mCardInfo
=
cardInfo
;
imageLoader
.
bindImage
(
cardImage
,
cardInfo
,
ImageLoader
.
Type
.
middle
);
imageLoader
.
bindImage
(
cardImage
,
cardInfo
,
ImageLoader
.
Type
.
middle
);
dialog
=
DialogUtils
.
getdx
(
context
);
dialog
=
DialogUtils
.
getdx
(
context
);
cardImage
.
setOnClickListener
((
v
)
->
{
showCardImageDetail
(
cardInfo
.
Code
);});
cardImage
.
setOnClickListener
((
v
)
->
{
showCardImageDetail
(
cardInfo
.
Code
);
});
packName
.
setText
(
packManager
.
findPackNameById
(
cardInfo
.
Alias
!=
0
?
cardInfo
.
Alias
:
cardInfo
.
Code
));
packName
.
setText
(
packManager
.
findPackNameById
(
cardInfo
.
Alias
!=
0
?
cardInfo
.
Alias
:
cardInfo
.
Code
));
name
.
setText
(
cardInfo
.
Name
);
name
.
setText
(
cardInfo
.
Name
);
setHighlightTextWithClickableSpans
(
cardInfo
.
Name
.
equals
(
"Unknown"
)
?
context
.
getString
(
R
.
string
.
tip_card_info_diff
)
:
cardInfo
.
Desc
);
setHighlightTextWithClickableSpans
(
cardInfo
.
Name
.
equals
(
"Unknown"
)
?
context
.
getString
(
R
.
string
.
tip_card_info_diff
)
:
cardInfo
.
Desc
);
...
@@ -658,6 +695,9 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
...
@@ -658,6 +695,9 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
}
}
}
}
// 定义引号类型
private
enum
QuoteType
{
NONE
,
DOUBLE_QUOTE
,
ANGLE_QUOTE
}
public
interface
OnFavoriteChangedListener
{
public
interface
OnFavoriteChangedListener
{
void
onFavoriteChange
(
Card
card
,
boolean
favorite
);
void
onFavoriteChange
(
Card
card
,
boolean
favorite
);
}
}
...
@@ -717,6 +757,4 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
...
@@ -717,6 +757,4 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
}
}
}
}
// 定义引号类型
enum
QuoteType
{
NONE
,
DOUBLE_QUOTE
,
ANGLE_QUOTE
}
}
}
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