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
53c30ec3
Commit
53c30ec3
authored
Sep 10, 2021
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
移除不使用的卡组编辑
parent
712747e2
Changes
33
Show whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
1553 additions
and
3956 deletions
+1553
-3956
mobile/src/main/java/cn/garymb/ygomobile/loader/ICardSearcher.java
...c/main/java/cn/garymb/ygomobile/loader/ICardSearcher.java
+13
-0
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/DebugActivity.java
...java/cn/garymb/ygomobile/ui/activities/DebugActivity.java
+0
-33
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/LogoActivity.java
.../java/cn/garymb/ygomobile/ui/activities/LogoActivity.java
+3
-1
mobile/src/main/java/cn/garymb/ygomobile/ui/adapters/CardListAdapter.java
...java/cn/garymb/ygomobile/ui/adapters/CardListAdapter.java
+3
-5
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/BaseCardsActivity.java
.../java/cn/garymb/ygomobile/ui/cards/BaseCardsActivity.java
+66
-101
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
...rc/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
+65
-119
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardSearchAcitivity.java
...ava/cn/garymb/ygomobile/ui/cards/CardSearchAcitivity.java
+0
-5
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardSearchActivity.java
...java/cn/garymb/ygomobile/ui/cards/CardSearchActivity.java
+49
-74
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardSearcher.java
.../main/java/cn/garymb/ygomobile/ui/cards/CardSearcher.java
+151
-166
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivity.java
...ava/cn/garymb/ygomobile/ui/cards/DeckManagerActivity.java
+1167
-5
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivity2.java
...va/cn/garymb/ygomobile/ui/cards/DeckManagerActivity2.java
+0
-5
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivity3.java
...va/cn/garymb/ygomobile/ui/cards/DeckManagerActivity3.java
+0
-158
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivityImpl.java
...cn/garymb/ygomobile/ui/cards/DeckManagerActivityImpl.java
+0
-1236
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivityImpl2.java
...n/garymb/ygomobile/ui/cards/DeckManagerActivityImpl2.java
+0
-727
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck/DeckAdapater.java
.../java/cn/garymb/ygomobile/ui/cards/deck/DeckAdapater.java
+1
-1
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck/DeckAdapater2.java
...java/cn/garymb/ygomobile/ui/cards/deck/DeckAdapater2.java
+0
-155
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck/DeckLayoutManager2.java
...cn/garymb/ygomobile/ui/cards/deck/DeckLayoutManager2.java
+0
-25
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/DeckAdapter.java
.../java/cn/garymb/ygomobile/ui/cards/deck2/DeckAdapter.java
+0
-410
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/DeckHelperCallback.java
...n/garymb/ygomobile/ui/cards/deck2/DeckHelperCallback.java
+0
-44
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/DeckItemDecoration.java
...n/garymb/ygomobile/ui/cards/deck2/DeckItemDecoration.java
+0
-60
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/DeckLayoutManager.java
...cn/garymb/ygomobile/ui/cards/deck2/DeckLayoutManager.java
+0
-36
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/DeckViewHolder.java
...va/cn/garymb/ygomobile/ui/cards/deck2/DeckViewHolder.java
+0
-131
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/IDeckLayout.java
.../java/cn/garymb/ygomobile/ui/cards/deck2/IDeckLayout.java
+0
-41
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
...c/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
+19
-27
mobile/src/main/java/cn/garymb/ygomobile/ui/home/MainActivity.java
...c/main/java/cn/garymb/ygomobile/ui/home/MainActivity.java
+3
-10
mobile/src/main/java/cn/garymb/ygomobile/ui/home/ResCheckTask.java
...c/main/java/cn/garymb/ygomobile/ui/home/ResCheckTask.java
+2
-3
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/fragments/SettingFragment.java
...mb/ygomobile/ui/preference/fragments/SettingFragment.java
+0
-2
mobile/src/main/java/com/ourygo/assistant/service/DuelAssistantService.java
...va/com/ourygo/assistant/service/DuelAssistantService.java
+5
-11
mobile/src/main/java/ocgcore/ConfigManager.java
mobile/src/main/java/ocgcore/ConfigManager.java
+0
-120
mobile/src/main/res/color/selector_text_color_white_gold.xml
mobile/src/main/res/color/selector_text_color_white_gold.xml
+5
-0
mobile/src/main/res/layout/activity_deck_cards2.xml
mobile/src/main/res/layout/activity_deck_cards2.xml
+0
-137
mobile/src/main/res/layout/activity_deck_cards3.xml
mobile/src/main/res/layout/activity_deck_cards3.xml
+0
-108
mobile/src/main/res/layout/nav_card_search.xml
mobile/src/main/res/layout/nav_card_search.xml
+1
-0
No files found.
mobile/src/main/java/cn/garymb/ygomobile/loader/ICardSearcher.java
0 → 100644
View file @
53c30ec3
package
cn.garymb.ygomobile.loader
;
import
ocgcore.data.LimitList
;
public
interface
ICardSearcher
extends
ICardLoader
{
void
search
(
String
prefixWord
,
String
suffixWord
,
long
attribute
,
long
level
,
long
race
,
String
limitName
,
long
limit
,
String
atk
,
String
def
,
long
pscale
,
long
setcode
,
long
category
,
long
ot
,
int
link
,
long
...
types
);
void
onReset
();
void
setLimitList
(
LimitList
limit
);
LimitList
getLimitList
();
}
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/DebugActivity.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.activities
;
import
android.os.Bundle
;
import
androidx.annotation.Nullable
;
import
androidx.appcompat.widget.Toolbar
;
import
androidx.recyclerview.widget.RecyclerView
;
import
cn.garymb.ygomobile.lite.R
;
public
class
DebugActivity
extends
BaseActivity
{
private
RecyclerView
rv_list
;
private
Toolbar
toolbar
;
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
debug_activity
);
initView
();
}
private
void
initView
()
{
rv_list
=
$
(
R
.
id
.
rv_list
);
toolbar
=
$
(
R
.
id
.
toolbar
);
setSupportActionBar
(
toolbar
);
enableBackHome
();
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/activities/LogoActivity.java
View file @
53c30ec3
...
...
@@ -27,6 +27,9 @@ public class LogoActivity extends Activity {
finish
();
return
;
}
else
{
// File file = new File(AppsSettings.get().getDeckDir(), "1.ydk");
// Uri uri = FileUtils.toUri(this, file);
// Log.w("kk-test", file.getAbsolutePath() + "->" + uri);
handler
=
new
Handler
();
runnable
=
new
Runnable
()
{
@Override
...
...
@@ -40,7 +43,6 @@ public class LogoActivity extends Activity {
}
if
(!
isTaskRoot
())
{
finish
();
return
;
}
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/adapters/CardListAdapter.java
View file @
53c30ec3
package
cn.garymb.ygomobile.ui.adapters
;
import
android.content.Context
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.ImageView
;
...
...
@@ -32,7 +31,6 @@ public class CardListAdapter extends BaseRecyclerAdapterPlus<Card, ViewHolder> i
private
boolean
mItemBg
;
private
ImageLoader
imageLoader
;
private
boolean
mEnableSwipe
=
false
;
private
BaseActivity
mContext
;
public
CardListAdapter
(
Context
context
,
ImageLoader
imageLoader
)
{
super
(
context
);
...
...
@@ -103,10 +101,10 @@ public class CardListAdapter extends BaseRecyclerAdapterPlus<Card, ViewHolder> i
@Override
public
void
onBindViewHolder
(
ViewHolder
holder
,
int
position
)
{
Log
.
e
(
"Cardlist"
,
"num"
+
position
);
Card
item
=
getItem
(
position
);
if
(
item
==
null
)
if
(
item
==
null
){
return
;
}
imageLoader
.
bindImage
(
holder
.
cardImage
,
item
.
Code
);
holder
.
cardName
.
setText
(
item
.
Name
);
if
(
item
.
isType
(
CardType
.
Monster
))
{
...
...
@@ -126,7 +124,7 @@ public class CardListAdapter extends BaseRecyclerAdapterPlus<Card, ViewHolder> i
}
if
(
item
.
isType
(
CardType
.
Pendulum
))
{
holder
.
layout_p_scale
.
setVisibility
(
View
.
VISIBLE
);
holder
.
cardScale
.
setText
(
String
.
valueOf
(
item
.
LScale
));
holder
.
cardScale
.
setText
(
String
.
valueOf
(
item
.
L
eft
Scale
));
}
else
{
holder
.
layout_p_scale
.
setVisibility
(
View
.
GONE
);
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/BaseCardsAc
i
tivity.java
→
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/BaseCardsActivity.java
View file @
53c30ec3
package
cn.garymb.ygomobile.ui.cards
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.DashPathEffect
;
import
android.graphics.Paint
;
...
...
@@ -12,6 +11,7 @@ import android.view.animation.Animation;
import
android.view.animation.AnimationUtils
;
import
android.widget.TextView
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.appcompat.widget.RecyclerViewItemListener
;
import
androidx.drawerlayout.widget.DrawerLayout
;
...
...
@@ -19,9 +19,6 @@ import androidx.recyclerview.widget.FastScrollLinearLayoutManager;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.app.hubert.guide.NewbieGuide
;
import
com.app.hubert.guide.core.Controller
;
import
com.app.hubert.guide.listener.OnHighlightDrewListener
;
import
com.app.hubert.guide.listener.OnLayoutInflatedListener
;
import
com.app.hubert.guide.model.GuidePage
;
import
com.app.hubert.guide.model.HighLight
;
import
com.app.hubert.guide.model.HighlightOptions
;
...
...
@@ -41,11 +38,11 @@ import ocgcore.LimitManager;
import
ocgcore.StringManager
;
import
ocgcore.data.Card
;
public
abstract
class
BaseCardsAc
i
tivity
extends
BaseActivity
implements
CardLoader
.
CallBack
,
CardSearcher
.
CallBack
{
protected
DrawerLayout
mDrawer
l
ayout
;
public
abstract
class
BaseCardsActivity
extends
BaseActivity
implements
CardLoader
.
CallBack
,
CardSearcher
.
CallBack
{
protected
DrawerLayout
mDrawer
L
ayout
;
protected
RecyclerView
mListView
;
protected
CardSearcher
mCardSelector
;
protected
CardListAdapter
mCardListAdap
a
ter
;
protected
CardListAdapter
mCardListAdapter
;
protected
CardLoader
mCardLoader
;
protected
boolean
isLoad
=
false
;
private
ImageLoader
mImageLoader
;
...
...
@@ -59,13 +56,13 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
setContentView
(
R
.
layout
.
activity_deck_cards
);
AnimationShake2
();
mImageLoader
=
ImageLoader
.
get
(
this
);
mDrawer
l
ayout
=
$
(
R
.
id
.
drawer_layout
);
mDrawer
L
ayout
=
$
(
R
.
id
.
drawer_layout
);
screenWidth
=
getResources
().
getDisplayMetrics
().
widthPixels
;
mListView
=
$
(
R
.
id
.
list_cards
);
mCardListAdap
a
ter
=
new
CardListAdapter
(
this
,
mImageLoader
);
mCardListAdap
a
ter
.
setEnableSwipe
(
true
);
mCardListAdapter
=
new
CardListAdapter
(
this
,
mImageLoader
);
mCardListAdapter
.
setEnableSwipe
(
true
);
mListView
.
setLayoutManager
(
new
FastScrollLinearLayoutManager
(
this
));
mListView
.
setAdapter
(
mCardListAdap
a
ter
);
mListView
.
setAdapter
(
mCardListAdapter
);
setListeners
();
mCardLoader
=
new
CardLoader
(
this
);
...
...
@@ -78,28 +75,22 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
//https://www.jianshu.com/p/99649af3b191
public
void
showNewbieGuide
(
String
scene
)
{
HighlightOptions
options
=
new
HighlightOptions
.
Builder
()
//绘制一个高亮虚线圈
.
setOnHighlightDrewListener
(
new
OnHighlightDrewListener
()
{
@Override
public
void
onHighlightDrew
(
Canvas
canvas
,
RectF
rectF
)
{
.
setOnHighlightDrewListener
((
canvas
,
rectF
)
->
{
Paint
paint
=
new
Paint
();
paint
.
setColor
(
Color
.
WHITE
);
paint
.
setStyle
(
Paint
.
Style
.
STROKE
);
paint
.
setStrokeWidth
(
20
);
paint
.
setPathEffect
(
new
DashPathEffect
(
new
float
[]{
20
,
20
},
0
));
canvas
.
drawCircle
(
rectF
.
centerX
(),
rectF
.
centerY
(),
rectF
.
width
()
/
2
+
10
,
paint
);
}
}).
build
();
HighlightOptions
options2
=
new
HighlightOptions
.
Builder
()
//绘制一个高亮虚线矩形
.
setOnHighlightDrewListener
(
new
OnHighlightDrewListener
()
{
@Override
public
void
onHighlightDrew
(
Canvas
canvas
,
RectF
rectF
)
{
.
setOnHighlightDrewListener
((
canvas
,
rectF
)
->
{
Paint
paint
=
new
Paint
();
paint
.
setColor
(
Color
.
WHITE
);
paint
.
setStyle
(
Paint
.
Style
.
STROKE
);
paint
.
setStrokeWidth
(
20
);
paint
.
setPathEffect
(
new
DashPathEffect
(
new
float
[]{
20
,
20
},
0
));
canvas
.
drawRect
(
rectF
,
paint
);
}
}).
build
();
if
(
scene
.
equals
(
"deckmain"
))
{
NewbieGuide
.
with
(
this
)
//with方法可以传入Activity或者Fragment,获取引导页的依附者
...
...
@@ -109,13 +100,9 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
.
setBackgroundColor
(
0xbc000000
)
.
addHighLightWithOptions
(
findViewById
(
R
.
id
.
deck_menu
),
HighLight
.
Shape
.
CIRCLE
,
options
)
.
setLayoutRes
(
R
.
layout
.
view_guide_home
)
.
setOnLayoutInflatedListener
(
new
OnLayoutInflatedListener
()
{
@Override
public
void
onLayoutInflated
(
View
view
,
Controller
controller
)
{
.
setOnLayoutInflatedListener
((
view
,
controller
)
->
{
//可只创建一个引导layout并把相关内容都放在其中并GONE,获得ID并初始化相应为显示
view
.
findViewById
(
R
.
id
.
view_abt_bmb
).
setVisibility
(
View
.
VISIBLE
);
}
})
)
...
...
@@ -124,14 +111,10 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
.
setBackgroundColor
(
0xbc000000
)
.
addHighLightWithOptions
(
findViewById
(
R
.
id
.
nav_search
),
HighLight
.
Shape
.
CIRCLE
,
options
)
.
setLayoutRes
(
R
.
layout
.
view_guide_home
)
.
setOnLayoutInflatedListener
(
new
OnLayoutInflatedListener
()
{
@Override
public
void
onLayoutInflated
(
View
view
,
Controller
controller
)
{
.
setOnLayoutInflatedListener
((
view
,
controller
)
->
{
TextView
tv
=
view
.
findViewById
(
R
.
id
.
text_about
);
tv
.
setVisibility
(
View
.
VISIBLE
);
tv
.
setText
(
R
.
string
.
guide_button_search
);
}
})
)
.
addGuidePage
(
...
...
@@ -139,14 +122,10 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
.
setBackgroundColor
(
0xbc000000
)
.
addHighLightWithOptions
(
findViewById
(
R
.
id
.
nav_list
),
HighLight
.
Shape
.
CIRCLE
,
options
)
.
setLayoutRes
(
R
.
layout
.
view_guide_home
)
.
setOnLayoutInflatedListener
(
new
OnLayoutInflatedListener
()
{
@Override
public
void
onLayoutInflated
(
View
view
,
Controller
controller
)
{
.
setOnLayoutInflatedListener
((
view
,
controller
)
->
{
TextView
tv
=
view
.
findViewById
(
R
.
id
.
text_about
);
tv
.
setVisibility
(
View
.
VISIBLE
);
tv
.
setText
(
R
.
string
.
guide_button_search_result
);
}
})
)
.
addGuidePage
(
...
...
@@ -154,30 +133,22 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
.
setBackgroundColor
(
0xbc000000
)
.
addHighLightWithOptions
(
findViewById
(
R
.
id
.
tv_deckmanger
),
HighLight
.
Shape
.
CIRCLE
,
options2
)
.
setLayoutRes
(
R
.
layout
.
view_guide_home
)
.
setOnLayoutInflatedListener
(
new
OnLayoutInflatedListener
()
{
@Override
public
void
onLayoutInflated
(
View
view
,
Controller
controller
)
{
.
setOnLayoutInflatedListener
((
view
,
controller
)
->
{
TextView
tv
=
view
.
findViewById
(
R
.
id
.
text_about
);
tv
.
setVisibility
(
View
.
VISIBLE
);
tv
.
setText
(
R
.
string
.
guide_view_deck_manager
);
}
})
)
.
addGuidePage
(
GuidePage
.
newInstance
().
setEverywhereCancelable
(
true
)
.
setBackgroundColor
(
0xbc000000
)
.
addHighLightWithOptions
(
new
RectF
(
screenWidth
/
10
,
screenWidth
/
20
,
screenWidth
/
5
,
screenWidth
/
20
+
screenWidth
/
10
*
254
/
177
),
HighLight
.
Shape
.
RECTANGLE
,
options2
)
.
addHighLightWithOptions
(
new
RectF
(
screenWidth
/
10
.0f
,
screenWidth
/
20.0f
,
screenWidth
/
5.0f
,
screenWidth
/
20.0f
+
screenWidth
/
10.0f
*
254.0f
/
177.0f
),
HighLight
.
Shape
.
RECTANGLE
,
options2
)
.
setLayoutRes
(
R
.
layout
.
view_guide_home
)
.
setOnLayoutInflatedListener
(
new
OnLayoutInflatedListener
()
{
@Override
public
void
onLayoutInflated
(
View
view
,
Controller
controller
)
{
.
setOnLayoutInflatedListener
((
view
,
controller
)
->
{
TextView
tv
=
view
.
findViewById
(
R
.
id
.
text_abt_mid
);
tv
.
setVisibility
(
View
.
VISIBLE
);
tv
.
setText
(
R
.
string
.
guide_view_move_card
);
}
})
)
//.alwaysShow(true)//总是显示,调试时可以打开
...
...
@@ -186,20 +157,16 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
}
}
protected
int
getDimen
(
int
id
)
{
return
(
int
)
getResources
().
getDimension
(
id
);
}
protected
void
setListeners
()
{
mListView
.
addOnItemTouchListener
(
new
RecyclerViewItemListener
(
mListView
,
new
RecyclerViewItemListener
.
OnItemListener
()
{
@Override
public
void
onItemClick
(
View
view
,
int
pos
)
{
onCardClick
(
view
,
mCardListAdap
a
ter
.
getItem
(
pos
),
pos
);
onCardClick
(
view
,
mCardListAdapter
.
getItem
(
pos
),
pos
);
}
@Override
public
void
onItemLongClick
(
View
view
,
int
pos
)
{
onCardLongClick
(
view
,
mCardListAdap
a
ter
.
getItem
(
pos
),
pos
);
onCardLongClick
(
view
,
mCardListAdapter
.
getItem
(
pos
),
pos
);
}
@Override
...
...
@@ -209,18 +176,16 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
}));
mListView
.
addOnScrollListener
(
new
RecyclerView
.
OnScrollListener
()
{
@Override
public
void
onScrollStateChanged
(
RecyclerView
recyclerView
,
int
newState
)
{
public
void
onScrollStateChanged
(
@NonNull
RecyclerView
recyclerView
,
int
newState
)
{
super
.
onScrollStateChanged
(
recyclerView
,
newState
);
switch
(
newState
)
{
case
RecyclerView
.
SCROLL_STATE_IDLE
:
case
RecyclerView
.
SCROLL_STATE_SETTLING
:
Glide
.
with
(
getContext
()).
resumeRequests
();
break
;
case
RecyclerView
.
SCROLL_STATE_DRAGGING
:
Glide
.
with
(
getContext
()).
pauseRequests
();
break
;
case
RecyclerView
.
SCROLL_STATE_SETTLING
:
Glide
.
with
(
getContext
()).
resumeRequests
();
break
;
}
}
});
...
...
@@ -232,12 +197,12 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
@Override
protected
void
onBackHome
()
{
if
(
mDrawer
l
ayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawer
l
ayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
if
(
mDrawer
L
ayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawer
L
ayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
return
;
}
if
(
mDrawer
l
ayout
.
isDrawerOpen
(
Gravity
.
LEFT
))
{
mDrawer
l
ayout
.
closeDrawer
(
Gravity
.
LEFT
);
if
(
mDrawer
L
ayout
.
isDrawerOpen
(
Gravity
.
LEFT
))
{
mDrawer
L
ayout
.
closeDrawer
(
Gravity
.
LEFT
);
return
;
}
finish
();
...
...
@@ -245,8 +210,8 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
public
void
onSearchResult
(
List
<
Card
>
cardInfos
,
boolean
isHide
)
{
// Log.d("kk", "find " + (cardInfos == null ? -1 : cardInfos.size()));
mCardListAdap
a
ter
.
set
(
cardInfos
);
mCardListAdap
a
ter
.
notifyDataSetChanged
();
mCardListAdapter
.
set
(
cardInfos
);
mCardListAdapter
.
notifyDataSetChanged
();
if
(
cardInfos
!=
null
&&
cardInfos
.
size
()
>
0
)
{
mListView
.
smoothScrollToPosition
(
0
);
}
...
...
@@ -274,11 +239,11 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
}
protected
void
hideDrawers
()
{
if
(
mDrawer
l
ayout
.
isDrawerOpen
(
Gravity
.
RIGHT
))
{
mDrawer
l
ayout
.
closeDrawer
(
Gravity
.
RIGHT
);
if
(
mDrawer
L
ayout
.
isDrawerOpen
(
Gravity
.
RIGHT
))
{
mDrawer
L
ayout
.
closeDrawer
(
Gravity
.
RIGHT
);
}
if
(
mDrawer
l
ayout
.
isDrawerOpen
(
Gravity
.
LEFT
))
{
mDrawer
l
ayout
.
closeDrawer
(
Gravity
.
LEFT
);
if
(
mDrawer
L
ayout
.
isDrawerOpen
(
Gravity
.
LEFT
))
{
mDrawer
L
ayout
.
closeDrawer
(
Gravity
.
LEFT
);
}
}
...
...
@@ -287,25 +252,25 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
protected
abstract
void
onCardLongClick
(
View
view
,
Card
cardInfo
,
int
pos
);
protected
void
showSearch
(
boolean
autoClose
)
{
if
(
mDrawer
l
ayout
.
isDrawerOpen
(
Constants
.
CARD_RESULT_GRAVITY
))
{
mDrawer
l
ayout
.
closeDrawer
(
Constants
.
CARD_RESULT_GRAVITY
);
if
(
mDrawer
L
ayout
.
isDrawerOpen
(
Constants
.
CARD_RESULT_GRAVITY
))
{
mDrawer
L
ayout
.
closeDrawer
(
Constants
.
CARD_RESULT_GRAVITY
);
}
if
(
autoClose
&&
mDrawer
l
ayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawer
l
ayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
if
(
autoClose
&&
mDrawer
L
ayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawer
L
ayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
}
else
if
(
isLoad
)
{
mDrawer
l
ayout
.
openDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
mDrawer
L
ayout
.
openDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
}
}
protected
void
showResult
(
boolean
autoClose
)
{
if
(
mDrawer
l
ayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawer
l
ayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
if
(
mDrawer
L
ayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawer
L
ayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
}
if
(
autoClose
&&
mDrawer
l
ayout
.
isDrawerOpen
(
Constants
.
CARD_RESULT_GRAVITY
))
{
mDrawer
l
ayout
.
closeDrawer
(
Constants
.
CARD_RESULT_GRAVITY
);
if
(
autoClose
&&
mDrawer
L
ayout
.
isDrawerOpen
(
Constants
.
CARD_RESULT_GRAVITY
))
{
mDrawer
L
ayout
.
closeDrawer
(
Constants
.
CARD_RESULT_GRAVITY
);
showNewbieGuide
(
"searchResult"
);
}
else
if
(
isLoad
)
{
mDrawer
l
ayout
.
openDrawer
(
Constants
.
CARD_RESULT_GRAVITY
);
mDrawer
L
ayout
.
openDrawer
(
Constants
.
CARD_RESULT_GRAVITY
);
}
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardDetail.java
View file @
53c30ec3
...
...
@@ -5,9 +5,6 @@ import android.content.Intent;
import
android.os.Handler
;
import
android.os.Message
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.util.SparseArray
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.Window
;
...
...
@@ -26,13 +23,11 @@ import com.bm.library.PhotoView;
import
com.feihua.dialogutils.util.DialogUtils
;
import
java.io.File
;
import
java.util.List
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.loader.CardLoader
;
import
cn.garymb.ygomobile.loader.ImageLoader
;
import
cn.garymb.ygomobile.ui.activities.BaseActivity
;
import
cn.garymb.ygomobile.ui.adapters.BaseAdapterPlus
;
...
...
@@ -41,15 +36,12 @@ import cn.garymb.ygomobile.utils.DownloadUtil;
import
cn.garymb.ygomobile.utils.FileUtils
;
import
cn.garymb.ygomobile.utils.YGOUtil
;
import
ocgcore.CardManager
;
import
ocgcore.ConfigManager
;
import
ocgcore.DataManager
;
import
ocgcore.StringManager
;
import
ocgcore.data.Card
;
import
ocgcore.enums.CardOt
;
import
ocgcore.enums.CardType
;
import
static
cn
.
garymb
.
ygomobile
.
core
.
IrrlichtBridge
.
ACTION_SHARE_FILE
;
import
static
cn
.
garymb
.
ygomobile
.
ui
.
cards
.
DeckManagerActivityImpl
.
Favorite
;
/***
* 卡片详情
...
...
@@ -61,34 +53,32 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
private
static
final
int
TYPE_DOWNLOAD_CARD_IMAGE_ING
=
2
;
private
static
final
String
TAG
=
"CardDetail"
;
private
static
CardManager
cardManager
;
private
ImageView
cardImage
;
private
TextView
name
;
private
TextView
desc
;
private
TextView
level
;
private
TextView
type
;
private
TextView
race
;
private
TextView
cardAtk
;
private
TextView
cardDef
;
private
TextView
setname
;
private
TextView
otView
;
private
TextView
attrView
;
private
View
monsterlayout
;
private
View
close
;
private
View
faq
;
private
View
addMain
;
private
View
addSide
;
private
View
linkArrow
;
private
View
layout_detail_p_scale
;
private
TextView
detail_cardscale
;
private
TextView
cardcode
;
private
View
lb_setcode
;
private
ImageLoader
imageLoader
;
private
View
mImageFav
,
atkdefView
;
private
BaseActivity
mContext
;
private
StringManager
mStringManager
;
private
final
CardManager
cardManager
;
private
final
ImageView
cardImage
;
private
final
TextView
name
;
private
final
TextView
desc
;
private
final
TextView
level
;
private
final
TextView
type
;
private
final
TextView
race
;
private
final
TextView
cardAtk
;
private
final
TextView
cardDef
;
private
final
TextView
setName
;
private
final
TextView
otView
;
private
final
TextView
attrView
;
private
final
View
monsterLayout
;
private
final
View
close
;
private
final
View
addMain
;
private
final
View
addSide
;
private
final
View
linkArrow
;
private
final
View
layoutDetailPScale
;
private
final
TextView
detailCardScale
;
private
final
TextView
cardCode
;
private
final
View
lbSetCode
;
private
final
ImageLoader
imageLoader
;
private
final
View
mImageFav
,
atkdefView
;
private
final
StringManager
mStringManager
;
private
int
curPosition
;
private
Card
mCardInfo
;
private
CardListProvider
mProvider
;
...
...
@@ -130,10 +120,11 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
}
}
};
private
CallBack
mCallBack
;
private
final
BaseActivity
mContext
;
private
OnFavoriteChangedListener
mCallBack
;
public
CardDetail
(
BaseActivity
context
,
ImageLoader
imageLoader
,
StringManager
stringManager
)
{
super
(
LayoutInflater
.
from
(
context
).
inflate
(
R
.
layout
.
dialog_cardinfo
,
null
));
super
(
context
.
getLayoutInflater
(
).
inflate
(
R
.
layout
.
dialog_cardinfo
,
null
));
mContext
=
context
;
cardImage
=
bind
(
R
.
id
.
card_image
);
this
.
imageLoader
=
imageLoader
;
...
...
@@ -141,33 +132,27 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
name
=
bind
(
R
.
id
.
text_name
);
desc
=
bind
(
R
.
id
.
text_desc
);
close
=
bind
(
R
.
id
.
btn_close
);
card
c
ode
=
bind
(
R
.
id
.
card_code
);
card
C
ode
=
bind
(
R
.
id
.
card_code
);
level
=
bind
(
R
.
id
.
card_level
);
linkArrow
=
bind
(
R
.
id
.
detail_link_arrows
);
type
=
bind
(
R
.
id
.
card_type
);
faq
=
bind
(
R
.
id
.
btn_faq
);
View
faq
=
bind
(
R
.
id
.
btn_faq
);
cardAtk
=
bind
(
R
.
id
.
card_atk
);
cardDef
=
bind
(
R
.
id
.
card_def
);
atkdefView
=
bind
(
R
.
id
.
layout_atkdef2
);
mImageFav
=
bind
(
R
.
id
.
image_fav
);
monster
l
ayout
=
bind
(
R
.
id
.
layout_monster
);
layout
_detail_p_s
cale
=
bind
(
R
.
id
.
detail_p_scale
);
detail
_cards
cale
=
bind
(
R
.
id
.
detail_cardscale
);
monster
L
ayout
=
bind
(
R
.
id
.
layout_monster
);
layout
DetailPS
cale
=
bind
(
R
.
id
.
detail_p_scale
);
detail
CardS
cale
=
bind
(
R
.
id
.
detail_cardscale
);
race
=
bind
(
R
.
id
.
card_race
);
set
n
ame
=
bind
(
R
.
id
.
card_setname
);
set
N
ame
=
bind
(
R
.
id
.
card_setname
);
addMain
=
bind
(
R
.
id
.
btn_add_main
);
addSide
=
bind
(
R
.
id
.
btn_add_side
);
otView
=
bind
(
R
.
id
.
card_ot
);
attrView
=
bind
(
R
.
id
.
card_attribute
);
lb_setcode
=
bind
(
R
.
id
.
label_setcode
);
if
(
cardManager
==
null
)
{
Log
.
e
(
"CardDetail"
,
"加载卡片信息"
);
cardManager
=
new
CardManager
(
AppsSettings
.
get
().
getDataBaseFile
().
getAbsolutePath
(),
null
);
//加载数据库中所有卡片卡片
cardManager
.
loadCards
();
}
lbSetCode
=
bind
(
R
.
id
.
label_setcode
);
cardManager
=
DataManager
.
get
().
getCardManager
();
close
.
setOnClickListener
((
v
)
->
{
if
(
mListener
!=
null
)
{
mListener
.
onClose
();
...
...
@@ -206,35 +191,20 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
bind
(
R
.
id
.
nextone
).
setOnClickListener
((
v
)
->
{
onNextCard
();
});
bind
(
R
.
id
.
image_fav
)
.
setOnClickListener
((
v
)
->
{
mImageFav
.
setOnClickListener
((
v
)
->
{
doMyFavorites
(
getCardInfo
());
});
}
/**
* 收藏卡片
*/
public
void
doMyFavorites
(
Card
cardInfo
)
{
CardLoader
mCardLoader
=
new
CardLoader
(
context
);
ConfigManager
favConf
=
DataManager
.
openConfig
(
AppsSettings
.
get
().
getSystemConfig
());
Integer
code
=
cardInfo
.
Code
;
if
(
favConf
.
mLines
.
contains
(
code
))
{
favConf
.
mLines
.
remove
(
code
);
mImageFav
.
setBackgroundResource
(
R
.
drawable
.
ic_control_point
);
}
else
{
favConf
.
mLines
.
add
(
0
,
code
);
mImageFav
.
setBackgroundResource
(
R
.
drawable
.
ic_fav
);
boolean
ret
=
CardFavorites
.
get
().
toggle
(
cardInfo
.
Code
);
mImageFav
.
setSelected
(
ret
);
if
(
mCallBack
!=
null
){
mCallBack
.
onFavoriteChange
(
cardInfo
,
ret
);
}
favConf
.
save
(
"#Favorite"
);
favConf
.
read
();
Favorite
.
clear
();
if
(!
DeckManagerActivityImpl
.
isSearchResult
)
{
SparseArray
<
Card
>
id
=
mCardLoader
.
readCards
(
ConfigManager
.
mLines
,
false
);
if
(
id
!=
null
)
{
for
(
int
i
=
0
;
i
<
id
.
size
();
i
++)
Favorite
.
add
(
id
.
valueAt
(
i
));
}
if
(
mCallBack
!=
null
)
mCallBack
.
onSearchResult
(
Favorite
,
true
);
}
}
public
ImageView
getCardImage
()
{
...
...
@@ -262,7 +232,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
mListener
=
listener
;
}
public
void
setCallBack
(
CallBack
callBack
)
{
public
void
setCallBack
(
OnFavoriteChangedListener
callBack
)
{
mCallBack
=
callBack
;
}
...
...
@@ -286,25 +256,8 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
return
mCardInfo
;
}
public
String
getOTSString
(
int
ot
)
{
String
str
=
""
;
if
(
ot
==
CardOt
.
OCG
.
ordinal
())
{
str
=
mContext
.
getString
(
R
.
string
.
label_ot_OCG
);
}
else
if
(
ot
==
CardOt
.
TCG
.
ordinal
())
{
str
=
mContext
.
getString
(
R
.
string
.
label_ot_TCG
);
}
else
if
(
ot
==
8
)
{
str
=
mContext
.
getString
(
R
.
string
.
label_ot_SC_OCG
);
}
else
if
(
ot
==
CardOt
.
CUSTOM
.
ordinal
())
{
str
=
mContext
.
getString
(
R
.
string
.
label_ot_CUSTOM
);
}
else
{
str
=
"OCG/TCG"
;
}
return
str
;
}
private
void
setCardInfo
(
Card
cardInfo
,
View
view
)
{
if
(
cardInfo
==
null
)
return
;
mCardInfo
=
cardInfo
;
imageLoader
.
bindImage
(
cardImage
,
cardInfo
.
Code
,
null
,
true
);
dialog
=
DialogUtils
.
getdx
(
context
);
...
...
@@ -315,46 +268,41 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
desc
.
setText
(
cardInfo
.
Desc
);
int
t
=
cardInfo
.
Alias
-
cardInfo
.
Code
;
if
(
t
>
10
||
t
<
-
10
)
{
card
c
ode
.
setText
(
String
.
format
(
"%08d"
,
cardInfo
.
Code
));
card
C
ode
.
setText
(
String
.
format
(
"%08d"
,
cardInfo
.
Code
));
}
else
{
card
c
ode
.
setText
(
String
.
format
(
"%08d"
,
cardInfo
.
Alias
));
card
C
ode
.
setText
(
String
.
format
(
"%08d"
,
cardInfo
.
Alias
));
}
//按是否存在于收藏夹切换显示图标
if
(
ConfigManager
.
mLines
.
contains
(
cardInfo
.
Code
))
{
mImageFav
.
setBackgroundResource
(
R
.
drawable
.
ic_fav
);
}
else
{
mImageFav
.
setBackgroundResource
(
R
.
drawable
.
ic_control_point
);
}
mImageFav
.
setSelected
(
CardFavorites
.
get
().
hasCard
(
cardInfo
.
Code
));
type
.
setText
(
CardUtils
.
getAllTypeString
(
cardInfo
,
mStringManager
).
replace
(
"/"
,
"|"
));
attrView
.
setText
(
mStringManager
.
getAttributeString
(
cardInfo
.
Attribute
));
otView
.
setText
(
getOTSString
(
cardInfo
.
Ot
));
//otView.setText(mStringManager.getOtString(cardInfo.Ot, "" + cardInfo.Ot));//暂时弃用
otView
.
setText
(
mStringManager
.
getOtString
(
cardInfo
.
Ot
,
true
));
long
[]
sets
=
cardInfo
.
getSetCode
();
set
n
ame
.
setText
(
""
);
set
N
ame
.
setText
(
""
);
int
index
=
0
;
for
(
long
set
:
sets
)
{
if
(
set
>
0
)
{
if
(
index
!=
0
)
{
set
n
ame
.
append
(
"\n"
);
set
N
ame
.
append
(
"\n"
);
}
set
n
ame
.
append
(
""
+
mStringManager
.
getSetName
(
set
));
set
N
ame
.
append
(
""
+
mStringManager
.
getSetName
(
set
));
index
++;
}
}
if
(
TextUtils
.
isEmpty
(
set
n
ame
.
getText
()))
{
set
n
ame
.
setVisibility
(
View
.
INVISIBLE
);
lb
_setc
ode
.
setVisibility
(
View
.
INVISIBLE
);
if
(
TextUtils
.
isEmpty
(
set
N
ame
.
getText
()))
{
set
N
ame
.
setVisibility
(
View
.
INVISIBLE
);
lb
SetC
ode
.
setVisibility
(
View
.
INVISIBLE
);
}
else
{
set
n
ame
.
setVisibility
(
View
.
VISIBLE
);
lb
_setc
ode
.
setVisibility
(
View
.
VISIBLE
);
set
N
ame
.
setVisibility
(
View
.
VISIBLE
);
lb
SetC
ode
.
setVisibility
(
View
.
VISIBLE
);
}
if
(
cardInfo
.
isType
(
CardType
.
Monster
))
{
atkdefView
.
setVisibility
(
View
.
VISIBLE
);
monster
l
ayout
.
setVisibility
(
View
.
VISIBLE
);
monster
L
ayout
.
setVisibility
(
View
.
VISIBLE
);
race
.
setVisibility
(
View
.
VISIBLE
);
String
star
=
"★"
+
cardInfo
.
getStar
();
/* for (int i = 0; i < cardInfo.getStar(); i++) {
...
...
@@ -367,10 +315,10 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
level
.
setTextColor
(
context
.
getResources
().
getColor
(
R
.
color
.
star
));
}
if
(
cardInfo
.
isType
(
CardType
.
Pendulum
))
{
layout
_detail_p_s
cale
.
setVisibility
(
View
.
VISIBLE
);
detail
_cardscale
.
setText
(
String
.
valueOf
(
cardInfo
.
L
Scale
));
layout
DetailPS
cale
.
setVisibility
(
View
.
VISIBLE
);
detail
CardScale
.
setText
(
String
.
valueOf
(
cardInfo
.
Left
Scale
));
}
else
{
layout
_detail_p_s
cale
.
setVisibility
(
View
.
GONE
);
layout
DetailPS
cale
.
setVisibility
(
View
.
GONE
);
}
cardAtk
.
setText
((
cardInfo
.
Attack
<
0
?
"?"
:
String
.
valueOf
(
cardInfo
.
Attack
)));
//连接怪兽设置
...
...
@@ -388,7 +336,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
}
else
{
atkdefView
.
setVisibility
(
View
.
GONE
);
race
.
setVisibility
(
View
.
GONE
);
monster
l
ayout
.
setVisibility
(
View
.
GONE
);
monster
L
ayout
.
setVisibility
(
View
.
GONE
);
level
.
setVisibility
(
View
.
GONE
);
linkArrow
.
setVisibility
(
View
.
GONE
);
}
...
...
@@ -569,10 +517,8 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
return
(
T
)
findViewById
(
id
);
}
public
interface
CallBack
{
void
onSearchStart
();
void
onSearchResult
(
List
<
Card
>
Cards
,
boolean
isHide
);
public
interface
OnFavoriteChangedListener
{
void
onFavoriteChange
(
Card
card
,
boolean
favorite
);
}
public
interface
OnCardClickListener
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardSearchAcitivity.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards
;
public
class
CardSearchAcitivity
extends
CardSearchActivityImpl
{
public
static
final
String
SEARCH_MESSAGE
=
"searchMessage"
;
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardSearchActivity
Impl
.java
→
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardSearchActivity.java
View file @
53c30ec3
package
cn.garymb.ygomobile.ui.cards
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.DashPathEffect
;
import
android.graphics.Paint
;
import
android.graphics.RectF
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
android.view.Gravity
;
...
...
@@ -15,6 +13,7 @@ import android.view.View;
import
android.widget.Button
;
import
android.widget.TextView
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.appcompat.widget.RecyclerViewItemListener
;
import
androidx.drawerlayout.widget.DrawerLayout
;
...
...
@@ -22,9 +21,6 @@ import androidx.recyclerview.widget.FastScrollLinearLayoutManager;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.app.hubert.guide.NewbieGuide
;
import
com.app.hubert.guide.core.Controller
;
import
com.app.hubert.guide.listener.OnHighlightDrewListener
;
import
com.app.hubert.guide.listener.OnLayoutInflatedListener
;
import
com.app.hubert.guide.model.GuidePage
;
import
com.app.hubert.guide.model.HighLight
;
import
com.app.hubert.guide.model.HighlightOptions
;
...
...
@@ -50,11 +46,11 @@ import ocgcore.StringManager;
import
ocgcore.data.Card
;
import
ocgcore.data.LimitList
;
class
CardSearchActivityImpl
extends
BaseActivity
implements
CardLoader
.
CallBack
,
CardSearcher
.
CallBack
{
public
class
CardSearchActivity
extends
BaseActivity
implements
CardLoader
.
CallBack
,
CardSearcher
.
CallBack
{
public
static
final
String
SEARCH_MESSAGE
=
"searchMessage"
;
protected
DrawerLayout
mDrawerlayout
;
protected
CardSearcher
mCardSelector
;
protected
CardListAdapter
mCardListAdap
a
ter
;
protected
CardListAdapter
mCardListAdapter
;
protected
CardLoader
mCardLoader
;
protected
boolean
isLoad
=
false
;
protected
StringManager
mStringManager
=
DataManager
.
get
().
getStringManager
();
...
...
@@ -68,7 +64,6 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
private
DuelAssistantManagement
duelAssistantManagement
;
private
CardDetail
mCardDetail
;
private
DialogPlus
mDialog
;
private
Button
btn_search
;
private
TextView
mResult_count
;
@Override
...
...
@@ -77,21 +72,19 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
setContentView
(
R
.
layout
.
activity_search
);
mResult_count
=
findViewById
(
R
.
id
.
search_result_count
);
duelAssistantManagement
=
DuelAssistantManagement
.
getInstance
();
intentSearchMessage
=
getIntent
().
getStringExtra
(
CardSearchAc
i
tivity
.
SEARCH_MESSAGE
);
intentSearchMessage
=
getIntent
().
getStringExtra
(
CardSearchActivity
.
SEARCH_MESSAGE
);
// Toolbar toolbar = $(R.id.toolbar);
// setSupportActionBar(toolbar);
enableBackHome
();
mDrawerlayout
=
$
(
R
.
id
.
drawer_layout
);
mImageLoader
=
ImageLoader
.
get
(
this
);
mListView
=
$
(
R
.
id
.
list_cards
);
mCardListAdap
a
ter
=
new
CardListAdapter
(
this
,
mImageLoader
);
mCardListAdap
a
ter
.
setItemBg
(
true
);
mCardListAdapter
=
new
CardListAdapter
(
this
,
mImageLoader
);
mCardListAdapter
.
setItemBg
(
true
);
mListView
.
setLayoutManager
(
new
FastScrollLinearLayoutManager
(
this
));
mListView
.
setAdapter
(
mCardListAdapater
);
btn_search
=
$
(
R
.
id
.
btn_search
);
btn_search
.
setOnClickListener
((
v
)
->
{
showSearch
(
true
);
});
mListView
.
setAdapter
(
mCardListAdapter
);
Button
btn_search
=
$
(
R
.
id
.
btn_search
);
btn_search
.
setOnClickListener
((
v
)
->
showSearch
(
true
));
/*
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawerlayout, toolbar, R.string.search_open, R.string.search_close);
...
...
@@ -109,7 +102,7 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
setListeners
();
DialogPlus
dlg
=
DialogPlus
.
show
(
this
,
null
,
getString
(
R
.
string
.
loading
));
VUiKit
.
defer
().
when
(()
->
{
DataManager
.
get
().
load
(
fals
e
);
DataManager
.
get
().
load
(
tru
e
);
if
(
mLimitManager
.
getCount
()
>
0
)
{
mCardLoader
.
setLimitList
(
mLimitManager
.
getTopLimit
());
}
...
...
@@ -151,7 +144,7 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
mListView
.
addOnItemTouchListener
(
new
RecyclerViewItemListener
(
mListView
,
new
RecyclerViewItemListener
.
OnItemListener
()
{
@Override
public
void
onItemClick
(
View
view
,
int
pos
)
{
onCardClick
(
pos
,
mCardListAdap
a
ter
);
onCardClick
(
pos
,
mCardListAdapter
);
}
@Override
...
...
@@ -166,10 +159,11 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
}));
mListView
.
addOnScrollListener
(
new
RecyclerView
.
OnScrollListener
()
{
@Override
public
void
onScrollStateChanged
(
RecyclerView
recyclerView
,
int
newState
)
{
public
void
onScrollStateChanged
(
@NonNull
RecyclerView
recyclerView
,
int
newState
)
{
super
.
onScrollStateChanged
(
recyclerView
,
newState
);
switch
(
newState
)
{
case
RecyclerView
.
SCROLL_STATE_IDLE
:
case
RecyclerView
.
SCROLL_STATE_SETTLING
:
if
(!
isFinishing
())
{
Glide
.
with
(
getContext
()).
resumeRequests
();
}
...
...
@@ -177,27 +171,21 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
case
RecyclerView
.
SCROLL_STATE_DRAGGING
:
Glide
.
with
(
getContext
()).
pauseRequests
();
break
;
case
RecyclerView
.
SCROLL_STATE_SETTLING
:
if
(!
isFinishing
())
{
Glide
.
with
(
getContext
()).
resumeRequests
();
}
break
;
}
}
});
}
private
boolean
onBack
()
{
private
void
onBack
()
{
if
(
mDrawerlayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawerlayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
return
true
;
return
;
}
if
(
mDrawerlayout
.
isDrawerOpen
(
Gravity
.
LEFT
))
{
mDrawerlayout
.
closeDrawer
(
Gravity
.
LEFT
);
return
true
;
return
;
}
finish
();
return
true
;
}
@Override
...
...
@@ -214,10 +202,10 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
@Override
public
void
onSearchResult
(
List
<
Card
>
cardInfos
,
boolean
isHide
)
{
// Log.d("kk", "find " + (cardInfos == null ? -1 : cardInfos.size()));
mCardListAdap
a
ter
.
set
(
cardInfos
);
mCardListAdapter
.
set
(
cardInfos
);
mResult_count
.
setText
(
String
.
valueOf
(
cardInfos
.
size
()));
mCardListAdap
a
ter
.
notifyDataSetChanged
();
if
(
cardInfos
!=
null
&&
cardInfos
.
size
()
>
0
)
{
mCardListAdapter
.
notifyDataSetChanged
();
if
(
cardInfos
.
size
()
>
0
)
{
mListView
.
smoothScrollToPosition
(
0
);
}
}
...
...
@@ -244,7 +232,7 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
if
(
mDrawerlayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawerlayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
}
mCardListAdap
a
ter
.
setLimitList
(
limitList
);
mCardListAdapter
.
setLimitList
(
limitList
);
}
@Override
...
...
@@ -255,11 +243,8 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
switch
(
item
.
getItemId
())
{
case
R
.
id
.
action_search
:
//弹条件对话框
if
(
item
.
getItemId
()
==
R
.
id
.
action_search
)
{
//弹条件对话框
showSearch
(
true
);
break
;
}
return
super
.
onOptionsItemSelected
(
item
);
}
...
...
@@ -295,6 +280,11 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
if
(
cardInfo
!=
null
)
{
if
(
mCardDetail
==
null
)
{
mCardDetail
=
new
CardDetail
(
this
,
mImageLoader
,
mStringManager
);
mCardDetail
.
setCallBack
((
card
,
favorite
)
->
{
if
(
mCardSelector
.
isShowFavorite
())
{
mCardSelector
.
showFavorites
(
false
);
}
});
mCardDetail
.
setOnCardClickListener
(
new
CardDetail
.
DefaultOnCardClickListener
()
{
@Override
public
void
onOpenUrl
(
Card
cardInfo
)
{
...
...
@@ -313,16 +303,6 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
mDialog
.
dismiss
();
}
});
mCardDetail
.
setCallBack
(
new
CardDetail
.
CallBack
()
{
@Override
public
void
onSearchStart
()
{
}
@Override
public
void
onSearchResult
(
List
<
Card
>
Cards
,
boolean
isHide
)
{
CardSearchActivityImpl
.
this
.
onSearchResult
(
Cards
,
isHide
);
}
});
}
if
(
mDialog
==
null
)
{
mDialog
=
new
DialogPlus
(
this
);
...
...
@@ -358,19 +338,22 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
}
}
@Override
protected
void
onStop
()
{
super
.
onStop
();
CardFavorites
.
get
().
save
();
}
//https://www.jianshu.com/p/99649af3b191
public
void
showNewbieGuide
()
{
HighlightOptions
options
=
new
HighlightOptions
.
Builder
()
//绘制一个高亮虚线圈
.
setOnHighlightDrewListener
(
new
OnHighlightDrewListener
()
{
@Override
public
void
onHighlightDrew
(
Canvas
canvas
,
RectF
rectF
)
{
.
setOnHighlightDrewListener
((
canvas
,
rectF
)
->
{
Paint
paint
=
new
Paint
();
paint
.
setColor
(
Color
.
WHITE
);
paint
.
setStyle
(
Paint
.
Style
.
STROKE
);
paint
.
setStrokeWidth
(
20
);
paint
.
setPathEffect
(
new
DashPathEffect
(
new
float
[]{
20
,
20
},
0
));
canvas
.
drawCircle
(
rectF
.
centerX
(),
rectF
.
centerY
(),
rectF
.
width
()
/
2
+
10
,
paint
);
}
}).
build
();
NewbieGuide
.
with
(
this
)
//with方法可以传入Activity或者Fragment,获取引导页的依附者
.
setLabel
(
"searchCardGuide"
)
...
...
@@ -379,14 +362,10 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
.
setBackgroundColor
(
0xbc000000
)
.
addHighLightWithOptions
(
findViewById
(
R
.
id
.
btn_search
),
HighLight
.
Shape
.
CIRCLE
,
options
)
.
setLayoutRes
(
R
.
layout
.
view_guide_home
)
.
setOnLayoutInflatedListener
(
new
OnLayoutInflatedListener
()
{
@Override
public
void
onLayoutInflated
(
View
view
,
Controller
controller
)
{
.
setOnLayoutInflatedListener
((
view
,
controller
)
->
{
TextView
tv
=
view
.
findViewById
(
R
.
id
.
text_about
);
tv
.
setVisibility
(
View
.
VISIBLE
);
tv
.
setText
(
R
.
string
.
guide_button_search
);
}
})
)
...
...
@@ -395,14 +374,10 @@ class CardSearchActivityImpl extends BaseActivity implements CardLoader.CallBack
.
setBackgroundColor
(
0xbc000000
)
.
addHighLightWithOptions
(
findViewById
(
R
.
id
.
search_result_count
),
HighLight
.
Shape
.
CIRCLE
,
options
)
.
setLayoutRes
(
R
.
layout
.
view_guide_home
)
.
setOnLayoutInflatedListener
(
new
OnLayoutInflatedListener
()
{
@Override
public
void
onLayoutInflated
(
View
view
,
Controller
controller
)
{
.
setOnLayoutInflatedListener
((
view
,
controller
)
->
{
TextView
tv
=
view
.
findViewById
(
R
.
id
.
text_about
);
tv
.
setVisibility
(
View
.
VISIBLE
);
tv
.
setText
(
R
.
string
.
guide_search_result_count
);
}
})
)
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/CardSearcher.java
View file @
53c30ec3
...
...
@@ -4,30 +4,26 @@ package cn.garymb.ygomobile.ui.cards;
import
android.content.Context
;
import
android.graphics.Color
;
import
android.text.TextUtils
;
import
android.util.SparseArray
;
import
android.view.KeyEvent
;
import
android.view.View
;
import
android.view.View.OnClickListener
;
import
android.view.inputmethod.EditorInfo
;
import
android.view.inputmethod.InputMethodManager
;
import
android.widget.AdapterView
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.Spinner
;
import
android.widget.TextView
;
import
android.widget.TextView.OnEditorActionListener
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.loader.CardLoader
;
import
cn.garymb.ygomobile.loader.ICardLoader
;
import
cn.garymb.ygomobile.loader.ICardSearcher
;
import
cn.garymb.ygomobile.ui.adapters.SimpleSpinnerAdapter
;
import
cn.garymb.ygomobile.ui.adapters.SimpleSpinnerItem
;
import
cn.garymb.ygomobile.ui.plus.DialogPlus
;
import
ocgcore.ConfigManager
;
import
ocgcore.DataManager
;
import
ocgcore.LimitManager
;
import
ocgcore.StringManager
;
...
...
@@ -41,8 +37,6 @@ import ocgcore.enums.CardRace;
import
ocgcore.enums.CardType
;
import
ocgcore.enums.LimitType
;
import
static
cn
.
garymb
.
ygomobile
.
ui
.
cards
.
DeckManagerActivityImpl
.
Favorite
;
public
class
CardSearcher
implements
View
.
OnClickListener
{
final
String
[]
BtnVals
=
new
String
[
9
];
...
...
@@ -50,34 +44,35 @@ public class CardSearcher implements View.OnClickListener {
protected
LimitManager
mLimitManager
;
protected
AppsSettings
mSettings
;
int
lineKey
;
private
EditText
prefixWord
;
private
EditText
suffixWord
;
private
Spinner
otSpinner
;
private
Spinner
limitSpinner
;
private
Spinner
limitListSpinner
;
private
Spinner
typeSpinner
;
private
Spinner
typeMonsterSpinner
;
private
Spinner
typeMonsterSpinner2
;
private
Spinner
typeSpellSpinner
;
private
Spinner
typeTrapSpinner
;
private
Spinner
setc
odeSpinner
;
private
Spinner
categorySpinner
;
private
Spinner
raceSpinner
;
private
Spinner
levelSpinner
;
private
Spinner
attributeSpinner
;
private
EditText
atkText
;
private
EditText
defText
;
private
Spinner
pScale
;
private
Button
MyFav
Button
;
private
Button
LinkMarker
Button
;
private
Button
search
Button
;
private
Button
resetButton
;
private
View
view
;
private
View
layout_monst
er
;
private
ICardLoader
dataLoader
;
private
Context
mContext
;
private
final
EditText
prefixWord
;
private
final
EditText
suffixWord
;
private
final
Spinner
otSpinner
;
private
final
Spinner
limitSpinner
;
private
final
Spinner
limitListSpinner
;
private
final
Spinner
typeSpinner
;
private
final
Spinner
typeMonsterSpinner
;
private
final
Spinner
typeMonsterSpinner2
;
private
final
Spinner
typeSpellSpinner
;
private
final
Spinner
typeTrapSpinner
;
private
final
Spinner
setC
odeSpinner
;
private
final
Spinner
categorySpinner
;
private
final
Spinner
raceSpinner
;
private
final
Spinner
levelSpinner
;
private
final
Spinner
attributeSpinner
;
private
final
EditText
atkText
;
private
final
EditText
defText
;
private
final
Spinner
pScale
;
private
final
Button
LinkMarker
Button
;
private
final
Button
search
Button
;
private
final
Button
reset
Button
;
private
final
View
view
;
private
final
View
layout_monster
;
private
final
ICardSearcher
dataLoad
er
;
private
final
Context
mContext
;
private
final
Button
myFavButton
;
private
CallBack
mCallBack
;
CardLoader
mCardLoader
;
private
boolean
mShowFavorite
;
private
ICardSearcher
mCardLoader
;
public
interface
CallBack
{
void
onSearchStart
();
...
...
@@ -89,7 +84,7 @@ public class CardSearcher implements View.OnClickListener {
mCallBack
=
callBack
;
}
public
CardSearcher
(
View
view
,
ICard
Load
er
dataLoader
)
{
public
CardSearcher
(
View
view
,
ICard
Search
er
dataLoader
)
{
this
.
view
=
view
;
this
.
mContext
=
view
.
getContext
();
this
.
dataLoader
=
dataLoader
;
...
...
@@ -106,7 +101,7 @@ public class CardSearcher implements View.OnClickListener {
typeMonsterSpinner2
=
findViewById
(
R
.
id
.
sp_type_monster2
);
typeSpellSpinner
=
findViewById
(
R
.
id
.
sp_type_spell
);
typeTrapSpinner
=
findViewById
(
R
.
id
.
sp_type_trap
);
set
c
odeSpinner
=
findViewById
(
R
.
id
.
sp_setcode
);
set
C
odeSpinner
=
findViewById
(
R
.
id
.
sp_setcode
);
categorySpinner
=
findViewById
(
R
.
id
.
sp_category
);
raceSpinner
=
findViewById
(
R
.
id
.
sp_race
);
levelSpinner
=
findViewById
(
R
.
id
.
sp_level
);
...
...
@@ -114,20 +109,18 @@ public class CardSearcher implements View.OnClickListener {
atkText
=
findViewById
(
R
.
id
.
edt_atk
);
defText
=
findViewById
(
R
.
id
.
edt_def
);
LinkMarkerButton
=
findViewById
(
R
.
id
.
btn_linkmarker
);
M
yFavButton
=
findViewById
(
R
.
id
.
btn_my_fav
);
m
yFavButton
=
findViewById
(
R
.
id
.
btn_my_fav
);
searchButton
=
findViewById
(
R
.
id
.
btn_search
);
resetButton
=
findViewById
(
R
.
id
.
btn_reset
);
layout_monster
=
findViewById
(
R
.
id
.
layout_monster
);
pScale
=
findViewById
(
R
.
id
.
sp_scale
);
M
yFavButton
.
setOnClickListener
(
this
);
m
yFavButton
.
setOnClickListener
(
this
);
LinkMarkerButton
.
setOnClickListener
(
this
);
searchButton
.
setOnClickListener
(
this
);
resetButton
.
setOnClickListener
(
this
);
mCardLoader
=
new
CardLoader
(
mContext
)
;
mCardLoader
=
dataLoader
;
OnEditorActionListener
searchListener
=
new
OnEditorActionListener
()
{
@Override
public
boolean
onEditorAction
(
TextView
v
,
int
actionId
,
KeyEvent
event
)
{
OnEditorActionListener
searchListener
=
(
v
,
actionId
,
event
)
->
{
if
(
actionId
==
EditorInfo
.
IME_ACTION_SEARCH
)
{
InputMethodManager
imm
=
(
InputMethodManager
)
mContext
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
imm
.
hideSoftInputFromWindow
(
view
.
getWindowToken
(),
0
);
...
...
@@ -135,36 +128,21 @@ public class CardSearcher implements View.OnClickListener {
return
true
;
}
return
false
;
}
};
prefixWord
.
setOnEditorActionListener
(
searchListener
);
suffixWord
.
setOnEditorActionListener
(
searchListener
);
MyFavButton
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
SparseArray
<
Card
>
id
=
mCardLoader
.
readCards
(
ConfigManager
.
mLines
,
false
);
Favorite
.
clear
();
if
(
id
!=
null
)
{
for
(
int
i
=
0
;
i
<
id
.
size
();
i
++)
Favorite
.
add
(
id
.
valueAt
(
i
));
}
if
(
mCallBack
!=
null
)
{
mCallBack
.
onSearchStart
();
mCallBack
.
onSearchResult
(
Favorite
,
false
);
}
DeckManagerActivityImpl
.
isSearchResult
=
false
;
myFavButton
.
setOnClickListener
(
v
->
{
if
(
isShowFavorite
()){
hideFavorites
();
}
else
{
showFavorites
(
true
);
}
});
LinkMarkerButton
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
for
(
int
i
=
0
;
i
<
BtnVals
.
length
;
i
++)
{
BtnVals
[
i
]
=
"0"
;
}
LinkMarkerButton
.
setOnClickListener
(
v
->
{
Arrays
.
fill
(
BtnVals
,
"0"
);
DialogPlus
viewDialog
=
new
DialogPlus
(
mContext
);
viewDialog
.
setContentView
(
R
.
layout
.
item_linkmarker
);
viewDialog
.
setTitle
(
R
.
string
.
ClickLinkArrows
);
...
...
@@ -223,8 +201,6 @@ public class CardSearcher implements View.OnClickListener {
}
});
}
}
});
...
...
@@ -257,7 +233,7 @@ public class CardSearcher implements View.OnClickListener {
pScale
.
setVisibility
(
View
.
INVISIBLE
);
LinkMarkerButton
.
setVisibility
(
View
.
INVISIBLE
);
resetMonster
();
}
else
if
(
value
==
CardType
.
Spell
.
value
())
{
}
else
if
(
value
==
CardType
.
Spell
.
getId
())
{
layout_monster
.
setVisibility
(
View
.
INVISIBLE
);
raceSpinner
.
setVisibility
(
View
.
GONE
);
typeSpellSpinner
.
setVisibility
(
View
.
VISIBLE
);
...
...
@@ -265,7 +241,7 @@ public class CardSearcher implements View.OnClickListener {
pScale
.
setVisibility
(
View
.
INVISIBLE
);
LinkMarkerButton
.
setVisibility
(
View
.
INVISIBLE
);
resetMonster
();
}
else
if
(
value
==
CardType
.
Trap
.
value
())
{
}
else
if
(
value
==
CardType
.
Trap
.
getId
())
{
layout_monster
.
setVisibility
(
View
.
INVISIBLE
);
raceSpinner
.
setVisibility
(
View
.
GONE
);
typeSpellSpinner
.
setVisibility
(
View
.
GONE
);
...
...
@@ -297,6 +273,24 @@ public class CardSearcher implements View.OnClickListener {
});
}
public
void
showFavorites
(
boolean
showList
)
{
mShowFavorite
=
true
;
myFavButton
.
setSelected
(
true
);
if
(
mCallBack
!=
null
)
{
mCallBack
.
onSearchStart
();
mCallBack
.
onSearchResult
(
CardFavorites
.
get
().
getCards
(
mCardLoader
),
!
showList
);
}
}
public
void
hideFavorites
(){
mShowFavorite
=
true
;
myFavButton
.
setSelected
(
false
);
if
(
mCallBack
!=
null
)
{
mCallBack
.
onSearchStart
();
mCallBack
.
onSearchResult
(
Collections
.
emptyList
(),
true
);
}
}
public
void
initItems
()
{
initOtSpinners
(
otSpinner
);
initLimitSpinners
(
limitSpinner
);
...
...
@@ -317,7 +311,7 @@ public class CardSearcher implements View.OnClickListener {
initPscaleSpinners
(
pScale
);
initAttributes
(
attributeSpinner
);
initRaceSpinners
(
raceSpinner
);
initSetNameSpinners
(
set
c
odeSpinner
);
initSetNameSpinners
(
set
C
odeSpinner
);
initCategorySpinners
(
categorySpinner
);
}
...
...
@@ -334,21 +328,11 @@ public class CardSearcher implements View.OnClickListener {
}*/
private
void
initOtSpinners
(
Spinner
spinner
)
{
CardOt
[]
ots
=
CardOt
.
values
();
List
<
SimpleSpinnerItem
>
items
=
new
ArrayList
<>();
items
.
add
(
new
SimpleSpinnerItem
(
0
,
getString
(
R
.
string
.
label_ot
)));
/*
for (CardOt item : ots) {
if (item.ordinal() != 0) {
items.add(new SimpleSpinnerItem(item.ordinal(),
mStringManager.getOtString(item.ordinal(), item.toString()))
);
for
(
CardOt
item
:
CardOt
.
values
())
{
items
.
add
(
new
SimpleSpinnerItem
(
item
.
getId
(),
mStringManager
.
getOtString
(
item
.
getId
(),
false
)));
}
}*/
items
.
add
(
new
SimpleSpinnerItem
(
1
,
getString
(
R
.
string
.
label_ot_OCG
)));
items
.
add
(
new
SimpleSpinnerItem
(
2
,
getString
(
R
.
string
.
label_ot_TCG
)));
items
.
add
(
new
SimpleSpinnerItem
(
3
,
getString
(
R
.
string
.
label_ot_No_Exclusive
)));
items
.
add
(
new
SimpleSpinnerItem
(
4
,
getString
(
R
.
string
.
label_ot_CUSTOM
)));
items
.
add
(
new
SimpleSpinnerItem
(
8
,
getString
(
R
.
string
.
label_ot_SC_OCG
)));
SimpleSpinnerAdapter
adapter
=
new
SimpleSpinnerAdapter
(
mContext
);
adapter
.
setColor
(
Color
.
WHITE
);
adapter
.
setColor
(
Color
.
WHITE
);
...
...
@@ -356,6 +340,10 @@ public class CardSearcher implements View.OnClickListener {
spinner
.
setAdapter
(
adapter
);
}
public
boolean
isShowFavorite
()
{
return
mShowFavorite
;
}
protected
String
getString
(
int
id
)
{
return
mContext
.
getString
(
id
);
}
...
...
@@ -364,13 +352,12 @@ public class CardSearcher implements View.OnClickListener {
LimitType
[]
eitems
=
LimitType
.
values
();
List
<
SimpleSpinnerItem
>
items
=
new
ArrayList
<>();
for
(
LimitType
item
:
eitems
)
{
long
val
=
item
.
value
();
if
(
val
==
0
)
{
items
.
add
(
new
SimpleSpinnerItem
(
val
,
getString
(
R
.
string
.
label_limit
)));
}
else
if
(
val
==
LimitType
.
All
.
value
())
{
items
.
add
(
new
SimpleSpinnerItem
(
val
,
getString
(
R
.
string
.
all
)));
if
(
item
==
LimitType
.
None
)
{
items
.
add
(
new
SimpleSpinnerItem
(
item
.
getId
(),
getString
(
R
.
string
.
label_limit
)));
}
else
if
(
item
==
LimitType
.
All
)
{
items
.
add
(
new
SimpleSpinnerItem
(
item
.
getId
(),
getString
(
R
.
string
.
all
)));
}
else
{
items
.
add
(
new
SimpleSpinnerItem
(
val
,
mStringManager
.
getLimitString
(
val
)));
items
.
add
(
new
SimpleSpinnerItem
(
item
.
getId
(),
mStringManager
.
getLimitString
(
item
.
getId
()
)));
}
}
SimpleSpinnerAdapter
adapter
=
new
SimpleSpinnerAdapter
(
mContext
);
...
...
@@ -455,11 +442,10 @@ public class CardSearcher implements View.OnClickListener {
}
List
<
SimpleSpinnerItem
>
items
=
new
ArrayList
<>();
for
(
CardType
item
:
eitems
)
{
long
val
=
item
.
value
();
if
(
val
==
0
)
{
items
.
add
(
new
SimpleSpinnerItem
(
val
,
getString
(
R
.
string
.
label_type
)));
if
(
item
==
CardType
.
None
)
{
items
.
add
(
new
SimpleSpinnerItem
(
item
.
getId
(),
getString
(
R
.
string
.
label_type
)));
}
else
{
items
.
add
(
new
SimpleSpinnerItem
(
val
,
mStringManager
.
getTypeString
(
val
)));
items
.
add
(
new
SimpleSpinnerItem
(
item
.
getId
(),
mStringManager
.
getTypeString
(
item
.
getId
()
)));
}
}
SimpleSpinnerAdapter
adapter
=
new
SimpleSpinnerAdapter
(
mContext
);
...
...
@@ -472,11 +458,10 @@ public class CardSearcher implements View.OnClickListener {
CardAttribute
[]
attributes
=
CardAttribute
.
values
();
List
<
SimpleSpinnerItem
>
items
=
new
ArrayList
<>();
for
(
CardAttribute
item
:
attributes
)
{
long
val
=
item
.
value
();
if
(
val
==
0
)
{
items
.
add
(
new
SimpleSpinnerItem
(
val
,
getString
(
R
.
string
.
label_attr
)));
if
(
item
==
CardAttribute
.
None
)
{
items
.
add
(
new
SimpleSpinnerItem
(
CardAttribute
.
None
.
getId
(),
getString
(
R
.
string
.
label_attr
)));
}
else
{
items
.
add
(
new
SimpleSpinnerItem
(
val
,
mStringManager
.
getAttributeString
(
val
)));
items
.
add
(
new
SimpleSpinnerItem
(
item
.
getId
(),
mStringManager
.
getAttributeString
(
item
.
getId
()
)));
}
}
SimpleSpinnerAdapter
adapter
=
new
SimpleSpinnerAdapter
(
mContext
);
...
...
@@ -543,9 +528,10 @@ public class CardSearcher implements View.OnClickListener {
@Override
public
void
onClick
(
View
v
)
{
if
(
v
==
searchButton
)
{
if
(
v
.
getId
()
==
R
.
id
.
btn_search
)
{
hideFavorites
();
search
();
}
else
if
(
v
==
resetButton
)
{
}
else
if
(
v
.
getId
()
==
R
.
id
.
btn_reset
)
{
resetAll
();
}
}
...
...
@@ -564,12 +550,11 @@ public class CardSearcher implements View.OnClickListener {
,
getSelect
(
levelSpinner
),
getSelect
(
raceSpinner
),
getSelectText
(
limitListSpinner
),
getSelect
(
limitSpinner
),
text
(
atkText
),
text
(
defText
),
getSelect
(
pScale
),
getSelect
(
set
c
odeSpinner
)
getSelect
(
set
C
odeSpinner
)
,
getSelect
(
categorySpinner
),
getSelect
(
otSpinner
),
lineKey
,
getSelect
(
typeSpinner
),
getSelect
(
typeMonsterSpinner
),
getSelect
(
typeSpellSpinner
),
getSelect
(
typeTrapSpinner
)
,
getSelect
(
typeMonsterSpinner2
));
lineKey
=
0
;
}
DeckManagerActivityImpl
.
isSearchResult
=
true
;
}
private
void
resetAll
()
{
...
...
@@ -588,7 +573,7 @@ public class CardSearcher implements View.OnClickListener {
reset
(
typeSpinner
);
reset
(
typeSpellSpinner
);
reset
(
typeTrapSpinner
);
reset
(
set
c
odeSpinner
);
reset
(
set
C
odeSpinner
);
reset
(
categorySpinner
);
resetMonster
();
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivity.java
View file @
53c30ec3
package
cn.garymb.ygomobile.ui.cards
;
import
android.app.Activity
;
import
android.content.ClipData
;
import
android.content.ClipboardManager
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.Color
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.text.InputType
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.util.SparseArray
;
import
android.view.Gravity
;
import
android.view.MenuItem
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.ImageView
;
import
android.widget.Spinner
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
androidx.annotation.Nullable
;
import
androidx.appcompat.widget.AppCompatSpinner
;
import
androidx.appcompat.widget.RecyclerViewItemListener
;
import
androidx.recyclerview.widget.ItemTouchHelperPlus
;
import
androidx.recyclerview.widget.OnItemDragListener
;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.feihua.dialogutils.util.DialogUtils
;
import
com.nightonke.boommenu.BoomButtons.BoomButton
;
import
com.nightonke.boommenu.BoomButtons.TextOutsideCircleButton
;
import
com.nightonke.boommenu.BoomMenuButton
;
import
com.ourygo.assistant.service.DuelAssistantService
;
import
org.greenrobot.eventbus.EventBus
;
import
org.greenrobot.eventbus.Subscribe
;
import
org.greenrobot.eventbus.ThreadMode
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Locale
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.bean.Deck
;
import
cn.garymb.ygomobile.bean.DeckInfo
;
import
cn.garymb.ygomobile.bean.DeckType
;
import
cn.garymb.ygomobile.bean.events.CardInfoEvent
;
import
cn.garymb.ygomobile.bean.events.DeckFile
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.activities.WebActivity
;
import
cn.garymb.ygomobile.ui.adapters.SimpleSpinnerAdapter
;
import
cn.garymb.ygomobile.ui.adapters.SimpleSpinnerItem
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckAdapater
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckItem
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckItemTouchHelper
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckItemType
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckLayoutManager
;
import
cn.garymb.ygomobile.ui.mycard.mcchat.util.ImageUtil
;
import
cn.garymb.ygomobile.ui.plus.AOnGestureListener
;
import
cn.garymb.ygomobile.ui.plus.DefaultOnBoomListener
;
import
cn.garymb.ygomobile.ui.plus.DialogPlus
;
import
cn.garymb.ygomobile.ui.plus.VUiKit
;
import
cn.garymb.ygomobile.utils.BitmapUtil
;
import
cn.garymb.ygomobile.utils.DeckUtil
;
import
cn.garymb.ygomobile.utils.FileUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
cn.garymb.ygomobile.utils.ShareUtil
;
import
cn.garymb.ygomobile.utils.YGODialogUtil
;
import
cn.garymb.ygomobile.utils.YGOUtil
;
import
ocgcore.DataManager
;
import
ocgcore.data.Card
;
import
ocgcore.data.LimitList
;
import
ocgcore.enums.LimitType
;
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
;
@SuppressWarnings
({
"unused"
,
"deprecated"
})
public
class
DeckManagerActivity
extends
BaseCardsActivity
implements
RecyclerViewItemListener
.
OnItemListener
,
OnItemDragListener
,
YGODialogUtil
.
OnDeckMenuListener
{
public
static
void
start
(
Context
context
,
String
path
)
{
Intent
starter
=
new
Intent
(
context
,
DeckManagerActivity
.
class
);
starter
.
putExtra
(
Intent
.
EXTRA_TEXT
,
path
);
if
(!(
context
instanceof
Activity
))
{
starter
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
}
context
.
startActivity
(
starter
);
}
//region ui onCreate/onDestroy
private
RecyclerView
mRecyclerView
;
private
DeckAdapater
mDeckAdapater
;
private
final
AppsSettings
mSettings
=
AppsSettings
.
get
();
private
File
mPreLoadFile
;
private
DeckItemTouchHelper
mDeckItemTouchHelper
;
private
AppCompatSpinner
mDeckSpinner
;
private
TextView
tv_deck
;
private
TextView
tv_result_count
;
private
AppCompatSpinner
mLimitSpinner
;
private
CardDetail
mCardDetail
;
private
DialogPlus
mDialog
;
private
DialogPlus
builderShareLoading
;
private
boolean
isExit
=
false
;
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
tv_deck
=
$
(
R
.
id
.
tv_deck
);
tv_result_count
=
$
(
R
.
id
.
result_count
);
mDeckSpinner
=
$
(
R
.
id
.
toolbar_list
);
mDeckSpinner
.
setPopupBackgroundResource
(
R
.
color
.
colorNavy
);
mLimitSpinner
=
$
(
R
.
id
.
sp_limit_list
);
mLimitSpinner
.
setPopupBackgroundResource
(
R
.
color
.
colorNavy
);
mRecyclerView
=
$
(
R
.
id
.
grid_cards
);
mRecyclerView
.
setPadding
(
mRecyclerView
.
getPaddingLeft
(),
0
,
mRecyclerView
.
getPaddingRight
(),
mRecyclerView
.
getPaddingBottom
());
mRecyclerView
.
setAdapter
((
mDeckAdapater
=
new
DeckAdapater
(
this
,
mRecyclerView
,
getImageLoader
())));
mRecyclerView
.
setLayoutManager
(
new
DeckLayoutManager
(
this
,
Constants
.
DECK_WIDTH_COUNT
));
mDeckItemTouchHelper
=
new
DeckItemTouchHelper
(
mDeckAdapater
);
ItemTouchHelperPlus
touchHelper
=
new
ItemTouchHelperPlus
(
this
,
mDeckItemTouchHelper
);
touchHelper
.
setItemDragListener
(
this
);
touchHelper
.
setEnableClickDrag
(
Constants
.
DECK_SINGLE_PRESS_DRAG
);
touchHelper
.
attachToRecyclerView
(
mRecyclerView
);
mRecyclerView
.
addOnItemTouchListener
(
new
RecyclerViewItemListener
(
mRecyclerView
,
this
));
mDeckSpinner
.
setOnItemSelectedListener
(
new
AdapterView
.
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
AdapterView
<?>
adapterView
,
View
view
,
int
i
,
long
l
)
{
File
file
=
getSelectDeck
(
mDeckSpinner
);
if
(
file
!=
null
)
{
loadDeckFromFile
(
file
);
}
}
@Override
public
void
onNothingSelected
(
AdapterView
<?>
adapterView
)
{
}
});
String
preLoadFile
=
getIntent
().
getStringExtra
(
Intent
.
EXTRA_TEXT
);
initBoomMenuButton
(
$
(
R
.
id
.
bmb
));
$
(
R
.
id
.
btn_nav_search
).
setOnClickListener
((
v
)
->
doMenu
(
R
.
id
.
action_search
));
$
(
R
.
id
.
btn_nav_list
).
setOnClickListener
((
v
)
->
doMenu
(
R
.
id
.
action_card_list
));
//
final
File
_file
;
//打开指定卡组
if
(!
TextUtils
.
isEmpty
(
preLoadFile
)
&&
(
mPreLoadFile
=
new
File
(
preLoadFile
)).
exists
())
{
//外面卡组
_file
=
mPreLoadFile
;
}
else
{
mPreLoadFile
=
null
;
String
path
=
mSettings
.
getLastDeckPath
();
if
(
TextUtils
.
isEmpty
(
path
)){
_file
=
null
;
}
else
{
//最后卡组
_file
=
new
File
(
path
);
}
}
init
(
_file
);
EventBus
.
getDefault
().
register
(
this
);
tv_deck
.
setOnClickListener
(
v
->
YGODialogUtil
.
dialogDeckSelect
(
getActivity
(),
AppsSettings
.
get
().
getLastDeckPath
(),
this
));
}
//endregion
@Override
protected
void
onStop
()
{
super
.
onStop
();
CardFavorites
.
get
().
save
();
}
@Override
protected
void
onDestroy
()
{
EventBus
.
getDefault
().
unregister
(
this
);
super
.
onDestroy
();
}
//region card edit
@Override
public
void
onLimitListChanged
(
LimitList
limitList
)
{
}
public
class
DeckManagerActivity
extends
DeckManagerActivityImpl
{
@Override
public
void
onDragStart
()
{
public
static
Class
<?
extends
Activity
>
getDeckManager
()
{
if
(
AppsSettings
.
get
().
isUseDeckManagerV2
())
{
return
DeckManagerActivity3
.
class
;
}
return
DeckManagerActivity
.
class
;
@Override
public
void
onDragLongPress
(
int
pos
)
{
if
(
pos
<
0
)
return
;
if
(
Constants
.
DEBUG
)
Log
.
d
(
"kk"
,
"delete "
+
pos
);
if
(
mSettings
.
isDialogDelete
())
{
DeckItem
deckItem
=
mDeckAdapater
.
getItem
(
pos
);
if
(
deckItem
==
null
||
deckItem
.
getCardInfo
()
==
null
)
{
return
;
}
DialogPlus
dialogPlus
=
new
DialogPlus
(
this
);
dialogPlus
.
setTitle
(
R
.
string
.
question
);
dialogPlus
.
setMessage
(
getString
(
R
.
string
.
delete_card
,
deckItem
.
getCardInfo
().
Name
));
dialogPlus
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
dialogPlus
.
setLeftButtonListener
((
dlg
,
v
)
->
{
dlg
.
dismiss
();
mDeckItemTouchHelper
.
remove
(
pos
);
});
dialogPlus
.
show
();
}
else
{
mDeckAdapater
.
showHeadView
();
}
}
@Override
public
void
onDragLongPressEnd
()
{
mDeckAdapater
.
hideHeadView
();
}
//endregion
@Override
public
void
onDragEnd
()
{
}
//endregion
//region load deck
private
void
loadDeckFromFile
(
File
file
)
{
if
(!
mCardLoader
.
isOpen
()
||
file
==
null
||
!
file
.
exists
())
{
setCurDeck
(
new
DeckInfo
());
return
;
}
DialogPlus
dlg
=
DialogPlus
.
show
(
this
,
null
,
getString
(
R
.
string
.
loading
));
VUiKit
.
defer
().
when
(()
->
{
if
(
mCardLoader
.
isOpen
()
&&
file
.
exists
())
{
return
mDeckAdapater
.
read
(
mCardLoader
,
file
,
mCardLoader
.
getLimitList
());
}
else
{
return
new
DeckInfo
();
}
}).
done
((
rs
)
->
{
dlg
.
dismiss
();
setCurDeck
(
rs
);
});
}
//endregion
//region init
private
void
init
(
@Nullable
File
ydk
)
{
DialogPlus
dlg
=
DialogPlus
.
show
(
this
,
null
,
getString
(
R
.
string
.
loading
));
VUiKit
.
defer
().
when
(()
->
{
DataManager
.
get
().
load
(
true
);
//默认第一个卡表
if
(
mLimitManager
.
getCount
()
>
0
)
{
mCardLoader
.
setLimitList
(
mLimitManager
.
getTopLimit
());
}
File
file
=
ydk
;
if
(
file
==
null
||
!
file
.
exists
())
{
//当默认卡组不存在的时候
List
<
File
>
files
=
getYdkFiles
();
if
(
files
!=
null
&&
files
.
size
()
>
0
)
{
file
=
files
.
get
(
0
);
}
}
//EXTRA_DECK
if
(
file
==
null
)
{
return
new
DeckInfo
();
}
Log
.
i
(
"kk"
,
"load ydk "
+
file
);
if
(
mCardLoader
.
isOpen
()
&&
file
.
exists
())
{
return
mDeckAdapater
.
read
(
mCardLoader
,
file
,
mCardLoader
.
getLimitList
());
}
else
{
return
new
DeckInfo
();
}
}).
done
((
rs
)
->
{
isLoad
=
true
;
dlg
.
dismiss
();
mCardSelector
.
initItems
();
initLimitListSpinners
(
mLimitSpinner
,
mCardLoader
.
getLimitList
());
initDecksListSpinners
(
mDeckSpinner
,
rs
.
source
);
//设置当前卡组
setCurDeck
(
rs
);
//设置收藏夹
mCardSelector
.
showFavorites
(
false
);
});
}
/**
* 设置当前卡组
*/
private
void
setCurDeck
(
DeckInfo
deckInfo
)
{
if
(
deckInfo
==
null
)
{
deckInfo
=
new
DeckInfo
();
}
File
file
=
deckInfo
.
source
;
if
(
file
!=
null
&&
file
.
exists
())
{
String
name
=
IOUtils
.
tirmName
(
file
.
getName
(),
Constants
.
YDK_FILE_EX
);
setActionBarSubTitle
(
name
);
// if (inDeckDir(file)) {
//记住最后打开的卡组
mSettings
.
setLastDeckPath
(
file
.
getAbsolutePath
());
tv_deck
.
setText
(
name
);
// }
}
else
{
setActionBarSubTitle
(
getString
(
R
.
string
.
noname
));
}
mDeckAdapater
.
setDeck
(
deckInfo
);
mDeckAdapater
.
notifyDataSetChanged
();
}
private
boolean
inDeckDir
(
File
file
)
{
String
deck
=
new
File
(
AppsSettings
.
get
().
getDeckDir
()).
getAbsolutePath
();
return
TextUtils
.
equals
(
deck
,
file
.
getParent
());
}
@Override
public
void
onSearchStart
()
{
hideDrawers
();
}
@Override
protected
void
onCardClick
(
View
view
,
Card
cardInfo
,
int
pos
)
{
if
(
mCardListAdapter
.
isShowMenu
(
view
))
{
return
;
}
if
(
cardInfo
!=
null
)
{
showCardDialog
(
mCardListAdapter
,
cardInfo
,
pos
);
}
}
@Override
protected
void
onCardLongClick
(
View
view
,
Card
cardInfo
,
int
pos
)
{
// mCardListAdapater.showMenu(view);
}
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
public
void
onCardInfoEvent
(
CardInfoEvent
event
)
{
int
pos
=
event
.
position
;
Card
cardInfo
=
mCardListAdapter
.
getItem
(
pos
);
if
(
cardInfo
==
null
)
{
mCardListAdapter
.
hideMenu
(
null
);
}
else
if
(
event
.
toMain
)
{
if
(!
addMainCard
(
cardInfo
))
{
// || !checkLimit(cardInfo, false)) {
mCardListAdapter
.
hideMenu
(
null
);
}
}
else
{
if
(!
addSideCard
(
cardInfo
))
{
// || !checkLimit(cardInfo, false)) {
mCardListAdapter
.
hideMenu
(
null
);
}
}
}
@Override
public
void
onSearchResult
(
List
<
Card
>
cardInfos
,
boolean
isHide
)
{
super
.
onSearchResult
(
cardInfos
,
isHide
);
tv_result_count
.
setText
(
String
.
valueOf
(
cardInfos
.
size
()));
if
(!
isHide
)
showResult
(
false
);
}
@Override
public
void
onItemClick
(
View
view
,
int
pos
)
{
if
(
isShowDrawer
())
{
return
;
}
showDeckCard
(
view
,
pos
);
}
@Override
public
void
onItemLongClick
(
View
view
,
int
pos
)
{
}
@Override
public
void
onItemDoubleClick
(
View
view
,
int
pos
)
{
//拖拽中,就不显示
if
(
isShowDrawer
())
{
return
;
}
if
(
Constants
.
DECK_SINGLE_PRESS_DRAG
)
{
showDeckCard
(
view
,
pos
);
}
}
private
void
showDeckCard
(
View
view
,
int
pos
)
{
DeckItem
deckItem
=
mDeckAdapater
.
getItem
(
pos
);
if
(
deckItem
!=
null
&&
deckItem
.
getCardInfo
()
!=
null
)
{
showCardDialog
(
mDeckAdapater
,
deckItem
.
getCardInfo
(),
mDeckAdapater
.
getCardPosByView
(
pos
));
}
}
private
boolean
isShowDrawer
()
{
return
mDrawerLayout
.
isDrawerOpen
(
Constants
.
CARD_RESULT_GRAVITY
)
||
mDrawerLayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
);
}
private
boolean
isShowCard
()
{
return
mDialog
!=
null
&&
mDialog
.
isShowing
();
}
protected
void
showCardDialog
(
CardListProvider
provider
,
Card
cardInfo
,
int
pos
)
{
if
(
cardInfo
!=
null
)
{
if
(
isShowCard
())
return
;
if
(
mCardDetail
==
null
)
{
mCardDetail
=
new
CardDetail
(
this
,
getImageLoader
(),
mStringManager
);
mCardDetail
.
setOnCardClickListener
(
new
CardDetail
.
OnCardClickListener
()
{
@Override
public
void
onOpenUrl
(
Card
cardInfo
)
{
String
uri
;
int
t
=
cardInfo
.
Alias
-
cardInfo
.
Code
;
if
(
t
>
10
||
t
<
-
10
)
{
uri
=
Constants
.
WIKI_SEARCH_URL
+
String
.
format
(
"%08d"
,
cardInfo
.
Code
);
}
else
{
uri
=
Constants
.
WIKI_SEARCH_URL
+
String
.
format
(
"%08d"
,
cardInfo
.
Alias
);
}
WebActivity
.
open
(
getContext
(),
cardInfo
.
Name
,
uri
);
}
@Override
public
void
onClose
()
{
mDialog
.
dismiss
();
}
@Override
public
void
onAddSideCard
(
Card
cardInfo
)
{
addSideCard
(
cardInfo
);
}
@Override
public
void
onAddMainCard
(
Card
cardInfo
)
{
addMainCard
(
cardInfo
);
}
});
mCardDetail
.
setCallBack
((
card
,
favorite
)
->
{
if
(
mCardSelector
.
isShowFavorite
()){
mCardSelector
.
showFavorites
(
false
);
}
});
}
mCardDetail
.
showAdd
();
if
(
mDialog
==
null
)
{
mDialog
=
new
DialogPlus
(
this
);
mDialog
.
setView
(
mCardDetail
.
getView
());
mDialog
.
hideButton
();
mDialog
.
hideTitleBar
();
mDialog
.
setOnGestureListener
(
new
AOnGestureListener
()
{
@Override
public
boolean
onFling
(
MotionEvent
e1
,
MotionEvent
e2
,
float
velocityX
,
float
velocityY
)
{
if
(
isLeftFling
(
e1
,
e2
,
velocityX
,
velocityY
))
{
mCardDetail
.
onNextCard
();
return
true
;
}
else
if
(
isRightFling
(
e1
,
e2
,
velocityX
,
velocityY
))
{
mCardDetail
.
onPreCard
();
return
true
;
}
return
super
.
onFling
(
e1
,
e2
,
velocityX
,
velocityY
);
}
});
}
if
(!
mDialog
.
isShowing
())
{
mDialog
.
show
();
}
mCardDetail
.
bind
(
cardInfo
,
pos
,
provider
);
}
}
private
boolean
addSideCard
(
Card
cardInfo
)
{
if
(
checkLimit
(
cardInfo
))
{
boolean
rs
=
mDeckAdapater
.
AddCard
(
cardInfo
,
DeckItemType
.
SideCard
);
if
(
rs
)
{
showToast
(
R
.
string
.
add_card_tip_ok
,
Toast
.
LENGTH_SHORT
);
}
else
{
showToast
(
R
.
string
.
add_card_tip_fail
,
Toast
.
LENGTH_SHORT
);
}
return
rs
;
}
return
false
;
}
private
boolean
addMainCard
(
Card
cardInfo
)
{
if
(
checkLimit
(
cardInfo
))
{
boolean
rs
;
if
(
cardInfo
.
isExtraCard
())
{
rs
=
mDeckAdapater
.
AddCard
(
cardInfo
,
DeckItemType
.
ExtraCard
);
}
else
{
rs
=
mDeckAdapater
.
AddCard
(
cardInfo
,
DeckItemType
.
MainCard
);
}
if
(
rs
)
{
showToast
(
R
.
string
.
add_card_tip_ok
,
Toast
.
LENGTH_SHORT
);
}
else
{
showToast
(
R
.
string
.
add_card_tip_fail
,
Toast
.
LENGTH_SHORT
);
}
return
rs
;
}
return
false
;
}
@Override
protected
void
onBackHome
()
{
if
(
mDeckAdapater
.
isChanged
())
{
File
ydk
=
mDeckAdapater
.
getYdkFile
();
if
(
ydk
!=
null
&&
ydk
.
exists
())
{
DialogPlus
builder
=
new
DialogPlus
(
this
);
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
quit_deck_tip
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setRightButtonText
(
getString
(
R
.
string
.
save_quit
));
builder
.
setLeftButtonText
(
getString
(
R
.
string
.
quit
));
builder
.
setRightButtonListener
((
dlg
,
s
)
->
{
doMenu
(
R
.
id
.
action_save
);
dlg
.
dismiss
();
isExit
=
true
;
finish
();
});
builder
.
setLeftButtonListener
((
dlg
,
s
)
->
{
dlg
.
dismiss
();
isExit
=
true
;
finish
();
});
builder
.
show
();
}
}
else
{
super
.
onBackHome
();
}
}
@Override
public
void
onBackPressed
()
{
if
(
mDrawerLayout
.
isDrawerOpen
(
Constants
.
CARD_RESULT_GRAVITY
))
{
mDrawerLayout
.
closeDrawer
(
Constants
.
CARD_RESULT_GRAVITY
);
}
else
if
(
mDrawerLayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawerLayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
}
else
if
(!
isExit
)
{
if
(
mDeckAdapater
.
isChanged
())
{
File
ydk
=
mDeckAdapater
.
getYdkFile
();
if
(
ydk
!=
null
&&
ydk
.
exists
())
{
DialogPlus
builder
=
new
DialogPlus
(
this
);
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
quit_deck_tip
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonListener
((
dlg
,
s
)
->
{
dlg
.
dismiss
();
isExit
=
true
;
finish
();
});
builder
.
show
();
}
}
else
{
super
.
onBackPressed
();
}
}
else
{
super
.
onBackPressed
();
}
}
private
boolean
checkLimit
(
Card
cardInfo
)
{
SparseArray
<
Integer
>
mCount
=
mDeckAdapater
.
getCardCount
();
LimitList
limitList
=
mDeckAdapater
.
getLimitList
();
int
id
=
cardInfo
.
Alias
>
0
?
cardInfo
.
Alias
:
cardInfo
.
Code
;
Integer
count
=
mCount
.
get
(
id
);
if
(
limitList
==
null
)
{
return
count
!=
null
&&
count
<=
3
;
}
if
(
limitList
.
check
(
cardInfo
,
LimitType
.
Forbidden
))
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
0
),
Toast
.
LENGTH_SHORT
);
return
false
;
}
if
(
count
!=
null
)
{
if
(
limitList
.
check
(
cardInfo
,
LimitType
.
Limit
))
{
if
(
count
>=
1
)
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
1
),
Toast
.
LENGTH_SHORT
);
return
false
;
}
}
else
if
(
limitList
.
check
(
cardInfo
,
LimitType
.
SemiLimit
))
{
if
(
count
>=
2
)
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
2
),
Toast
.
LENGTH_SHORT
);
return
false
;
}
}
else
if
(
count
>=
Constants
.
CARD_MAX_COUNT
)
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
3
),
Toast
.
LENGTH_SHORT
);
return
false
;
}
}
return
true
;
}
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
if
(
doMenu
(
item
.
getItemId
()))
{
return
true
;
}
return
super
.
onOptionsItemSelected
(
item
);
}
public
boolean
doMenu
(
int
menuId
)
{
DialogPlus
builder
=
new
DialogPlus
(
this
);
switch
(
menuId
)
{
case
R
.
id
.
action_deck_backup_n_restore
:
startPermissionsActivity
();
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
deck_explain
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonText
(
R
.
string
.
deck_restore
);
builder
.
setRightButtonText
(
R
.
string
.
deck_back_up
);
builder
.
setRightButtonListener
((
dialog
,
which
)
->
{
dialog
.
dismiss
();
doBackUpDeck
();
});
builder
.
setLeftButtonListener
((
dialog
,
which
)
->
{
dialog
.
dismiss
();
doRestoreDeck
();
});
builder
.
show
();
break
;
// case R.id.action_refresh:
// mDeckAdapater.notifyDataSetChanged();
// break;
case
R
.
id
.
action_search
:
//弹条件对话框
showSearch
(
true
);
break
;
case
R
.
id
.
action_card_list
:
showResult
(
true
);
break
;
case
R
.
id
.
action_share_deck
:
if
(
mDeckAdapater
.
getYdkFile
()
==
null
)
{
Toast
.
makeText
(
this
,
R
.
string
.
unable_to_edit_empty_deck
,
Toast
.
LENGTH_SHORT
).
show
();
return
true
;
}
shareDeck
();
break
;
case
R
.
id
.
action_save
:
if
(
mPreLoadFile
!=
null
&&
mPreLoadFile
==
mDeckAdapater
.
getYdkFile
())
{
//需要保存到deck文件夹
inputDeckName
(
mPreLoadFile
,
null
,
true
);
}
else
{
if
(
mDeckAdapater
.
getYdkFile
()
==
null
)
{
inputDeckName
(
null
,
null
,
true
);
}
else
{
if
(
TextUtils
.
equals
(
mDeckAdapater
.
getYdkFile
().
getParent
(),
mSettings
.
getAiDeckDir
()))
{
Toast
.
makeText
(
this
,
R
.
string
.
donot_editor_bot_Deck
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
save
(
mDeckAdapater
.
getYdkFile
());
}
}
}
break
;
case
R
.
id
.
action_rename
:
if
(
mDeckAdapater
.
getYdkFile
()
==
null
)
{
Toast
.
makeText
(
this
,
R
.
string
.
unable_to_edit_empty_deck
,
Toast
.
LENGTH_SHORT
).
show
();
return
true
;
}
if
(
TextUtils
.
equals
(
mDeckAdapater
.
getYdkFile
().
getParent
(),
mSettings
.
getAiDeckDir
()))
{
Toast
.
makeText
(
this
,
R
.
string
.
donot_editor_bot_Deck
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
inputDeckName
(
mDeckAdapater
.
getYdkFile
(),
mDeckAdapater
.
getYdkFile
().
getParent
(),
false
);
}
break
;
case
R
.
id
.
action_deck_new
:
createDeck
(
null
);
break
;
case
R
.
id
.
action_clear_deck
:
{
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
question_clear_deck
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonListener
((
dlg
,
rs
)
->
{
mDeckAdapater
.
setDeck
(
new
DeckInfo
());
mDeckAdapater
.
notifyDataSetChanged
();
dlg
.
dismiss
();
});
builder
.
show
();
}
break
;
case
R
.
id
.
action_delete_deck
:
{
if
(
mDeckAdapater
.
getYdkFile
()
==
null
)
{
Toast
.
makeText
(
this
,
R
.
string
.
unable_to_edit_empty_deck
,
Toast
.
LENGTH_SHORT
).
show
();
return
true
;
}
if
(
TextUtils
.
equals
(
mDeckAdapater
.
getYdkFile
().
getParent
(),
mSettings
.
getAiDeckDir
()))
{
Toast
.
makeText
(
this
,
R
.
string
.
donot_editor_bot_Deck
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
question_delete_deck
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonListener
((
dlg
,
rs
)
->
{
if
(
mDeckAdapater
.
getYdkFile
()
!=
null
)
{
FileUtils
.
deleteFile
(
mDeckAdapater
.
getYdkFile
());
dlg
.
dismiss
();
File
file
=
getFirstYdk
();
initDecksListSpinners
(
mDeckSpinner
,
file
);
loadDeckFromFile
(
file
);
}
});
builder
.
show
();
}
}
break
;
case
R
.
id
.
action_unsort
:
//打乱
mDeckAdapater
.
unSort
();
break
;
case
R
.
id
.
action_sort
:
mDeckAdapater
.
sort
();
break
;
default
:
return
false
;
}
return
true
;
}
private
void
createDeck
(
String
savePath
)
{
final
File
old
=
mDeckAdapater
.
getYdkFile
();
DialogPlus
builder
=
new
DialogPlus
(
this
);
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
question_keep_cur_deck
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonListener
((
dlg
,
rs
)
->
{
dlg
.
dismiss
();
//复制当前卡组
inputDeckName
(
old
,
savePath
,
true
);
});
builder
.
setRightButtonListener
((
dlg
,
rs
)
->
{
dlg
.
dismiss
();
setCurDeck
(
null
);
inputDeckName
(
null
,
savePath
,
true
);
});
builder
.
setOnCloseLinster
((
dlg
)
->
{
dlg
.
dismiss
();
setCurDeck
(
null
);
inputDeckName
(
null
,
savePath
,
true
);
});
builder
.
show
();
}
private
File
getFirstYdk
()
{
List
<
File
>
files
=
getYdkFiles
();
return
files
==
null
||
files
.
size
()
==
0
?
null
:
files
.
get
(
0
);
}
private
void
shareDeck
()
{
builderShareLoading
=
new
DialogPlus
(
this
);
builderShareLoading
.
showProgressBar
();
builderShareLoading
.
hideTitleBar
();
builderShareLoading
.
setMessage
(
R
.
string
.
Pre_share
);
builderShareLoading
.
show
();
//先排序
// mDeckAdapater.sort();
//保存
// if (mPreLoadFile != null && mPreLoadFile == mDeckAdapater.getYdkFile()) {
// //需要保存到deck文件夹
// inputDeckName(mPreLoadFile, null, true);
// } else {
// if (mDeckAdapater.getYdkFile() == null) {
// inputDeckName(null, null, true);
// } else {
// save(mDeckAdapater.getYdkFile());
// }
// }
// //保存成功后重新加载卡组
// File file = getSelectDeck(mDeckSpinner);
// if (file != null) {
// loadDeckFromFile(file);
// }
//延时半秒,使整体看起来更流畅
new
Handler
().
postDelayed
(
this
::
shareDeck1
,
500
);
}
private
void
shareDeck1
()
{
//开启绘图缓存
mRecyclerView
.
setDrawingCacheEnabled
(
true
);
//这个方法可调可不调,因为在getDrawingCache()里会自动判断有没有缓存有没有准备好,
//如果没有,会自动调用buildDrawingCache()
mRecyclerView
.
buildDrawingCache
();
//获取绘图缓存 这里直接创建了一个新的bitmap
//因为我们在最后需要释放缓存资源,会释放掉缓存中创建的bitmap对象
Bitmap
bitmap
=
BitmapUtil
.
drawBg4Bitmap
(
Color
.
parseColor
(
"#e6f3fd"
),
Bitmap
.
createBitmap
(
mRecyclerView
.
getDrawingCache
(),
0
,
0
,
mRecyclerView
.
getMeasuredWidth
(),
mRecyclerView
.
getMeasuredHeight
()));
//清理绘图缓存,释放资源
mRecyclerView
.
destroyDrawingCache
();
// shotRecyclerView(mRecyclerView)
Deck
deck
=
mDeckAdapater
.
toDeck
(
mDeckAdapater
.
getYdkFile
());
String
deckName
=
deck
.
getName
();
int
end
=
deckName
.
lastIndexOf
(
"."
);
if
(
end
!=
-
1
)
{
deckName
=
deckName
.
substring
(
0
,
end
);
}
String
savePath
=
new
File
(
AppsSettings
.
get
().
getDeckSharePath
(),
deckName
+
".jpg"
).
getAbsolutePath
();
BitmapUtil
.
saveBitmap
(
bitmap
,
savePath
,
50
);
builderShareLoading
.
dismiss
();
DialogUtils
du
=
DialogUtils
.
getdx
(
this
);
View
viewDialog
=
du
.
dialogBottomSheet
(
R
.
layout
.
dialog_deck_share
,
0
);
ImageView
iv_image
=
viewDialog
.
findViewById
(
R
.
id
.
iv_image
);
Button
bt_image_share
=
viewDialog
.
findViewById
(
R
.
id
.
bt_image_share
);
Button
bt_code_share
=
viewDialog
.
findViewById
(
R
.
id
.
bt_code_share
);
EditText
et_code
=
viewDialog
.
findViewById
(
R
.
id
.
et_code
);
et_code
.
setText
(
mDeckAdapater
.
getDeckInfo
().
toDeck
().
toAppUri
().
toString
());
ImageUtil
.
setImage
(
this
,
savePath
,
iv_image
);
bt_code_share
.
setOnClickListener
(
v
->
{
du
.
dis
();
stopService
(
new
Intent
(
this
,
DuelAssistantService
.
class
));
YGOUtil
.
copyMessage
(
this
,
et_code
.
getText
().
toString
().
trim
());
showToast
(
getString
(
R
.
string
.
deck_text_copyed
));
//复制完毕开启决斗助手
YGOUtil
.
startDuelService
(
this
);
});
bt_image_share
.
setOnClickListener
(
v
->
{
du
.
dis
();
String
category
=
mDeckAdapater
.
getYdkFile
().
getParent
();
String
fname
=
deck
.
getName
();
Intent
intent
=
new
Intent
(
ACTION_SHARE_FILE
);
intent
.
addCategory
(
Intent
.
CATEGORY_DEFAULT
);
intent
.
putExtra
(
IrrlichtBridge
.
EXTRA_SHARE_TYPE
,
"ydk"
);
if
(
TextUtils
.
equals
(
category
,
mSettings
.
getDeckDir
()))
{
intent
.
putExtra
(
IrrlichtBridge
.
EXTRA_SHARE_FILE
,
fname
);
}
else
{
String
cname
=
DeckUtil
.
getDeckTypeName
(
mDeckAdapater
.
getYdkFile
().
getAbsolutePath
());
intent
.
putExtra
(
IrrlichtBridge
.
EXTRA_SHARE_FILE
,
cname
+
"/"
+
fname
);
}
intent
.
setPackage
(
getPackageName
());
try
{
startActivity
(
intent
);
}
catch
(
Throwable
e
)
{
Toast
.
makeText
(
getContext
(),
"dev error:not found activity."
,
Toast
.
LENGTH_SHORT
).
show
();
}
});
//复制前关闭决斗助手
// String label = TextUtils.isEmpty(deck.getName()) ? getString(R.string.share_deck) : deck.getName();
// final String uriString = deck.toAppUri().toString();
// final String httpUri = deck.toHttpUri().toString();
// shareUrl(uriString, label);
}
private
void
shareUrl
(
String
uri
,
String
label
)
{
String
url
=
getString
(
R
.
string
.
deck_share_head
)
+
" "
+
uri
;
ShareUtil
.
shareText
(
this
,
getString
(
R
.
string
.
share_deck
),
url
,
null
);
ClipboardManager
clipboardManager
=
(
ClipboardManager
)
getSystemService
(
CLIPBOARD_SERVICE
);
if
(
Build
.
VERSION
.
SDK_INT
>
19
)
{
clipboardManager
.
setPrimaryClip
(
ClipData
.
newPlainText
(
label
,
uri
));
}
else
{
clipboardManager
.
setText
(
uri
);
}
showToast
(
R
.
string
.
copy_to_clipbroad
,
Toast
.
LENGTH_SHORT
);
}
private
File
getSelectDeck
(
Spinner
spinner
)
{
Object
o
=
SimpleSpinnerAdapter
.
getSelectTag
(
spinner
);
if
(
o
instanceof
File
)
{
return
(
File
)
o
;
}
return
null
;
}
private
List
<
File
>
getYdkFiles
()
{
File
dir
=
new
File
(
mSettings
.
getResourcePath
(),
Constants
.
CORE_DECK_PATH
);
File
[]
files
=
dir
.
listFiles
((
file
,
s
)
->
s
.
toLowerCase
(
Locale
.
US
).
endsWith
(
Constants
.
YDK_FILE_EX
));
if
(
files
!=
null
)
{
List
<
File
>
list
=
new
ArrayList
<>(
Arrays
.
asList
(
files
));
if
(
mPreLoadFile
!=
null
&&
mPreLoadFile
.
exists
())
{
boolean
hasCur
=
false
;
for
(
File
f
:
list
)
{
if
(
TextUtils
.
equals
(
f
.
getAbsolutePath
(),
mPreLoadFile
.
getAbsolutePath
()))
{
hasCur
=
true
;
break
;
}
}
if
(!
hasCur
)
{
list
.
add
(
mPreLoadFile
);
}
}
return
list
;
}
return
null
;
}
private
void
initDecksListSpinners
(
Spinner
spinner
,
File
curYdk
)
{
List
<
File
>
files
=
getYdkFiles
();
List
<
SimpleSpinnerItem
>
items
=
new
ArrayList
<>();
String
name
=
curYdk
!=
null
?
curYdk
.
getName
()
:
null
;
int
index
=
-
1
;
if
(
files
!=
null
)
{
Collections
.
sort
(
files
,
(
ydk1
,
ydk2
)
->
{
if
(
ydk1
.
isDirectory
()
&&
ydk2
.
isFile
())
return
-
1
;
if
(
ydk1
.
isFile
()
&&
ydk2
.
isDirectory
())
return
1
;
return
ydk1
.
getName
().
compareTo
(
ydk2
.
getName
());
});
int
i
=
0
;
for
(
File
file
:
files
)
{
if
(
name
!=
null
&&
TextUtils
.
equals
(
name
,
file
.
getName
()))
{
index
=
i
;
}
String
filename
=
IOUtils
.
tirmName
(
file
.
getName
(),
Constants
.
YDK_FILE_EX
);
items
.
add
(
new
SimpleSpinnerItem
(
i
++,
filename
).
setTag
(
file
));
}
}
SimpleSpinnerAdapter
simpleSpinnerAdapter
=
new
SimpleSpinnerAdapter
(
this
);
simpleSpinnerAdapter
.
set
(
items
);
simpleSpinnerAdapter
.
setColor
(
Color
.
WHITE
);
simpleSpinnerAdapter
.
setSingleLine
(
true
);
spinner
.
setAdapter
(
simpleSpinnerAdapter
);
if
(
index
>=
0
)
{
spinner
.
setSelection
(
index
);
}
}
// private void initLimitListSpinners(Spinner spinner) {
// List<SimpleSpinnerItem> items = new ArrayList<>();
// List<Integer> ids = mLimitManager.getLists();
// int index = -1;
// int i = 0;
// for (Integer id : ids) {
// LimitList list = mLimitManager.getLimitFromIndex(id);
// if (list == mLimitList) {
// index = i;
// }
// items.add(new SimpleSpinnerItem(id, list.getName()));
// i++;
// }
// SimpleSpinnerAdapter adapter = new SimpleSpinnerAdapter(this);
// adapter.set(items);
// spinner.setAdapter(adapter);
// if (index >= 0) {
// spinner.setSelection(index);
// }
private
void
initLimitListSpinners
(
Spinner
spinner
,
LimitList
cur
)
{
List
<
SimpleSpinnerItem
>
items
=
new
ArrayList
<>();
List
<
String
>
limitLists
=
mLimitManager
.
getLimitNames
();
int
index
=
-
1
;
int
count
=
mLimitManager
.
getCount
();
items
.
add
(
new
SimpleSpinnerItem
(
0
,
getString
(
R
.
string
.
label_limitlist
)));
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
int
j
=
i
+
1
;
String
name
=
limitLists
.
get
(
i
);
items
.
add
(
new
SimpleSpinnerItem
(
j
,
name
));
if
(
cur
!=
null
&&
TextUtils
.
equals
(
cur
.
getName
(),
name
))
{
index
=
j
;
}
}
SimpleSpinnerAdapter
adapter
=
new
SimpleSpinnerAdapter
(
this
);
adapter
.
setColor
(
Color
.
WHITE
);
adapter
.
set
(
items
);
spinner
.
setAdapter
(
adapter
);
if
(
index
>=
0
)
{
spinner
.
setSelection
(
index
);
}
spinner
.
setOnItemSelectedListener
(
new
AdapterView
.
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
setLimitList
(
mLimitManager
.
getLimit
(
SimpleSpinnerAdapter
.
getSelectText
(
spinner
)));
}
@Override
public
void
onNothingSelected
(
AdapterView
<?>
parent
)
{
}
});
}
private
void
setLimitList
(
LimitList
limitList
)
{
if
(
limitList
==
null
)
return
;
LimitList
last
=
mDeckAdapater
.
getLimitList
();
boolean
nochanged
=
last
!=
null
&&
TextUtils
.
equals
(
last
.
getName
(),
limitList
.
getName
());
if
(!
nochanged
)
{
mDeckAdapater
.
setLimitList
(
limitList
);
runOnUiThread
(()
->
{
mDeckAdapater
.
notifyItemRangeChanged
(
DeckItem
.
MainStart
,
DeckItem
.
MainEnd
);
mDeckAdapater
.
notifyItemRangeChanged
(
DeckItem
.
ExtraStart
,
DeckItem
.
ExtraEnd
);
mDeckAdapater
.
notifyItemRangeChanged
(
DeckItem
.
SideStart
,
DeckItem
.
SideEnd
);
});
}
mCardListAdapter
.
setLimitList
(
limitList
);
runOnUiThread
(()
->
mCardListAdapter
.
notifyDataSetChanged
());
}
private
void
inputDeckName
(
File
oldYdk
,
String
savePath
,
boolean
keepOld
)
{
DialogPlus
builder
=
new
DialogPlus
(
this
);
builder
.
setTitle
(
R
.
string
.
intpu_name
);
EditText
editText
=
new
EditText
(
this
);
editText
.
setGravity
(
Gravity
.
TOP
|
Gravity
.
LEFT
);
editText
.
setInputType
(
InputType
.
TYPE_TEXT_FLAG_NO_SUGGESTIONS
);
editText
.
setSingleLine
();
if
(
oldYdk
!=
null
)
{
editText
.
setText
(
oldYdk
.
getName
());
}
builder
.
setContentView
(
editText
);
builder
.
setOnCloseLinster
(
DialogInterface:
:
dismiss
);
builder
.
setLeftButtonListener
((
dlg
,
s
)
->
{
CharSequence
name
=
editText
.
getText
();
if
(!
TextUtils
.
isEmpty
(
name
))
{
String
filename
=
String
.
valueOf
(
name
);
if
(!
filename
.
endsWith
(
YDK_FILE_EX
))
{
filename
+=
YDK_FILE_EX
;
}
File
ydk
;
if
(
TextUtils
.
isEmpty
(
savePath
))
ydk
=
new
File
(
mSettings
.
getDeckDir
(),
filename
);
else
ydk
=
new
File
(
savePath
,
filename
);
if
(
ydk
.
exists
())
{
showToast
(
R
.
string
.
file_exist
,
Toast
.
LENGTH_SHORT
);
return
;
}
if
(!
keepOld
&&
oldYdk
!=
null
&&
oldYdk
.
exists
())
{
if
(
oldYdk
.
renameTo
(
ydk
))
{
initDecksListSpinners
(
mDeckSpinner
,
ydk
);
dlg
.
dismiss
();
loadDeckFromFile
(
ydk
);
}
}
else
{
if
(
oldYdk
==
mPreLoadFile
)
{
mPreLoadFile
=
null
;
}
dlg
.
dismiss
();
try
{
boolean
ret
=
ydk
.
createNewFile
();
}
catch
(
Throwable
ignore
)
{
}
initDecksListSpinners
(
mDeckSpinner
,
ydk
);
save
(
ydk
);
loadDeckFromFile
(
ydk
);
}
}
else
{
dlg
.
dismiss
();
}
});
builder
.
show
();
}
private
void
save
(
File
ydk
)
{
if
(
mDeckAdapater
.
save
(
ydk
))
{
showToast
(
R
.
string
.
save_tip_ok
,
Toast
.
LENGTH_SHORT
);
}
else
{
showToast
(
R
.
string
.
save_tip_fail
,
Toast
.
LENGTH_SHORT
);
}
}
private
void
initBoomMenuButton
(
BoomMenuButton
menu
)
{
final
SparseArray
<
Integer
>
mMenuIds
=
new
SparseArray
<>();
// addMenuButton(mMenuIds, menu, R.id.action_card_search, R.string.deck_list, R.drawable.listicon);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_share_deck
,
R
.
string
.
share_deck
,
R
.
drawable
.
shareicon
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_save
,
R
.
string
.
save_deck
,
R
.
drawable
.
save
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_clear_deck
,
R
.
string
.
clear_deck
,
R
.
drawable
.
clear_deck
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_deck_new
,
R
.
string
.
new_deck
,
R
.
drawable
.
addsever
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_rename
,
R
.
string
.
rename_deck
,
R
.
drawable
.
rename
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_delete_deck
,
R
.
string
.
delete_deck
,
R
.
drawable
.
delete
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_unsort
,
R
.
string
.
unsort
,
R
.
drawable
.
unsort
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_sort
,
R
.
string
.
sort
,
R
.
drawable
.
sort
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_deck_backup_n_restore
,
R
.
string
.
deck_backup_n_restore
,
R
.
drawable
.
downloadimages
);
//设置展开或隐藏的延时。 默认值为 800ms。
menu
.
setDuration
(
150
);
//设置每两个子按钮之间动画的延时(ms为单位)。 比如,如果延时设为0,那么所有子按钮都会同时展开或隐藏,默认值为100ms。
menu
.
setDelay
(
10
);
menu
.
setOnBoomListener
(
new
DefaultOnBoomListener
()
{
@Override
public
void
onClicked
(
int
index
,
BoomButton
boomButton
)
{
doMenu
(
mMenuIds
.
get
(
index
));
}
});
}
private
void
addMenuButton
(
SparseArray
<
Integer
>
mMenuIds
,
BoomMenuButton
menuButton
,
int
menuId
,
int
stringId
,
int
image
)
{
addMenuButton
(
mMenuIds
,
menuButton
,
menuId
,
getString
(
stringId
),
image
);
}
private
void
addMenuButton
(
SparseArray
<
Integer
>
mMenuIds
,
BoomMenuButton
menuButton
,
int
menuId
,
String
str
,
int
image
)
{
TextOutsideCircleButton
.
Builder
builder
=
new
TextOutsideCircleButton
.
Builder
()
.
shadowColor
(
Color
.
TRANSPARENT
)
.
normalColor
(
Color
.
TRANSPARENT
)
.
normalImageRes
(
image
)
.
normalText
(
str
);
menuButton
.
addBuilder
(
builder
);
mMenuIds
.
put
(
mMenuIds
.
size
(),
menuId
);
}
private
void
doBackUpDeck
()
{
try
{
FileUtils
.
copyDir
(
mSettings
.
getDeckDir
(),
ORI_DECK
,
true
);
}
catch
(
Throwable
e
)
{
Toast
.
makeText
(
getContext
(),
e
+
""
,
Toast
.
LENGTH_SHORT
).
show
();
}
Toast
.
makeText
(
getContext
(),
R
.
string
.
done
,
Toast
.
LENGTH_SHORT
).
show
();
}
private
void
doRestoreDeck
()
{
try
{
FileUtils
.
copyDir
(
ORI_DECK
,
mSettings
.
getDeckDir
(),
false
);
}
catch
(
Throwable
e
)
{
Toast
.
makeText
(
getContext
(),
e
+
""
,
Toast
.
LENGTH_SHORT
).
show
();
}
Toast
.
makeText
(
getContext
(),
R
.
string
.
done
,
Toast
.
LENGTH_SHORT
).
show
();
}
@Override
public
void
onDeckSelect
(
DeckFile
deckFile
)
{
loadDeckFromFile
(
new
File
(
deckFile
.
getPath
()));
}
@Override
public
void
onDeckDel
(
List
<
DeckFile
>
deckFileList
)
{
File
deck
=
mDeckAdapater
.
getYdkFile
();
if
(
deck
==
null
)
return
;
String
currentDeckPath
=
deck
.
getAbsolutePath
();
for
(
DeckFile
deckFile
:
deckFileList
)
{
if
(
deckFile
.
getPath
().
equals
(
currentDeckPath
))
{
List
<
File
>
files
=
getYdkFiles
();
File
file
=
null
;
if
(
files
!=
null
&&
files
.
size
()
>
0
)
{
file
=
files
.
get
(
0
);
}
if
(
file
!=
null
)
{
loadDeckFromFile
(
file
);
}
else
{
setCurDeck
(
new
DeckInfo
());
}
return
;
}
}
}
@Override
public
void
onDeckMove
(
List
<
DeckFile
>
deckFileList
,
DeckType
toDeckType
)
{
String
currentDeckPath
=
mDeckAdapater
.
getYdkFile
().
getAbsolutePath
();
for
(
DeckFile
deckFile
:
deckFileList
)
{
if
(
deckFile
.
getPath
().
equals
(
currentDeckPath
))
{
loadDeckFromFile
(
new
File
(
toDeckType
.
getPath
(),
deckFile
.
getName
()
+
".ydk"
));
return
;
}
}
}
@Override
public
void
onDeckCopy
(
List
<
DeckFile
>
deckFileList
,
DeckType
toDeckType
)
{
String
currentDeckPath
=
mDeckAdapater
.
getYdkFile
().
getAbsolutePath
();
for
(
DeckFile
deckFile
:
deckFileList
)
{
if
(
deckFile
.
getPath
().
equals
(
currentDeckPath
))
{
loadDeckFromFile
(
new
File
(
toDeckType
.
getPath
(),
deckFile
.
getName
()
+
".ydk"
));
return
;
}
}
}
@Override
public
void
onDeckNew
(
DeckType
currentDeckType
)
{
createDeck
(
currentDeckType
.
getPath
());
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivity2.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards
;
public
class
DeckManagerActivity2
extends
DeckManagerActivityImpl2
{
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivity3.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards
;
import
android.content.Intent
;
import
android.content.res.Configuration
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
android.view.View
;
import
android.widget.Toast
;
import
androidx.appcompat.widget.Toolbar
;
import
androidx.recyclerview.widget.OnItemDragListener
;
import
androidx.recyclerview.widget.RecyclerView
;
import
java.io.File
;
import
java.util.List
;
import
java.util.Locale
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.bean.DeckInfo
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.loader.CardLoader
;
import
cn.garymb.ygomobile.loader.DeckLoader
;
import
cn.garymb.ygomobile.ui.activities.BaseActivity
;
import
cn.garymb.ygomobile.ui.cards.deck2.DeckAdapter
;
import
cn.garymb.ygomobile.ui.plus.DialogPlus
;
import
cn.garymb.ygomobile.ui.plus.VUiKit
;
import
ocgcore.DataManager
;
import
ocgcore.LimitManager
;
import
ocgcore.StringManager
;
import
ocgcore.data.Card
;
import
ocgcore.data.LimitList
;
public
class
DeckManagerActivity3
extends
BaseActivity
implements
OnItemDragListener
,
CardLoader
.
CallBack
{
private
RecyclerView
mRecyclerView
;
private
DeckAdapter
mDeckAdapter
;
protected
StringManager
mStringManager
=
DataManager
.
get
().
getStringManager
();
protected
LimitManager
mLimitManager
=
DataManager
.
get
().
getLimitManager
();
protected
CardLoader
mCardLoader
;
private
AppsSettings
mSettings
=
AppsSettings
.
get
();
private
String
mPreLoad
;
private
File
mYdkFile
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_deck_cards3
);
Toolbar
toolbar
=
$
(
R
.
id
.
toolbar
);
setSupportActionBar
(
toolbar
);
enableBackHome
();
mRecyclerView
=
(
RecyclerView
)
findViewById
(
R
.
id
.
recyclerview
);
mDeckAdapter
=
new
DeckAdapter
(
this
,
mRecyclerView
,
this
);
mRecyclerView
.
setAdapter
(
mDeckAdapter
);
findViewById
(
R
.
id
.
refresh
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
mDeckAdapter
.
notifyDataSetChanged
();
}
});
mCardLoader
=
new
CardLoader
(
this
);
mCardLoader
.
setCallBack
(
this
);
if
(
getIntent
().
hasExtra
(
Intent
.
EXTRA_TEXT
))
{
String
path
=
getIntent
().
getStringExtra
(
Intent
.
EXTRA_TEXT
);
if
(!
TextUtils
.
isEmpty
(
path
))
{
mPreLoad
=
path
;
}
}
DialogPlus
dlg
=
DialogPlus
.
show
(
this
,
null
,
getString
(
R
.
string
.
loading
));
VUiKit
.
defer
().
when
(()
->
{
mCardLoader
.
setLimitList
(
mLimitManager
.
getTopLimit
());
File
file
=
new
File
(
mSettings
.
getLastDeckPath
());
if
(!
TextUtils
.
isEmpty
(
mPreLoad
))
{
file
=
new
File
(
mPreLoad
);
mPreLoad
=
null
;
}
if
(!
file
.
exists
())
{
//当默认卡组不存在的时候
File
[]
files
=
getYdkFiles
();
if
(
files
!=
null
&&
files
.
length
>
0
)
{
file
=
files
[
0
];
}
}
//EXTRA_DECK
if
(
file
==
null
)
{
return
new
DeckInfo
();
}
mYdkFile
=
file
;
if
(
mCardLoader
.
isOpen
()
&&
file
.
exists
())
{
return
DeckLoader
.
readDeck
(
mCardLoader
,
file
,
mCardLoader
.
getLimitList
());
}
else
{
return
new
DeckInfo
();
}
}).
done
((
rs
)
->
{
dlg
.
dismiss
();
mDeckAdapter
.
setDeckInfo
(
rs
);
mDeckAdapter
.
notifyDataSetChanged
();
});
}
private
File
[]
getYdkFiles
()
{
File
dir
=
new
File
(
mSettings
.
getResourcePath
(),
Constants
.
CORE_DECK_PATH
);
File
[]
files
=
dir
.
listFiles
((
file
,
s
)
->
{
return
s
.
toLowerCase
(
Locale
.
US
).
endsWith
(
Constants
.
YDK_FILE_EX
);
});
return
files
;
}
@Override
public
void
onDragStart
()
{
}
@Override
public
void
onDragLongPress
(
int
pos
)
{
Toast
.
makeText
(
this
,
"on long press :"
+
pos
,
Toast
.
LENGTH_SHORT
).
show
();
}
@Override
public
void
onConfigurationChanged
(
Configuration
newConfig
)
{
if
(
getRequestedOrientation
()
!=
newConfig
.
orientation
)
{
mDeckAdapter
.
notifyDataSetChanged
();
}
super
.
onConfigurationChanged
(
newConfig
);
}
@Override
public
void
onDragLongPressEnd
()
{
}
@Override
public
void
onDragEnd
()
{
}
@Override
public
void
onSearchStart
()
{
}
@Override
public
void
onLimitListChanged
(
LimitList
limitList
)
{
}
@Override
public
void
onSearchResult
(
List
<
Card
>
Cards
,
boolean
isHide
)
{
}
@Override
public
void
onResetSearch
()
{
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivityImpl.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards
;
import
android.content.ClipData
;
import
android.content.ClipboardManager
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.Color
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.text.InputType
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.util.SparseArray
;
import
android.view.Gravity
;
import
android.view.MenuItem
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.ImageView
;
import
android.widget.Spinner
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
androidx.annotation.Nullable
;
import
androidx.appcompat.widget.AppCompatSpinner
;
import
androidx.appcompat.widget.RecyclerViewItemListener
;
import
androidx.recyclerview.widget.ItemTouchHelperPlus
;
import
androidx.recyclerview.widget.OnItemDragListener
;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.feihua.dialogutils.util.DialogUtils
;
import
com.nightonke.boommenu.BoomButtons.BoomButton
;
import
com.nightonke.boommenu.BoomButtons.TextOutsideCircleButton
;
import
com.nightonke.boommenu.BoomMenuButton
;
import
com.ourygo.assistant.service.DuelAssistantService
;
import
org.greenrobot.eventbus.EventBus
;
import
org.greenrobot.eventbus.Subscribe
;
import
org.greenrobot.eventbus.ThreadMode
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Locale
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.bean.Deck
;
import
cn.garymb.ygomobile.bean.DeckInfo
;
import
cn.garymb.ygomobile.bean.DeckType
;
import
cn.garymb.ygomobile.bean.events.CardInfoEvent
;
import
cn.garymb.ygomobile.bean.events.DeckFile
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.activities.WebActivity
;
import
cn.garymb.ygomobile.ui.adapters.SimpleSpinnerAdapter
;
import
cn.garymb.ygomobile.ui.adapters.SimpleSpinnerItem
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckAdapater
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckItem
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckItemTouchHelper
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckItemType
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckLayoutManager
;
import
cn.garymb.ygomobile.ui.mycard.mcchat.util.ImageUtil
;
import
cn.garymb.ygomobile.ui.plus.AOnGestureListener
;
import
cn.garymb.ygomobile.ui.plus.DefaultOnBoomListener
;
import
cn.garymb.ygomobile.ui.plus.DialogPlus
;
import
cn.garymb.ygomobile.ui.plus.VUiKit
;
import
cn.garymb.ygomobile.utils.BitmapUtil
;
import
cn.garymb.ygomobile.utils.DeckUtil
;
import
cn.garymb.ygomobile.utils.FileUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
cn.garymb.ygomobile.utils.ShareUtil
;
import
cn.garymb.ygomobile.utils.YGODialogUtil
;
import
cn.garymb.ygomobile.utils.YGOUtil
;
import
ocgcore.ConfigManager
;
import
ocgcore.DataManager
;
import
ocgcore.data.Card
;
import
ocgcore.data.LimitList
;
import
ocgcore.enums.LimitType
;
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
;
class
DeckManagerActivityImpl
extends
BaseCardsAcitivity
implements
RecyclerViewItemListener
.
OnItemListener
,
OnItemDragListener
,
YGODialogUtil
.
OnDeckMenuListener
{
//region ui onCreate/onDestroy
private
RecyclerView
mRecyclerView
;
private
DeckAdapater
mDeckAdapater
;
private
AppsSettings
mSettings
=
AppsSettings
.
get
();
private
File
mPreLoadFile
;
private
DeckItemTouchHelper
mDeckItemTouchHelper
;
private
AppCompatSpinner
mDeckSpinner
;
private
TextView
tv_deck
;
private
TextView
tv_result_count
;
private
SimpleSpinnerAdapter
mSimpleSpinnerAdapter
;
private
AppCompatSpinner
mLimitSpinner
;
private
CardDetail
mCardDetail
;
private
DialogPlus
mDialog
;
private
DialogPlus
builderShareLoading
;
private
boolean
isExit
=
false
;
public
static
boolean
isSearchResult
;
public
static
List
<
Card
>
Favorite
=
new
ArrayList
<
Card
>();
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
tv_deck
=
$
(
R
.
id
.
tv_deck
);
tv_result_count
=
$
(
R
.
id
.
result_count
);
mDeckSpinner
=
$
(
R
.
id
.
toolbar_list
);
mDeckSpinner
.
setPopupBackgroundResource
(
R
.
color
.
colorNavy
);
mLimitSpinner
=
$
(
R
.
id
.
sp_limit_list
);
mLimitSpinner
.
setPopupBackgroundResource
(
R
.
color
.
colorNavy
);
mRecyclerView
=
$
(
R
.
id
.
grid_cards
);
mRecyclerView
.
setPadding
(
mRecyclerView
.
getPaddingLeft
(),
0
,
mRecyclerView
.
getPaddingRight
(),
mRecyclerView
.
getPaddingBottom
());
mRecyclerView
.
setAdapter
((
mDeckAdapater
=
new
DeckAdapater
(
this
,
mRecyclerView
,
getImageLoader
())));
mRecyclerView
.
setLayoutManager
(
new
DeckLayoutManager
(
this
,
Constants
.
DECK_WIDTH_COUNT
));
mDeckItemTouchHelper
=
new
DeckItemTouchHelper
(
mDeckAdapater
);
ItemTouchHelperPlus
touchHelper
=
new
ItemTouchHelperPlus
(
this
,
mDeckItemTouchHelper
);
touchHelper
.
setItemDragListener
(
this
);
touchHelper
.
setEnableClickDrag
(
Constants
.
DECK_SINGLE_PRESS_DRAG
);
touchHelper
.
attachToRecyclerView
(
mRecyclerView
);
mRecyclerView
.
addOnItemTouchListener
(
new
RecyclerViewItemListener
(
mRecyclerView
,
this
));
mDeckSpinner
.
setOnItemSelectedListener
(
new
AdapterView
.
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
AdapterView
<?>
adapterView
,
View
view
,
int
i
,
long
l
)
{
File
file
=
getSelectDeck
(
mDeckSpinner
);
if
(
file
!=
null
)
{
loadDeckFromFile
(
file
);
}
}
@Override
public
void
onNothingSelected
(
AdapterView
<?>
adapterView
)
{
}
});
String
preLoadFile
=
null
;
if
(
getIntent
().
hasExtra
(
Intent
.
EXTRA_TEXT
))
{
preLoadFile
=
getIntent
().
getStringExtra
(
Intent
.
EXTRA_TEXT
);
}
initBoomMenuButton
(
$
(
R
.
id
.
bmb
));
$
(
R
.
id
.
btn_nav_search
).
setOnClickListener
((
v
)
->
{
doMenu
(
R
.
id
.
action_search
);
});
$
(
R
.
id
.
btn_nav_list
).
setOnClickListener
((
v
)
->
{
doMenu
(
R
.
id
.
action_card_list
);
});
//
final
File
_file
;
//打开指定卡组
if
(!
TextUtils
.
isEmpty
(
preLoadFile
)
&&
(
mPreLoadFile
=
new
File
(
preLoadFile
)).
exists
())
{
//外面卡组
_file
=
mPreLoadFile
;
}
else
{
mPreLoadFile
=
null
;
//最后卡组
_file
=
new
File
(
mSettings
.
getLastDeckPath
());
}
Favorite
.
clear
();
init
(
_file
);
EventBus
.
getDefault
().
register
(
this
);
tv_deck
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
YGODialogUtil
.
dialogDeckSelect
(
DeckManagerActivityImpl
.
this
,
AppsSettings
.
get
().
getLastDeckPath
(),
DeckManagerActivityImpl
.
this
);
}
});
}
//endregion
@Override
protected
void
onDestroy
()
{
EventBus
.
getDefault
().
unregister
(
this
);
super
.
onDestroy
();
}
//region card edit
@Override
public
void
onLimitListChanged
(
LimitList
limitList
)
{
}
@Override
public
void
onDragStart
()
{
}
@Override
public
void
onDragLongPress
(
int
pos
)
{
if
(
pos
<
0
)
return
;
if
(
Constants
.
DEBUG
)
Log
.
d
(
"kk"
,
"delete "
+
pos
);
if
(
mSettings
.
isDialogDelete
())
{
DeckItem
deckItem
=
mDeckAdapater
.
getItem
(
pos
);
if
(
deckItem
==
null
||
deckItem
.
getCardInfo
()
==
null
)
{
return
;
}
DialogPlus
dialogPlus
=
new
DialogPlus
(
this
);
dialogPlus
.
setTitle
(
R
.
string
.
question
);
dialogPlus
.
setMessage
(
getString
(
R
.
string
.
delete_card
,
deckItem
.
getCardInfo
().
Name
));
dialogPlus
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
dialogPlus
.
setLeftButtonListener
((
dlg
,
v
)
->
{
dlg
.
dismiss
();
mDeckItemTouchHelper
.
remove
(
pos
);
});
dialogPlus
.
show
();
}
else
{
mDeckAdapater
.
showHeadView
();
}
}
@Override
public
void
onDragLongPressEnd
()
{
mDeckAdapater
.
hideHeadView
();
}
//endregion
@Override
public
void
onDragEnd
()
{
}
//endregion
//region load deck
private
void
loadDeckFromFile
(
File
file
)
{
if
(!
mCardLoader
.
isOpen
()
||
file
==
null
||
!
file
.
exists
())
{
setCurDeck
(
new
DeckInfo
());
return
;
}
DialogPlus
dlg
=
DialogPlus
.
show
(
this
,
null
,
getString
(
R
.
string
.
loading
));
VUiKit
.
defer
().
when
(()
->
{
if
(
mCardLoader
.
isOpen
()
&&
file
.
exists
())
{
return
mDeckAdapater
.
read
(
mCardLoader
,
file
,
mCardLoader
.
getLimitList
());
}
else
{
return
new
DeckInfo
();
}
}).
done
((
rs
)
->
{
dlg
.
dismiss
();
setCurDeck
(
rs
);
});
}
//endregion
//region init
private
void
init
(
File
ydk
)
{
DialogPlus
dlg
=
DialogPlus
.
show
(
this
,
null
,
getString
(
R
.
string
.
loading
));
VUiKit
.
defer
().
when
(()
->
{
DataManager
.
get
().
load
(
false
);
//默认第一个卡表
if
(
mLimitManager
.
getCount
()
>
0
)
{
mCardLoader
.
setLimitList
(
mLimitManager
.
getTopLimit
());
}
File
file
=
ydk
;
if
(!
file
.
exists
())
{
//当默认卡组不存在的时候
List
<
File
>
files
=
getYdkFiles
();
if
(
files
!=
null
&&
files
.
size
()
>
0
)
{
file
=
files
.
get
(
0
);
}
}
//EXTRA_DECK
if
(
file
==
null
)
{
return
new
DeckInfo
();
}
Log
.
i
(
"kk"
,
"load ydk "
+
file
);
if
(
mCardLoader
.
isOpen
()
&&
file
.
exists
())
{
return
mDeckAdapater
.
read
(
mCardLoader
,
file
,
mCardLoader
.
getLimitList
());
}
else
{
return
new
DeckInfo
();
}
}).
done
((
rs
)
->
{
isLoad
=
true
;
dlg
.
dismiss
();
mCardSelector
.
initItems
();
initLimitListSpinners
(
mLimitSpinner
,
mCardLoader
.
getLimitList
());
initDecksListSpinners
(
mDeckSpinner
,
rs
.
source
);
//设置当前卡组
setCurDeck
(
rs
);
//设置收藏夹
SparseArray
<
Card
>
id
=
mCardLoader
.
readCards
(
ConfigManager
.
mLines
,
false
);
if
(
id
!=
null
)
{
for
(
int
i
=
0
;
i
<
id
.
size
();
i
++)
Favorite
.
add
(
id
.
valueAt
(
i
));
}
onSearchResult
(
Favorite
,
true
);
isSearchResult
=
false
;
});
}
/**
* 设置当前卡组
*
* @param deckInfo
*/
private
void
setCurDeck
(
DeckInfo
deckInfo
)
{
if
(
deckInfo
==
null
)
{
deckInfo
=
new
DeckInfo
();
}
File
file
=
deckInfo
.
source
;
if
(
file
!=
null
&&
file
.
exists
())
{
String
name
=
IOUtils
.
tirmName
(
file
.
getName
(),
Constants
.
YDK_FILE_EX
);
setActionBarSubTitle
(
name
);
// if (inDeckDir(file)) {
//记住最后打开的卡组
mSettings
.
setLastDeckPath
(
file
.
getAbsolutePath
());
tv_deck
.
setText
(
name
);
// }
}
else
{
setActionBarSubTitle
(
getString
(
R
.
string
.
noname
));
}
mDeckAdapater
.
setDeck
(
deckInfo
);
mDeckAdapater
.
notifyDataSetChanged
();
}
private
boolean
inDeckDir
(
File
file
)
{
String
deck
=
new
File
(
AppsSettings
.
get
().
getDeckDir
()).
getAbsolutePath
();
return
TextUtils
.
equals
(
deck
,
file
.
getParentFile
().
getAbsolutePath
());
}
@Override
public
void
onSearchStart
()
{
hideDrawers
();
}
@Override
protected
void
onCardClick
(
View
view
,
Card
cardInfo
,
int
pos
)
{
if
(
mCardListAdapater
.
isShowMenu
(
view
))
{
return
;
}
if
(
cardInfo
!=
null
)
{
showCardDialog
(
mCardListAdapater
,
cardInfo
,
pos
);
}
}
@Override
protected
void
onCardLongClick
(
View
view
,
Card
cardInfo
,
int
pos
)
{
// mCardListAdapater.showMenu(view);
}
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
public
void
onCardInfoEvent
(
CardInfoEvent
event
)
{
int
pos
=
event
.
position
;
Card
cardInfo
=
mCardListAdapater
.
getItem
(
pos
);
if
(
cardInfo
==
null
)
{
mCardListAdapater
.
hideMenu
(
null
);
}
else
if
(
event
.
toMain
)
{
if
(!
addMainCard
(
cardInfo
))
{
// || !checkLimit(cardInfo, false)) {
mCardListAdapater
.
hideMenu
(
null
);
}
}
else
{
if
(!
addSideCard
(
cardInfo
))
{
// || !checkLimit(cardInfo, false)) {
mCardListAdapater
.
hideMenu
(
null
);
}
}
}
@Override
public
void
onSearchResult
(
List
<
Card
>
cardInfos
,
boolean
isHide
)
{
super
.
onSearchResult
(
cardInfos
,
isHide
);
tv_result_count
.
setText
(
String
.
valueOf
(
cardInfos
.
size
()));
if
(!
isHide
)
showResult
(
false
);
}
@Override
public
void
onItemClick
(
View
view
,
int
pos
)
{
if
(
isShowDrawer
())
{
return
;
}
showDeckCard
(
view
,
pos
);
}
@Override
public
void
onItemLongClick
(
View
view
,
int
pos
)
{
if
(
isShowDrawer
())
{
return
;
}
}
@Override
public
void
onItemDoubleClick
(
View
view
,
int
pos
)
{
//拖拽中,就不显示
if
(
isShowDrawer
())
{
return
;
}
if
(
Constants
.
DECK_SINGLE_PRESS_DRAG
)
{
showDeckCard
(
view
,
pos
);
}
}
private
void
showDeckCard
(
View
view
,
int
pos
)
{
DeckItem
deckItem
=
mDeckAdapater
.
getItem
(
pos
);
if
(
deckItem
!=
null
&&
deckItem
.
getCardInfo
()
!=
null
)
{
showCardDialog
(
mDeckAdapater
,
deckItem
.
getCardInfo
(),
mDeckAdapater
.
getCardPosByView
(
pos
));
}
}
private
boolean
isShowDrawer
()
{
return
mDrawerlayout
.
isDrawerOpen
(
Constants
.
CARD_RESULT_GRAVITY
)
||
mDrawerlayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
);
}
private
boolean
isShowCard
()
{
return
mDialog
!=
null
&&
mDialog
.
isShowing
();
}
protected
void
showCardDialog
(
CardListProvider
provider
,
Card
cardInfo
,
int
pos
)
{
if
(
cardInfo
!=
null
)
{
if
(
isShowCard
())
return
;
if
(
mCardDetail
==
null
)
{
mCardDetail
=
new
CardDetail
(
this
,
getImageLoader
(),
mStringManager
);
mCardDetail
.
setOnCardClickListener
(
new
CardDetail
.
OnCardClickListener
()
{
@Override
public
void
onOpenUrl
(
Card
cardInfo
)
{
String
uri
;
int
t
=
cardInfo
.
Alias
-
cardInfo
.
Code
;
if
(
t
>
10
||
t
<
-
10
)
{
uri
=
Constants
.
WIKI_SEARCH_URL
+
String
.
format
(
"%08d"
,
cardInfo
.
Code
);
}
else
{
uri
=
Constants
.
WIKI_SEARCH_URL
+
String
.
format
(
"%08d"
,
cardInfo
.
Alias
);
}
WebActivity
.
open
(
getContext
(),
cardInfo
.
Name
,
uri
);
}
@Override
public
void
onClose
()
{
mDialog
.
dismiss
();
}
@Override
public
void
onAddSideCard
(
Card
cardInfo
)
{
addSideCard
(
cardInfo
);
}
@Override
public
void
onAddMainCard
(
Card
cardInfo
)
{
addMainCard
(
cardInfo
);
}
});
mCardDetail
.
setCallBack
(
new
CardDetail
.
CallBack
()
{
@Override
public
void
onSearchStart
()
{
}
@Override
public
void
onSearchResult
(
List
<
Card
>
Cards
,
boolean
isHide
)
{
DeckManagerActivityImpl
.
this
.
onSearchResult
(
Cards
,
isHide
);
}
});
}
mCardDetail
.
showAdd
();
if
(
mDialog
==
null
)
{
mDialog
=
new
DialogPlus
(
this
);
mDialog
.
setView
(
mCardDetail
.
getView
());
mDialog
.
hideButton
();
mDialog
.
hideTitleBar
();
mDialog
.
setOnGestureListener
(
new
AOnGestureListener
()
{
@Override
public
boolean
onFling
(
MotionEvent
e1
,
MotionEvent
e2
,
float
velocityX
,
float
velocityY
)
{
if
(
isLeftFling
(
e1
,
e2
,
velocityX
,
velocityY
))
{
mCardDetail
.
onNextCard
();
return
true
;
}
else
if
(
isRightFling
(
e1
,
e2
,
velocityX
,
velocityY
))
{
mCardDetail
.
onPreCard
();
return
true
;
}
return
super
.
onFling
(
e1
,
e2
,
velocityX
,
velocityY
);
}
});
}
if
(!
mDialog
.
isShowing
())
{
mDialog
.
show
();
}
mCardDetail
.
bind
(
cardInfo
,
pos
,
provider
);
}
}
private
boolean
addSideCard
(
Card
cardInfo
)
{
if
(
checkLimit
(
cardInfo
,
true
))
{
boolean
rs
=
mDeckAdapater
.
AddCard
(
cardInfo
,
DeckItemType
.
SideCard
);
if
(
rs
)
{
showToast
(
R
.
string
.
add_card_tip_ok
,
Toast
.
LENGTH_SHORT
);
}
else
{
showToast
(
R
.
string
.
add_card_tip_fail
,
Toast
.
LENGTH_SHORT
);
}
return
rs
;
}
return
false
;
}
private
boolean
addMainCard
(
Card
cardInfo
)
{
if
(
checkLimit
(
cardInfo
,
true
))
{
boolean
rs
;
if
(
cardInfo
.
isExtraCard
())
{
rs
=
mDeckAdapater
.
AddCard
(
cardInfo
,
DeckItemType
.
ExtraCard
);
}
else
{
rs
=
mDeckAdapater
.
AddCard
(
cardInfo
,
DeckItemType
.
MainCard
);
}
if
(
rs
)
{
showToast
(
R
.
string
.
add_card_tip_ok
,
Toast
.
LENGTH_SHORT
);
}
else
{
showToast
(
R
.
string
.
add_card_tip_fail
,
Toast
.
LENGTH_SHORT
);
}
return
rs
;
}
return
false
;
}
@Override
protected
void
onBackHome
()
{
if
(
mDeckAdapater
.
isChanged
())
{
File
ydk
=
mDeckAdapater
.
getYdkFile
();
if
(
ydk
!=
null
&&
ydk
.
exists
())
{
DialogPlus
builder
=
new
DialogPlus
(
this
);
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
quit_deck_tip
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setRightButtonText
(
getString
(
R
.
string
.
save_quit
));
builder
.
setLeftButtonText
(
getString
(
R
.
string
.
quit
));
builder
.
setRightButtonListener
((
dlg
,
s
)
->
{
doMenu
(
R
.
id
.
action_save
);
dlg
.
dismiss
();
isExit
=
true
;
finish
();
});
builder
.
setLeftButtonListener
((
dlg
,
s
)
->
{
dlg
.
dismiss
();
isExit
=
true
;
finish
();
});
builder
.
show
();
}
}
else
{
super
.
onBackHome
();
}
}
@Override
public
void
onBackPressed
()
{
if
(
mDrawerlayout
.
isDrawerOpen
(
Constants
.
CARD_RESULT_GRAVITY
))
{
mDrawerlayout
.
closeDrawer
(
Constants
.
CARD_RESULT_GRAVITY
);
}
else
if
(
mDrawerlayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawerlayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
}
else
if
(!
isExit
)
{
if
(
mDeckAdapater
.
isChanged
())
{
File
ydk
=
mDeckAdapater
.
getYdkFile
();
if
(
ydk
!=
null
&&
ydk
.
exists
())
{
DialogPlus
builder
=
new
DialogPlus
(
this
);
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
quit_deck_tip
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonListener
((
dlg
,
s
)
->
{
dlg
.
dismiss
();
isExit
=
true
;
finish
();
});
builder
.
show
();
}
}
else
{
super
.
onBackPressed
();
}
}
else
{
super
.
onBackPressed
();
}
}
private
boolean
checkLimit
(
Card
cardInfo
,
boolean
tip
)
{
SparseArray
<
Integer
>
mCount
=
mDeckAdapater
.
getCardCount
();
LimitList
limitList
=
mDeckAdapater
.
getLimitList
();
Integer
id
=
cardInfo
.
Alias
>
0
?
cardInfo
.
Alias
:
cardInfo
.
Code
;
Integer
count
=
mCount
.
get
(
id
);
if
(
limitList
==
null
)
{
return
count
!=
null
&&
count
<=
3
;
}
if
(
limitList
.
check
(
cardInfo
,
LimitType
.
Forbidden
))
{
if
(
tip
)
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
0
),
Toast
.
LENGTH_SHORT
);
}
return
false
;
}
if
(
count
!=
null
)
{
if
(
limitList
.
check
(
cardInfo
,
LimitType
.
Limit
))
{
if
(
count
>=
1
)
{
if
(
tip
)
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
1
),
Toast
.
LENGTH_SHORT
);
}
return
false
;
}
}
else
if
(
limitList
.
check
(
cardInfo
,
LimitType
.
SemiLimit
))
{
if
(
count
>=
2
)
{
if
(
tip
)
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
2
),
Toast
.
LENGTH_SHORT
);
}
return
false
;
}
}
else
if
(
count
>=
Constants
.
CARD_MAX_COUNT
)
{
if
(
tip
)
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
3
),
Toast
.
LENGTH_SHORT
);
}
return
false
;
}
}
return
true
;
}
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
if
(
doMenu
(
item
.
getItemId
()))
{
return
true
;
}
return
super
.
onOptionsItemSelected
(
item
);
}
public
boolean
doMenu
(
int
menuId
)
{
DialogPlus
builder
=
new
DialogPlus
(
this
);
switch
(
menuId
)
{
case
R
.
id
.
action_deck_backup_n_restore
:
startPermissionsActivity
();
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
deck_explain
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonText
(
R
.
string
.
deck_restore
);
builder
.
setRightButtonText
(
R
.
string
.
deck_back_up
);
builder
.
setRightButtonListener
(
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
dialog
.
dismiss
();
doBackUpDeck
();
}
});
builder
.
setLeftButtonListener
(
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
dialog
.
dismiss
();
doRestoreDeck
();
}
});
builder
.
show
();
break
;
// case R.id.action_refresh:
// mDeckAdapater.notifyDataSetChanged();
// break;
case
R
.
id
.
action_search
:
//弹条件对话框
showSearch
(
true
);
break
;
case
R
.
id
.
action_card_list
:
showResult
(
true
);
break
;
case
R
.
id
.
action_share_deck
:
if
(
mDeckAdapater
.
getYdkFile
()
==
null
)
{
Toast
.
makeText
(
this
,
R
.
string
.
unable_to_edit_empty_deck
,
Toast
.
LENGTH_SHORT
).
show
();
return
true
;
}
shareDeck
();
break
;
case
R
.
id
.
action_save
:
if
(
mPreLoadFile
!=
null
&&
mPreLoadFile
==
mDeckAdapater
.
getYdkFile
())
{
//需要保存到deck文件夹
inputDeckName
(
mPreLoadFile
,
null
,
true
);
}
else
{
if
(
mDeckAdapater
.
getYdkFile
()
==
null
)
{
inputDeckName
(
null
,
null
,
true
);
}
else
{
if
(
mDeckAdapater
.
getYdkFile
().
getParent
().
equals
(
mSettings
.
getAiDeckDir
()))
{
Toast
.
makeText
(
this
,
R
.
string
.
donot_editor_bot_Deck
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
save
(
mDeckAdapater
.
getYdkFile
());
}
}
}
break
;
case
R
.
id
.
action_rename
:
if
(
mDeckAdapater
.
getYdkFile
()
==
null
)
{
Toast
.
makeText
(
this
,
R
.
string
.
unable_to_edit_empty_deck
,
Toast
.
LENGTH_SHORT
).
show
();
return
true
;
}
if
(
mDeckAdapater
.
getYdkFile
().
getParent
().
equals
(
mSettings
.
getAiDeckDir
()))
{
Toast
.
makeText
(
this
,
R
.
string
.
donot_editor_bot_Deck
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
inputDeckName
(
mDeckAdapater
.
getYdkFile
(),
mDeckAdapater
.
getYdkFile
().
getParent
(),
false
);
}
break
;
case
R
.
id
.
action_deck_new
:
createDeck
(
null
);
break
;
case
R
.
id
.
action_clear_deck
:
{
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
question_clear_deck
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonListener
((
dlg
,
rs
)
->
{
mDeckAdapater
.
setDeck
(
new
DeckInfo
());
mDeckAdapater
.
notifyDataSetChanged
();
dlg
.
dismiss
();
});
builder
.
show
();
}
break
;
case
R
.
id
.
action_delete_deck
:
{
if
(
mDeckAdapater
.
getYdkFile
()
==
null
)
{
Toast
.
makeText
(
this
,
R
.
string
.
unable_to_edit_empty_deck
,
Toast
.
LENGTH_SHORT
).
show
();
return
true
;
}
if
(
mDeckAdapater
.
getYdkFile
().
getParent
().
equals
(
mSettings
.
getAiDeckDir
()))
{
Toast
.
makeText
(
this
,
R
.
string
.
donot_editor_bot_Deck
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
question_delete_deck
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonListener
((
dlg
,
rs
)
->
{
if
(
mDeckAdapater
.
getYdkFile
()
!=
null
)
{
FileUtils
.
deleteFile
(
mDeckAdapater
.
getYdkFile
());
dlg
.
dismiss
();
File
file
=
getFirstYdk
();
initDecksListSpinners
(
mDeckSpinner
,
file
);
loadDeckFromFile
(
file
);
}
else
{
return
;
}
});
builder
.
show
();
}
}
break
;
case
R
.
id
.
action_unsort
:
//打乱
mDeckAdapater
.
unSort
();
break
;
case
R
.
id
.
action_sort
:
mDeckAdapater
.
sort
();
break
;
default
:
return
false
;
}
return
true
;
}
private
void
createDeck
(
String
savePath
)
{
final
File
old
=
mDeckAdapater
.
getYdkFile
();
DialogPlus
builder
=
new
DialogPlus
(
this
);
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
question_keep_cur_deck
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonListener
((
dlg
,
rs
)
->
{
dlg
.
dismiss
();
//复制当前卡组
inputDeckName
(
old
,
savePath
,
true
);
});
builder
.
setRightButtonListener
((
dlg
,
rs
)
->
{
dlg
.
dismiss
();
setCurDeck
(
null
);
inputDeckName
(
null
,
savePath
,
true
);
});
builder
.
setOnCloseLinster
((
dlg
)
->
{
dlg
.
dismiss
();
setCurDeck
(
null
);
inputDeckName
(
null
,
savePath
,
true
);
});
builder
.
show
();
}
private
File
getFirstYdk
()
{
List
<
File
>
files
=
getYdkFiles
();
return
files
==
null
||
files
.
size
()
==
0
?
null
:
files
.
get
(
0
);
}
private
void
shareDeck
()
{
builderShareLoading
=
new
DialogPlus
(
this
);
builderShareLoading
.
showProgressBar
();
builderShareLoading
.
hideTitleBar
();
builderShareLoading
.
setMessage
(
R
.
string
.
Pre_share
);
builderShareLoading
.
show
();
//先排序
// mDeckAdapater.sort();
//保存
// if (mPreLoadFile != null && mPreLoadFile == mDeckAdapater.getYdkFile()) {
// //需要保存到deck文件夹
// inputDeckName(mPreLoadFile, null, true);
// } else {
// if (mDeckAdapater.getYdkFile() == null) {
// inputDeckName(null, null, true);
// } else {
// save(mDeckAdapater.getYdkFile());
// }
// }
// //保存成功后重新加载卡组
// File file = getSelectDeck(mDeckSpinner);
// if (file != null) {
// loadDeckFromFile(file);
// }
//延时半秒,使整体看起来更流畅
new
Handler
().
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
shareDeck1
();
}
},
500
);
}
private
void
shareDeck1
()
{
//开启绘图缓存
mRecyclerView
.
setDrawingCacheEnabled
(
true
);
//这个方法可调可不调,因为在getDrawingCache()里会自动判断有没有缓存有没有准备好,
//如果没有,会自动调用buildDrawingCache()
mRecyclerView
.
buildDrawingCache
();
//获取绘图缓存 这里直接创建了一个新的bitmap
//因为我们在最后需要释放缓存资源,会释放掉缓存中创建的bitmap对象
Bitmap
bitmap
=
BitmapUtil
.
drawBg4Bitmap
(
Color
.
parseColor
(
"#e6f3fd"
),
Bitmap
.
createBitmap
(
mRecyclerView
.
getDrawingCache
(),
0
,
0
,
mRecyclerView
.
getMeasuredWidth
(),
mRecyclerView
.
getMeasuredHeight
()));
//清理绘图缓存,释放资源
mRecyclerView
.
destroyDrawingCache
();
// shotRecyclerView(mRecyclerView)
Deck
deck
=
mDeckAdapater
.
toDeck
(
mDeckAdapater
.
getYdkFile
());
String
deckName
=
deck
.
getName
();
int
end
=
deckName
.
lastIndexOf
(
"."
);
if
(
end
!=
-
1
)
{
deckName
=
deckName
.
substring
(
0
,
end
);
}
String
savePath
=
new
File
(
AppsSettings
.
get
().
getDeckSharePath
(),
deckName
+
".jpg"
).
getAbsolutePath
();
BitmapUtil
.
saveBitmap
(
bitmap
,
savePath
,
50
);
builderShareLoading
.
dismiss
();
DialogUtils
du
=
DialogUtils
.
getdx
(
DeckManagerActivityImpl
.
this
);
View
viewDialog
=
du
.
dialogBottomSheet
(
R
.
layout
.
dialog_deck_share
,
0
);
ImageView
iv_image
=
viewDialog
.
findViewById
(
R
.
id
.
iv_image
);
Button
bt_image_share
=
viewDialog
.
findViewById
(
R
.
id
.
bt_image_share
);
Button
bt_code_share
=
viewDialog
.
findViewById
(
R
.
id
.
bt_code_share
);
EditText
et_code
=
viewDialog
.
findViewById
(
R
.
id
.
et_code
);
et_code
.
setText
(
mDeckAdapater
.
getDeckInfo
().
toDeck
().
toAppUri
().
toString
());
ImageUtil
.
setImage
(
DeckManagerActivityImpl
.
this
,
savePath
,
iv_image
);
bt_code_share
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
du
.
dis
();
stopService
(
new
Intent
(
DeckManagerActivityImpl
.
this
,
DuelAssistantService
.
class
));
YGOUtil
.
copyMessage
(
DeckManagerActivityImpl
.
this
,
et_code
.
getText
().
toString
().
trim
());
showToast
(
getString
(
R
.
string
.
deck_text_copyed
));
//复制完毕开启决斗助手
YGOUtil
.
startDuelService
(
DeckManagerActivityImpl
.
this
);
}
});
bt_image_share
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
du
.
dis
();
//ShareUtil.shareImage(DeckManagerActivityImpl.this, getContext().getString(R.string.screenshoot), savePath, null);
String
category
=
mDeckAdapater
.
getYdkFile
().
getParent
();
String
fname
=
deck
.
getName
();
Intent
intent
=
new
Intent
(
ACTION_SHARE_FILE
);
intent
.
addCategory
(
Intent
.
CATEGORY_DEFAULT
);
intent
.
putExtra
(
IrrlichtBridge
.
EXTRA_SHARE_TYPE
,
"ydk"
);
if
(
category
.
equals
(
mSettings
.
getDeckDir
()))
{
intent
.
putExtra
(
IrrlichtBridge
.
EXTRA_SHARE_FILE
,
fname
);
}
else
{
String
cname
=
DeckUtil
.
getDeckTypeName
(
mDeckAdapater
.
getYdkFile
().
getAbsolutePath
());
intent
.
putExtra
(
IrrlichtBridge
.
EXTRA_SHARE_FILE
,
cname
+
"/"
+
fname
);
}
intent
.
setPackage
(
getPackageName
());
try
{
startActivity
(
intent
);
}
catch
(
Throwable
e
)
{
Toast
.
makeText
(
getContext
(),
"dev error:not found activity."
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
});
//复制前关闭决斗助手
// String label = TextUtils.isEmpty(deck.getName()) ? getString(R.string.share_deck) : deck.getName();
// final String uriString = deck.toAppUri().toString();
// final String httpUri = deck.toHttpUri().toString();
// shareUrl(uriString, label);
}
private
void
shareUrl
(
String
uri
,
String
label
)
{
String
url
=
getString
(
R
.
string
.
deck_share_head
)
+
" "
+
uri
;
ShareUtil
.
shareText
(
this
,
getString
(
R
.
string
.
share_deck
),
url
,
null
);
ClipboardManager
clipboardManager
=
(
ClipboardManager
)
getSystemService
(
CLIPBOARD_SERVICE
);
if
(
Build
.
VERSION
.
SDK_INT
>
19
)
{
clipboardManager
.
setPrimaryClip
(
ClipData
.
newPlainText
(
label
,
uri
));
}
else
{
clipboardManager
.
setText
(
uri
);
}
showToast
(
R
.
string
.
copy_to_clipbroad
,
Toast
.
LENGTH_SHORT
);
}
private
File
getSelectDeck
(
Spinner
spinner
)
{
Object
o
=
SimpleSpinnerAdapter
.
getSelectTag
(
spinner
);
if
(
o
!=
null
&&
o
instanceof
File
)
{
return
(
File
)
o
;
}
return
null
;
}
// private LimitList getSelectLimitList(Spinner spinner) {
// int val = (int) SimpleSpinnerAdapter.getSelect(spinner);
// if (val > 0) {
// return mLimitManager.getLimit(val);
// }
// return null;
// }
private
List
<
File
>
getYdkFiles
()
{
File
dir
=
new
File
(
mSettings
.
getResourcePath
(),
Constants
.
CORE_DECK_PATH
);
File
[]
files
=
dir
.
listFiles
((
file
,
s
)
->
{
return
s
.
toLowerCase
(
Locale
.
US
).
endsWith
(
Constants
.
YDK_FILE_EX
);
});
if
(
files
!=
null
)
{
List
<
File
>
list
=
new
ArrayList
<>(
Arrays
.
asList
(
files
));
if
(
mPreLoadFile
!=
null
&&
mPreLoadFile
.
exists
())
{
boolean
hasCur
=
false
;
for
(
File
f
:
list
)
{
if
(
TextUtils
.
equals
(
f
.
getAbsolutePath
(),
mPreLoadFile
.
getAbsolutePath
()))
{
hasCur
=
true
;
break
;
}
}
if
(!
hasCur
)
{
list
.
add
(
mPreLoadFile
);
}
}
return
list
;
}
return
null
;
}
private
void
initDecksListSpinners
(
Spinner
spinner
,
File
curYdk
)
{
List
<
File
>
files
=
getYdkFiles
();
List
<
SimpleSpinnerItem
>
items
=
new
ArrayList
<>();
String
name
=
curYdk
!=
null
?
curYdk
.
getName
()
:
null
;
int
index
=
-
1
;
if
(
files
!=
null
)
{
Collections
.
sort
(
files
,
new
Comparator
<
File
>()
{
@Override
public
int
compare
(
File
ydk1
,
File
ydk2
)
{
if
(
ydk1
.
isDirectory
()
&&
ydk2
.
isFile
())
return
-
1
;
if
(
ydk1
.
isFile
()
&&
ydk2
.
isDirectory
())
return
1
;
return
ydk1
.
getName
().
compareTo
(
ydk2
.
getName
());
}
});
int
i
=
0
;
for
(
File
file
:
files
)
{
if
(
name
!=
null
&&
TextUtils
.
equals
(
name
,
file
.
getName
()))
{
index
=
i
;
}
String
filename
=
IOUtils
.
tirmName
(
file
.
getName
(),
Constants
.
YDK_FILE_EX
);
items
.
add
(
new
SimpleSpinnerItem
(
i
++,
filename
).
setTag
(
file
));
}
}
mSimpleSpinnerAdapter
=
new
SimpleSpinnerAdapter
(
this
);
mSimpleSpinnerAdapter
.
set
(
items
);
mSimpleSpinnerAdapter
.
setColor
(
Color
.
WHITE
);
mSimpleSpinnerAdapter
.
setSingleLine
(
true
);
spinner
.
setAdapter
(
mSimpleSpinnerAdapter
);
if
(
index
>=
0
)
{
spinner
.
setSelection
(
index
);
}
}
// private void initLimitListSpinners(Spinner spinner) {
// List<SimpleSpinnerItem> items = new ArrayList<>();
// List<Integer> ids = mLimitManager.getLists();
// int index = -1;
// int i = 0;
// for (Integer id : ids) {
// LimitList list = mLimitManager.getLimitFromIndex(id);
// if (list == mLimitList) {
// index = i;
// }
// items.add(new SimpleSpinnerItem(id, list.getName()));
// i++;
// }
// SimpleSpinnerAdapter adapter = new SimpleSpinnerAdapter(this);
// adapter.set(items);
// spinner.setAdapter(adapter);
// if (index >= 0) {
// spinner.setSelection(index);
// }
private
void
initLimitListSpinners
(
Spinner
spinner
,
LimitList
cur
)
{
List
<
SimpleSpinnerItem
>
items
=
new
ArrayList
<>();
List
<
String
>
limitLists
=
mLimitManager
.
getLimitNames
();
int
index
=
-
1
;
int
count
=
mLimitManager
.
getCount
();
items
.
add
(
new
SimpleSpinnerItem
(
0
,
getString
(
R
.
string
.
label_limitlist
)));
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
int
j
=
i
+
1
;
String
name
=
limitLists
.
get
(
i
);
items
.
add
(
new
SimpleSpinnerItem
(
j
,
name
));
if
(
cur
!=
null
&&
TextUtils
.
equals
(
cur
.
getName
(),
name
))
{
index
=
j
;
}
}
SimpleSpinnerAdapter
adapter
=
new
SimpleSpinnerAdapter
(
this
);
adapter
.
setColor
(
Color
.
WHITE
);
adapter
.
set
(
items
);
spinner
.
setAdapter
(
adapter
);
if
(
index
>=
0
)
{
spinner
.
setSelection
(
index
);
}
spinner
.
setOnItemSelectedListener
(
new
AdapterView
.
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
setLimitList
(
mLimitManager
.
getLimit
(
SimpleSpinnerAdapter
.
getSelectText
(
spinner
)));
}
@Override
public
void
onNothingSelected
(
AdapterView
<?>
parent
)
{
}
});
}
private
void
setLimitList
(
LimitList
limitList
)
{
if
(
limitList
==
null
)
return
;
LimitList
last
=
mDeckAdapater
.
getLimitList
();
boolean
nochanged
=
last
!=
null
&&
TextUtils
.
equals
(
last
.
getName
(),
limitList
.
getName
());
if
(!
nochanged
)
{
mDeckAdapater
.
setLimitList
(
limitList
);
runOnUiThread
(()
->
{
mDeckAdapater
.
notifyItemRangeChanged
(
DeckItem
.
MainStart
,
DeckItem
.
MainEnd
);
mDeckAdapater
.
notifyItemRangeChanged
(
DeckItem
.
ExtraStart
,
DeckItem
.
ExtraEnd
);
mDeckAdapater
.
notifyItemRangeChanged
(
DeckItem
.
SideStart
,
DeckItem
.
SideEnd
);
});
}
mCardListAdapater
.
setLimitList
(
limitList
);
runOnUiThread
(()
->
{
mCardListAdapater
.
notifyDataSetChanged
();
});
}
private
void
inputDeckName
(
File
oldYdk
,
String
savePath
,
boolean
keepOld
)
{
DialogPlus
builder
=
new
DialogPlus
(
this
);
builder
.
setTitle
(
R
.
string
.
intpu_name
);
EditText
editText
=
new
EditText
(
this
);
editText
.
setGravity
(
Gravity
.
TOP
|
Gravity
.
LEFT
);
editText
.
setInputType
(
InputType
.
TYPE_TEXT_FLAG_NO_SUGGESTIONS
);
editText
.
setSingleLine
();
if
(
oldYdk
!=
null
)
{
editText
.
setText
(
oldYdk
.
getName
());
}
builder
.
setContentView
(
editText
);
builder
.
setOnCloseLinster
((
dlg
)
->
{
dlg
.
dismiss
();
});
builder
.
setLeftButtonListener
((
dlg
,
s
)
->
{
CharSequence
name
=
editText
.
getText
();
if
(!
TextUtils
.
isEmpty
(
name
))
{
String
filename
=
String
.
valueOf
(
name
);
if
(!
filename
.
endsWith
(
YDK_FILE_EX
))
{
filename
+=
YDK_FILE_EX
;
}
File
ydk
;
if
(
TextUtils
.
isEmpty
(
savePath
))
ydk
=
new
File
(
mSettings
.
getDeckDir
(),
filename
);
else
ydk
=
new
File
(
savePath
,
filename
);
if
(
ydk
.
exists
())
{
showToast
(
R
.
string
.
file_exist
,
Toast
.
LENGTH_SHORT
);
return
;
}
if
(!
keepOld
&&
oldYdk
!=
null
&&
oldYdk
.
exists
())
{
if
(
oldYdk
.
renameTo
(
ydk
))
{
initDecksListSpinners
(
mDeckSpinner
,
ydk
);
dlg
.
dismiss
();
loadDeckFromFile
(
ydk
);
}
}
else
{
if
(
oldYdk
==
mPreLoadFile
)
{
mPreLoadFile
=
null
;
}
dlg
.
dismiss
();
try
{
ydk
.
createNewFile
();
}
catch
(
IOException
e
)
{
}
initDecksListSpinners
(
mDeckSpinner
,
ydk
);
save
(
ydk
);
loadDeckFromFile
(
ydk
);
}
}
else
{
dlg
.
dismiss
();
}
});
builder
.
show
();
}
private
void
save
(
File
ydk
)
{
if
(
mDeckAdapater
.
save
(
ydk
))
{
showToast
(
R
.
string
.
save_tip_ok
,
Toast
.
LENGTH_SHORT
);
}
else
{
showToast
(
R
.
string
.
save_tip_fail
,
Toast
.
LENGTH_SHORT
);
}
}
private
void
initBoomMenuButton
(
BoomMenuButton
menu
)
{
final
SparseArray
<
Integer
>
mMenuIds
=
new
SparseArray
<>();
// addMenuButton(mMenuIds, menu, R.id.action_card_search, R.string.deck_list, R.drawable.listicon);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_share_deck
,
R
.
string
.
share_deck
,
R
.
drawable
.
shareicon
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_save
,
R
.
string
.
save_deck
,
R
.
drawable
.
save
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_clear_deck
,
R
.
string
.
clear_deck
,
R
.
drawable
.
clear_deck
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_deck_new
,
R
.
string
.
new_deck
,
R
.
drawable
.
addsever
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_rename
,
R
.
string
.
rename_deck
,
R
.
drawable
.
rename
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_delete_deck
,
R
.
string
.
delete_deck
,
R
.
drawable
.
delete
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_unsort
,
R
.
string
.
unsort
,
R
.
drawable
.
unsort
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_sort
,
R
.
string
.
sort
,
R
.
drawable
.
sort
);
addMenuButton
(
mMenuIds
,
menu
,
R
.
id
.
action_deck_backup_n_restore
,
R
.
string
.
deck_backup_n_restore
,
R
.
drawable
.
downloadimages
);
//设置展开或隐藏的延时。 默认值为 800ms。
menu
.
setDuration
(
150
);
//设置每两个子按钮之间动画的延时(ms为单位)。 比如,如果延时设为0,那么所有子按钮都会同时展开或隐藏,默认值为100ms。
menu
.
setDelay
(
10
);
menu
.
setOnBoomListener
(
new
DefaultOnBoomListener
()
{
@Override
public
void
onClicked
(
int
index
,
BoomButton
boomButton
)
{
doMenu
(
mMenuIds
.
get
(
index
));
}
});
}
private
void
addMenuButton
(
SparseArray
<
Integer
>
mMenuIds
,
BoomMenuButton
menuButton
,
int
menuId
,
int
stringId
,
int
image
)
{
addMenuButton
(
mMenuIds
,
menuButton
,
menuId
,
getString
(
stringId
),
image
);
}
private
void
addMenuButton
(
SparseArray
<
Integer
>
mMenuIds
,
BoomMenuButton
menuButton
,
int
menuId
,
String
str
,
int
image
)
{
TextOutsideCircleButton
.
Builder
builder
=
new
TextOutsideCircleButton
.
Builder
()
.
shadowColor
(
Color
.
TRANSPARENT
)
.
normalColor
(
Color
.
TRANSPARENT
)
.
normalImageRes
(
image
)
.
normalText
(
str
);
menuButton
.
addBuilder
(
builder
);
mMenuIds
.
put
(
mMenuIds
.
size
(),
menuId
);
}
private
void
doBackUpDeck
()
{
try
{
FileUtils
.
copyDir
(
mSettings
.
getDeckDir
(),
ORI_DECK
,
true
);
}
catch
(
Throwable
e
)
{
Toast
.
makeText
(
getContext
(),
e
+
""
,
Toast
.
LENGTH_SHORT
).
show
();
}
Toast
.
makeText
(
getContext
(),
R
.
string
.
done
,
Toast
.
LENGTH_SHORT
).
show
();
}
private
void
doRestoreDeck
()
{
try
{
FileUtils
.
copyDir
(
ORI_DECK
,
mSettings
.
getDeckDir
(),
false
);
}
catch
(
Throwable
e
)
{
Toast
.
makeText
(
getContext
(),
e
+
""
,
Toast
.
LENGTH_SHORT
).
show
();
}
Toast
.
makeText
(
getContext
(),
R
.
string
.
done
,
Toast
.
LENGTH_SHORT
).
show
();
}
@Override
public
void
onDeckSelect
(
DeckFile
deckFile
)
{
loadDeckFromFile
(
new
File
(
deckFile
.
getPath
()));
}
@Override
public
void
onDeckDel
(
List
<
DeckFile
>
deckFileList
)
{
File
deck
=
mDeckAdapater
.
getYdkFile
();
if
(
deck
==
null
)
return
;
String
currentDeckPath
=
deck
.
getAbsolutePath
();
for
(
DeckFile
deckFile
:
deckFileList
)
{
if
(
deckFile
.
getPath
().
equals
(
currentDeckPath
))
{
List
<
File
>
files
=
getYdkFiles
();
File
file
=
null
;
if
(
files
!=
null
&&
files
.
size
()
>
0
)
{
file
=
files
.
get
(
0
);
}
if
(
file
!=
null
)
{
loadDeckFromFile
(
file
);
}
else
{
setCurDeck
(
new
DeckInfo
());
}
return
;
}
}
}
@Override
public
void
onDeckMove
(
List
<
DeckFile
>
deckFileList
,
DeckType
toDeckType
)
{
String
currentDeckPath
=
mDeckAdapater
.
getYdkFile
().
getAbsolutePath
();
if
(
currentDeckPath
!=
null
)
{
for
(
DeckFile
deckFile
:
deckFileList
)
{
if
(
deckFile
.
getPath
().
equals
(
currentDeckPath
))
{
loadDeckFromFile
(
new
File
(
toDeckType
.
getPath
(),
deckFile
.
getName
()
+
".ydk"
));
return
;
}
}
}
}
@Override
public
void
onDeckCopy
(
List
<
DeckFile
>
deckFileList
,
DeckType
toDeckType
)
{
String
currentDeckPath
=
mDeckAdapater
.
getYdkFile
().
getAbsolutePath
();
for
(
DeckFile
deckFile
:
deckFileList
)
{
if
(
deckFile
.
getPath
().
equals
(
currentDeckPath
))
{
loadDeckFromFile
(
new
File
(
toDeckType
.
getPath
(),
deckFile
.
getName
()
+
".ydk"
));
return
;
}
}
}
@Override
public
void
onDeckNew
(
DeckType
currentDeckType
)
{
createDeck
(
currentDeckType
.
getPath
());
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivityImpl2.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards
;
import
android.content.ClipData
;
import
android.content.ClipboardManager
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.text.InputType
;
import
android.text.TextUtils
;
import
android.view.Gravity
;
import
android.view.Menu
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.CheckBox
;
import
android.widget.CompoundButton
;
import
android.widget.EditText
;
import
android.widget.Spinner
;
import
android.widget.Toast
;
import
androidx.annotation.Nullable
;
import
androidx.appcompat.app.ActionBarDrawerToggle
;
import
androidx.appcompat.widget.AppCompatSpinner
;
import
androidx.appcompat.widget.RecyclerViewItemListener
;
import
androidx.appcompat.widget.Toolbar
;
import
androidx.drawerlayout.widget.DrawerLayout
;
import
androidx.recyclerview.widget.FastScrollLinearLayoutManager
;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.bumptech.glide.Glide
;
import
org.greenrobot.eventbus.EventBus
;
import
org.greenrobot.eventbus.Subscribe
;
import
org.greenrobot.eventbus.ThreadMode
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Locale
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.bean.DeckInfo
;
import
cn.garymb.ygomobile.bean.events.CardInfoEvent
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.loader.CardLoader
;
import
cn.garymb.ygomobile.loader.DeckLoader
;
import
cn.garymb.ygomobile.loader.ImageLoader
;
import
cn.garymb.ygomobile.ui.activities.BaseActivity
;
import
cn.garymb.ygomobile.ui.adapters.CardListAdapter
;
import
cn.garymb.ygomobile.ui.adapters.SimpleSpinnerAdapter
;
import
cn.garymb.ygomobile.ui.adapters.SimpleSpinnerItem
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckUtils
;
import
cn.garymb.ygomobile.ui.plus.DialogPlus
;
import
cn.garymb.ygomobile.ui.plus.VUiKit
;
import
cn.garymb.ygomobile.ui.widget.DeckGroupView
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
cn.garymb.ygomobile.utils.ShareUtil
;
import
ocgcore.DataManager
;
import
ocgcore.LimitManager
;
import
ocgcore.StringManager
;
import
ocgcore.data.Card
;
import
ocgcore.data.LimitList
;
import
ocgcore.enums.LimitType
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
YDK_FILE_EX
;
class
DeckManagerActivityImpl2
extends
BaseActivity
implements
CardLoader
.
CallBack
{
private
DeckGroupView
mDeckView
;
protected
CardSearcher
mCardSelector
;
protected
StringManager
mStringManager
=
DataManager
.
get
().
getStringManager
();
protected
LimitManager
mLimitManager
=
DataManager
.
get
().
getLimitManager
();
protected
CardLoader
mCardLoader
;
protected
boolean
isLoad
=
false
;
private
String
mPreLoad
;
private
LimitList
mLimitList
;
private
File
mYdkFile
;
private
ImageLoader
mImageLoader
;
private
AppsSettings
mSettings
=
AppsSettings
.
get
();
private
AppCompatSpinner
mLimitSpinner
;
private
AppCompatSpinner
mDeckSpinner
;
private
SimpleSpinnerAdapter
mSimpleSpinnerAdapter
;
protected
DrawerLayout
mDrawerlayout
;
private
RecyclerView
mListView
;
protected
CardListAdapter
mCardListAdapater
;
private
String
mDeckMd5
;
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_deck_cards2
);
Toolbar
toolbar
=
$
(
R
.
id
.
toolbar
);
setSupportActionBar
(
toolbar
);
enableBackHome
();
mLimitSpinner
=
$
(
R
.
id
.
sp_limit_list
);
mDeckSpinner
=
$
(
R
.
id
.
toolbar_list
);
mDeckView
=
$
(
R
.
id
.
deck_group
);
mDrawerlayout
=
$
(
R
.
id
.
drawer_layout
);
mImageLoader
=
ImageLoader
.
get
(
this
);
mCardLoader
=
new
CardLoader
(
this
);
mCardLoader
.
setCallBack
(
this
);
mCardSelector
=
new
CardSearcher
(
$
(
R
.
id
.
nav_view_list
),
mCardLoader
);
mListView
=
$
(
R
.
id
.
list_cards
);
mCardListAdapater
=
new
CardListAdapter
(
this
,
mImageLoader
);
mCardListAdapater
.
setEnableSwipe
(
true
);
mListView
.
setLayoutManager
(
new
FastScrollLinearLayoutManager
(
this
));
mListView
.
setAdapter
(
mCardListAdapater
);
setListeners
();
//
ActionBarDrawerToggle
toggle
=
new
ActionBarDrawerToggle
(
this
,
mDrawerlayout
,
toolbar
,
R
.
string
.
search_open
,
R
.
string
.
search_close
);
toggle
.
setDrawerIndicatorEnabled
(
false
);
mDrawerlayout
.
addDrawerListener
(
toggle
);
toggle
.
setToolbarNavigationClickListener
((
v
)
->
{
onBackHome
();
});
toggle
.
syncState
();
mDeckSpinner
.
setOnItemSelectedListener
(
new
AdapterView
.
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
AdapterView
<?>
adapterView
,
View
view
,
int
i
,
long
l
)
{
File
file
=
getSelectDeck
(
mDeckSpinner
);
if
(
file
!=
null
)
{
loadDeck
(
file
);
}
}
@Override
public
void
onNothingSelected
(
AdapterView
<?>
adapterView
)
{
}
});
if
(
getIntent
().
hasExtra
(
Intent
.
EXTRA_TEXT
))
{
String
path
=
getIntent
().
getStringExtra
(
Intent
.
EXTRA_TEXT
);
if
(!
TextUtils
.
isEmpty
(
path
))
{
mPreLoad
=
path
;
}
}
View
btnDel
=
$
(
R
.
id
.
btn_delete
);
CheckBox
checkBox
=
$
(
R
.
id
.
chk_autosort
);
mDeckView
.
setAutoSort
(
checkBox
.
isChecked
());
checkBox
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
@Override
public
void
onCheckedChanged
(
CompoundButton
buttonView
,
boolean
isChecked
)
{
mDeckView
.
setAutoSort
(
isChecked
);
}
});
$
(
R
.
id
.
btn_edit_delete
).
setOnClickListener
(
v
->
{
if
(
mDeckView
.
getEditMode
()
!=
DeckGroupView
.
EditMode
.
None
)
{
mDeckView
.
setEditMode
(
DeckGroupView
.
EditMode
.
None
);
btnDel
.
setEnabled
(
false
);
}
else
{
mDeckView
.
setEditMode
(
DeckGroupView
.
EditMode
.
Delete
);
btnDel
.
setEnabled
(
true
);
}
});
$
(
R
.
id
.
btn_edit_main2side
).
setOnClickListener
(
v
->
{
if
(
mDeckView
.
getEditMode
()
!=
DeckGroupView
.
EditMode
.
None
)
{
mDeckView
.
setEditMode
(
DeckGroupView
.
EditMode
.
None
);
btnDel
.
setEnabled
(
false
);
}
else
{
mDeckView
.
setEditMode
(
DeckGroupView
.
EditMode
.
Main2Side
);
btnDel
.
setEnabled
(
true
);
}
});
$
(
R
.
id
.
btn_edit_side2main
).
setOnClickListener
(
v
->
{
if
(
mDeckView
.
getEditMode
()
!=
DeckGroupView
.
EditMode
.
None
)
{
mDeckView
.
setEditMode
(
DeckGroupView
.
EditMode
.
None
);
btnDel
.
setEnabled
(
false
);
}
else
{
mDeckView
.
setEditMode
(
DeckGroupView
.
EditMode
.
Side2Main
);
btnDel
.
setEnabled
(
true
);
}
});
btnDel
.
setOnClickListener
((
v
)
->
{
if
(
mDeckView
.
getEditMode
()
!=
DeckGroupView
.
EditMode
.
None
)
{
mDeckView
.
completedEdit
();
mDeckView
.
notifyDataSetChanged
();
}
});
EventBus
.
getDefault
().
register
(
this
);
DialogPlus
dlg
=
DialogPlus
.
show
(
this
,
null
,
getString
(
R
.
string
.
loading
));
VUiKit
.
defer
().
when
(()
->
{
DataManager
.
get
().
load
(
false
);
if
(
mLimitManager
.
getCount
()
>
0
)
{
mCardLoader
.
setLimitList
(
mLimitManager
.
getTopLimit
());
}
File
file
=
new
File
(
mSettings
.
getLastDeckPath
());
if
(!
TextUtils
.
isEmpty
(
mPreLoad
))
{
file
=
new
File
(
mPreLoad
);
mPreLoad
=
null
;
}
if
(!
file
.
exists
())
{
//当默认卡组不存在的时候
File
[]
files
=
getYdkFiles
();
if
(
files
!=
null
&&
files
.
length
>
0
)
{
file
=
files
[
0
];
}
}
//EXTRA_DECK
if
(
file
==
null
)
{
return
new
DeckInfo
();
}
mYdkFile
=
file
;
if
(
mCardLoader
.
isOpen
()
&&
file
.
exists
())
{
return
DeckLoader
.
readDeck
(
mCardLoader
,
file
,
mLimitList
);
}
else
{
return
new
DeckInfo
();
}
}).
done
((
rs
)
->
{
isLoad
=
true
;
dlg
.
dismiss
();
mCardSelector
.
initItems
();
mLimitList
=
mCardLoader
.
getLimitList
();
isLoad
=
true
;
setCurYdkFile
(
mYdkFile
,
false
);
initLimitListSpinners
(
mLimitSpinner
);
initDecksListSpinners
(
mDeckSpinner
);
mDeckView
.
setDeck
(
rs
);
mDeckMd5
=
rs
.
makeMd5
();
mDeckView
.
notifyDataSetChanged
();
});
}
@Override
protected
void
onDestroy
()
{
ImageLoader
.
onDestory
(
this
);
EventBus
.
getDefault
().
unregister
(
this
);
super
.
onDestroy
();
}
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
public
void
onCardInfoEvent
(
CardInfoEvent
event
)
{
int
pos
=
event
.
position
;
Card
cardInfo
=
mCardListAdapater
.
getItem
(
pos
);
if
(
cardInfo
==
null
)
{
mCardListAdapater
.
hideMenu
(
null
);
}
else
if
(
event
.
toMain
)
{
if
(!
addMainCard
(
cardInfo
))
{
// || !checkLimit(cardInfo, false)) {
mCardListAdapater
.
hideMenu
(
null
);
}
}
else
{
if
(!
addSideCard
(
cardInfo
))
{
// || !checkLimit(cardInfo, false)) {
mCardListAdapater
.
hideMenu
(
null
);
}
}
}
private
File
getSelectDeck
(
Spinner
spinner
)
{
Object
o
=
SimpleSpinnerAdapter
.
getSelectTag
(
spinner
);
if
(
o
!=
null
&&
o
instanceof
File
)
{
return
(
File
)
o
;
}
return
null
;
}
private
void
loadDeck
(
File
file
)
{
loadDeck
(
file
,
false
);
}
private
void
loadDeck
(
File
file
,
boolean
noSaveLast
)
{
DialogPlus
dlg
=
DialogPlus
.
show
(
this
,
null
,
getString
(
R
.
string
.
loading
));
VUiKit
.
defer
().
when
(()
->
{
if
(
file
==
null
)
{
return
new
DeckInfo
();
}
if
(
mCardLoader
.
isOpen
()
&&
file
.
exists
())
{
return
DeckLoader
.
readDeck
(
mCardLoader
,
file
,
mLimitList
);
}
else
{
return
new
DeckInfo
();
}
}).
done
((
rs
)
->
{
dlg
.
dismiss
();
setCurYdkFile
(
file
,
noSaveLast
);
mDeckView
.
setDeck
(
rs
);
mDeckMd5
=
rs
.
makeMd5
();
mDeckView
.
notifyDataSetChanged
();
});
}
private
void
initDecksListSpinners
(
Spinner
spinner
)
{
File
[]
files
=
getYdkFiles
();
List
<
SimpleSpinnerItem
>
items
=
new
ArrayList
<>();
String
name
=
mYdkFile
!=
null
?
mYdkFile
.
getName
()
:
null
;
int
index
=
-
1
;
if
(
files
!=
null
)
{
int
i
=
0
;
for
(
File
file
:
files
)
{
if
(
name
!=
null
&&
TextUtils
.
equals
(
name
,
file
.
getName
()))
{
index
=
i
;
}
String
filename
=
IOUtils
.
tirmName
(
file
.
getName
(),
YDK_FILE_EX
);
items
.
add
(
new
SimpleSpinnerItem
(
i
++,
filename
).
setTag
(
file
));
}
}
mSimpleSpinnerAdapter
=
new
SimpleSpinnerAdapter
(
this
);
mSimpleSpinnerAdapter
.
set
(
items
);
mSimpleSpinnerAdapter
.
setColor
(
Color
.
WHITE
);
mSimpleSpinnerAdapter
.
setSingleLine
(
true
);
spinner
.
setAdapter
(
mSimpleSpinnerAdapter
);
if
(
index
>=
0
)
{
spinner
.
setSelection
(
index
);
}
}
private
void
initLimitListSpinners
(
Spinner
spinner
)
{
List
<
SimpleSpinnerItem
>
items
=
new
ArrayList
<>();
List
<
String
>
limitLists
=
mLimitManager
.
getLimitNames
();
int
index
=
-
1
;
int
count
=
mLimitManager
.
getCount
();
LimitList
cur
=
mLimitList
;
items
.
add
(
new
SimpleSpinnerItem
(
0
,
getString
(
R
.
string
.
label_limitlist
)));
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
int
j
=
i
+
1
;
String
name
=
limitLists
.
get
(
i
);
items
.
add
(
new
SimpleSpinnerItem
(
j
,
name
));
if
(
cur
!=
null
&&
TextUtils
.
equals
(
cur
.
getName
(),
name
))
{
index
=
j
;
}
}
SimpleSpinnerAdapter
adapter
=
new
SimpleSpinnerAdapter
(
this
);
adapter
.
setColor
(
Color
.
WHITE
);
adapter
.
set
(
items
);
spinner
.
setAdapter
(
adapter
);
if
(
index
>=
0
)
{
spinner
.
setSelection
(
index
);
}
spinner
.
setOnItemSelectedListener
(
new
AdapterView
.
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
setLimitList
(
mLimitManager
.
getLimit
(
SimpleSpinnerAdapter
.
getSelectText
(
spinner
)));
}
@Override
public
void
onNothingSelected
(
AdapterView
<?>
parent
)
{
}
});
}
private
void
setLimitList
(
LimitList
limitList
)
{
if
(
limitList
==
null
)
return
;
boolean
nochanged
=
mLimitList
!=
null
&&
TextUtils
.
equals
(
mLimitList
.
getName
(),
limitList
.
getName
());
mLimitList
=
limitList
;
mDeckView
.
setLimitList
(
limitList
);
runOnUiThread
(()
->
{
mDeckView
.
notifyDataSetChanged
();
});
}
private
void
setCurYdkFile
(
File
file
)
{
setCurYdkFile
(
file
,
false
);
}
private
void
setCurYdkFile
(
File
file
,
boolean
noSaveLast
)
{
mYdkFile
=
file
;
if
(
file
!=
null
&&
file
.
exists
())
{
String
name
=
IOUtils
.
tirmName
(
file
.
getName
(),
YDK_FILE_EX
);
setActionBarSubTitle
(
name
);
if
(!
noSaveLast
)
{
mSettings
.
setLastDeckPath
(
file
.
getAbsolutePath
());
}
}
else
{
setActionBarSubTitle
(
getString
(
R
.
string
.
noname
));
}
}
private
File
[]
getYdkFiles
()
{
File
dir
=
new
File
(
mSettings
.
getResourcePath
(),
Constants
.
CORE_DECK_PATH
);
File
[]
files
=
dir
.
listFiles
((
file
,
s
)
->
{
return
s
.
toLowerCase
(
Locale
.
US
).
endsWith
(
YDK_FILE_EX
);
});
return
files
;
}
@Override
public
void
onSearchStart
()
{
hideDrawers
();
}
@Override
public
void
onLimitListChanged
(
LimitList
limitList
)
{
}
@Override
public
void
onSearchResult
(
List
<
Card
>
cardInfos
,
boolean
isHide
)
{
mCardListAdapater
.
set
(
cardInfos
);
mCardListAdapater
.
notifyDataSetChanged
();
if
(
cardInfos
!=
null
&&
cardInfos
.
size
()
>
0
)
{
mListView
.
smoothScrollToPosition
(
0
);
}
showResult
(
false
);
}
@Override
public
void
onResetSearch
()
{
}
@Override
public
boolean
onCreateOptionsMenu
(
Menu
menu
)
{
getMenuInflater
().
inflate
(
R
.
menu
.
deck_menu
,
menu
);
return
true
;
}
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
switch
(
item
.
getItemId
())
{
// case R.id.action_refresh:
// mDeckAdapater.notifyDataSetChanged();
// break;
case
R
.
id
.
action_search
:
//弹条件对话框
showSearch
(
true
);
break
;
case
R
.
id
.
action_card_list
:
showResult
(
true
);
break
;
case
R
.
id
.
action_save
:
if
(
mYdkFile
==
null
)
{
inputDeckName
(
null
);
}
else
{
save
();
}
break
;
case
R
.
id
.
action_rename
:
inputDeckName
(
null
);
break
;
case
R
.
id
.
action_deck_new
:
{
final
String
old
=
mYdkFile
==
null
?
null
:
mYdkFile
.
getAbsolutePath
();
setCurYdkFile
(
null
);
DialogPlus
builder
=
new
DialogPlus
(
this
);
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
question_keep_cur_deck
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonListener
((
dlg
,
rs
)
->
{
dlg
.
dismiss
();
inputDeckName
(
old
);
});
builder
.
setRightButtonListener
((
dlg
,
rs
)
->
{
dlg
.
dismiss
();
loadDeck
(
null
);
inputDeckName
(
old
);
});
builder
.
setOnCloseLinster
((
dlg
)
->
{
dlg
.
dismiss
();
loadDeck
(
null
);
inputDeckName
(
old
);
});
builder
.
show
();
}
break
;
case
R
.
id
.
action_clear_deck
:
{
DialogPlus
builder
=
new
DialogPlus
(
this
);
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
question_clear_deck
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonListener
((
dlg
,
rs
)
->
{
mDeckView
.
setDeck
(
new
DeckInfo
());
mDeckMd5
=
mDeckView
.
getDeckInfo
().
makeMd5
();
mDeckView
.
notifyDataSetChanged
();
dlg
.
dismiss
();
});
builder
.
show
();
}
break
;
case
R
.
id
.
action_delete_deck
:
{
DialogPlus
builder
=
new
DialogPlus
(
this
);
builder
.
setTitle
(
R
.
string
.
question
);
builder
.
setMessage
(
R
.
string
.
question_delete_deck
);
builder
.
setMessageGravity
(
Gravity
.
CENTER_HORIZONTAL
);
builder
.
setLeftButtonListener
((
dlg
,
rs
)
->
{
if
(
mYdkFile
!=
null
&&
mYdkFile
.
exists
())
{
mYdkFile
.
delete
();
}
dlg
.
dismiss
();
initDecksListSpinners
(
mDeckSpinner
);
loadDeck
(
null
);
});
builder
.
show
();
}
break
;
case
R
.
id
.
action_unsort
:
//打乱
mDeckView
.
unSort
();
mDeckView
.
notifyDataSetChanged
();
break
;
case
R
.
id
.
action_sort
:
mDeckView
.
sort
();
mDeckView
.
notifyDataSetChanged
();
break
;
}
return
super
.
onOptionsItemSelected
(
item
);
}
private
void
shareDeck
()
{
// DeckUtils.save(mDeckView.getDeckInfo(), mYdkFile);
// String label = TextUtils.isEmpty(deck.getName()) ? getString(R.string.share_deck) : deck.getName();
// final String uriString = deck.toAppUri().toString();
// final String httpUri = deck.toHttpUri().toString();
// shareUrl(uriString, label);
}
private
void
shareUrl
(
String
uri
,
String
label
)
{
String
url
=
getString
(
R
.
string
.
deck_share_head
)
+
" "
+
uri
;
ShareUtil
.
shareText
(
this
,
getString
(
R
.
string
.
share_deck
),
url
,
null
);
ClipboardManager
clipboardManager
=
(
ClipboardManager
)
getSystemService
(
CLIPBOARD_SERVICE
);
if
(
Build
.
VERSION
.
SDK_INT
>
19
)
{
clipboardManager
.
setPrimaryClip
(
ClipData
.
newPlainText
(
label
,
uri
));
}
else
{
clipboardManager
.
setText
(
uri
);
}
showToast
(
R
.
string
.
copy_to_clipbroad
,
Toast
.
LENGTH_SHORT
);
}
private
void
inputDeckName
(
String
old
)
{
DialogPlus
builder
=
new
DialogPlus
(
this
);
// AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.
setTitle
(
R
.
string
.
intpu_name
);
EditText
editText
=
new
EditText
(
this
);
editText
.
setGravity
(
Gravity
.
TOP
|
Gravity
.
LEFT
);
editText
.
setInputType
(
InputType
.
TYPE_TEXT_FLAG_NO_SUGGESTIONS
);
editText
.
setSingleLine
();
if
(
mYdkFile
!=
null
)
{
editText
.
setText
(
mYdkFile
.
getName
());
}
builder
.
setContentView
(
editText
);
builder
.
setOnCloseLinster
((
dlg
)
->
{
dlg
.
dismiss
();
if
(
old
!=
null
)
{
loadDeck
(
new
File
(
old
));
}
});
builder
.
setLeftButtonListener
((
dlg
,
s
)
->
{
CharSequence
name
=
editText
.
getText
();
if
(!
TextUtils
.
isEmpty
(
name
))
{
String
filename
=
String
.
valueOf
(
name
);
if
(!
filename
.
endsWith
(
YDK_FILE_EX
))
{
filename
+=
YDK_FILE_EX
;
}
File
ydk
=
new
File
(
mSettings
.
getResourcePath
(),
Constants
.
CORE_DECK_PATH
+
"/"
+
filename
);
if
(
ydk
.
exists
())
{
showToast
(
R
.
string
.
file_exist
,
Toast
.
LENGTH_SHORT
);
return
;
}
if
(
mYdkFile
!=
null
&&
mYdkFile
.
exists
())
{
if
(
mYdkFile
.
renameTo
(
ydk
))
{
mYdkFile
=
ydk
;
initDecksListSpinners
(
mDeckSpinner
);
dlg
.
dismiss
();
loadDeck
(
ydk
);
}
}
else
{
dlg
.
dismiss
();
try
{
ydk
.
createNewFile
();
}
catch
(
IOException
e
)
{
}
mYdkFile
=
ydk
;
initDecksListSpinners
(
mDeckSpinner
);
save
();
setCurYdkFile
(
mYdkFile
);
}
}
else
{
dlg
.
dismiss
();
}
});
builder
.
show
();
}
private
void
save
()
{
mDeckMd5
=
mDeckView
.
getDeckInfo
().
makeMd5
();
//保存了,记录状态
if
(
DeckUtils
.
save
(
mDeckView
.
getDeckInfo
(),
mYdkFile
))
{
showToast
(
R
.
string
.
save_tip_ok
,
Toast
.
LENGTH_SHORT
);
}
else
{
showToast
(
R
.
string
.
save_tip_fail
,
Toast
.
LENGTH_SHORT
);
}
}
protected
void
showSearch
(
boolean
autoclose
)
{
if
(
mDrawerlayout
.
isDrawerOpen
(
Gravity
.
LEFT
))
{
mDrawerlayout
.
closeDrawer
(
Gravity
.
LEFT
);
}
if
(
autoclose
&&
mDrawerlayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawerlayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
}
else
if
(
isLoad
)
{
mDrawerlayout
.
openDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
}
}
protected
void
showResult
(
boolean
autoclose
)
{
if
(
mDrawerlayout
.
isDrawerOpen
(
Constants
.
CARD_SEARCH_GRAVITY
))
{
mDrawerlayout
.
closeDrawer
(
Constants
.
CARD_SEARCH_GRAVITY
);
}
if
(
autoclose
&&
mDrawerlayout
.
isDrawerOpen
(
Gravity
.
LEFT
))
{
mDrawerlayout
.
closeDrawer
(
Gravity
.
LEFT
);
}
else
if
(
isLoad
)
{
mDrawerlayout
.
openDrawer
(
Gravity
.
LEFT
);
}
}
protected
void
onCardClick
(
View
view
,
Card
cardInfo
,
int
pos
)
{
if
(
mCardListAdapater
.
isShowMenu
(
view
))
{
return
;
}
if
(
cardInfo
!=
null
)
{
//TODO 显示详情
}
}
protected
void
onCardLongClick
(
View
view
,
Card
cardInfo
,
int
pos
)
{
// mCardListAdapater.showMenu(view);
}
protected
void
hideDrawers
()
{
if
(
mDrawerlayout
.
isDrawerOpen
(
Gravity
.
RIGHT
))
{
mDrawerlayout
.
closeDrawer
(
Gravity
.
RIGHT
);
}
if
(
mDrawerlayout
.
isDrawerOpen
(
Gravity
.
LEFT
))
{
mDrawerlayout
.
closeDrawer
(
Gravity
.
LEFT
);
}
}
protected
void
setListeners
()
{
mListView
.
addOnItemTouchListener
(
new
RecyclerViewItemListener
(
mListView
,
new
RecyclerViewItemListener
.
OnItemListener
()
{
@Override
public
void
onItemClick
(
View
view
,
int
pos
)
{
onCardClick
(
view
,
mCardListAdapater
.
getItem
(
pos
),
pos
);
}
@Override
public
void
onItemLongClick
(
View
view
,
int
pos
)
{
onCardLongClick
(
view
,
mCardListAdapater
.
getItem
(
pos
),
pos
);
}
@Override
public
void
onItemDoubleClick
(
View
view
,
int
pos
)
{
}
}));
mListView
.
addOnScrollListener
(
new
RecyclerView
.
OnScrollListener
()
{
@Override
public
void
onScrollStateChanged
(
RecyclerView
recyclerView
,
int
newState
)
{
super
.
onScrollStateChanged
(
recyclerView
,
newState
);
switch
(
newState
)
{
case
RecyclerView
.
SCROLL_STATE_IDLE
:
Glide
.
with
(
getContext
()).
resumeRequests
();
break
;
case
RecyclerView
.
SCROLL_STATE_DRAGGING
:
Glide
.
with
(
getContext
()).
pauseRequests
();
break
;
case
RecyclerView
.
SCROLL_STATE_SETTLING
:
Glide
.
with
(
getContext
()).
resumeRequests
();
break
;
}
}
});
}
private
boolean
checkLimit
(
Card
cardInfo
,
boolean
tip
)
{
int
count
=
mDeckView
.
getDeckInfo
().
getCardUseCount
(
cardInfo
.
Code
);
if
(
mLimitList
!=
null
&&
mLimitList
.
check
(
cardInfo
,
LimitType
.
Forbidden
))
{
if
(
tip
)
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
0
),
Toast
.
LENGTH_SHORT
);
}
return
false
;
}
if
(
mLimitList
!=
null
&&
mLimitList
.
check
(
cardInfo
,
LimitType
.
Limit
))
{
if
(
count
>=
1
)
{
if
(
tip
)
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
1
),
Toast
.
LENGTH_SHORT
);
}
return
false
;
}
}
else
if
(
mLimitList
!=
null
&&
mLimitList
.
check
(
cardInfo
,
LimitType
.
SemiLimit
))
{
if
(
count
>=
2
)
{
if
(
tip
)
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
2
),
Toast
.
LENGTH_SHORT
);
}
return
false
;
}
}
else
if
(
count
>=
Constants
.
CARD_MAX_COUNT
)
{
if
(
tip
)
{
showToast
(
getString
(
R
.
string
.
tip_card_max
,
3
),
Toast
.
LENGTH_SHORT
);
}
return
false
;
}
return
true
;
}
private
boolean
addSideCard
(
Card
cardInfo
)
{
if
(
checkLimit
(
cardInfo
,
true
))
{
boolean
rs
=
mDeckView
.
addSideCards
(
cardInfo
);
if
(
rs
)
{
showToast
(
R
.
string
.
add_card_tip_ok
,
Toast
.
LENGTH_SHORT
);
}
else
{
showToast
(
R
.
string
.
add_card_tip_fail
,
Toast
.
LENGTH_SHORT
);
}
return
rs
;
}
return
false
;
}
private
boolean
addMainCard
(
Card
cardInfo
)
{
if
(
checkLimit
(
cardInfo
,
true
))
{
boolean
rs
;
if
(
cardInfo
.
isExtraCard
())
{
rs
=
mDeckView
.
addExtraCards
(
cardInfo
);
}
else
{
rs
=
mDeckView
.
addMainCards
(
cardInfo
);
}
if
(
rs
)
{
showToast
(
R
.
string
.
add_card_tip_ok
,
Toast
.
LENGTH_SHORT
);
}
else
{
showToast
(
R
.
string
.
add_card_tip_fail
,
Toast
.
LENGTH_SHORT
);
}
return
rs
;
}
return
false
;
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck/DeckAdapater.java
View file @
53c30ec3
...
...
@@ -162,7 +162,7 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
if
(
d1
.
getType
()
==
d2
.
getType
())
{
Card
c1
=
d1
.
getCardInfo
();
Card
c2
=
d2
.
getCardInfo
();
return
CardSort
.
ASC
.
compare
(
c1
,
c2
)
<
0
;
return
CardSort
.
FULL_ASC
.
compare
(
c1
,
c2
)
>
0
;
}
return
(
d1
.
getType
().
ordinal
()
-
d2
.
getType
().
ordinal
())
>
0
;
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck/DeckAdapater2.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards.deck
;
import
android.content.Context
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
androidx.recyclerview.widget.RecyclerView
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.bean.DeckInfo
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.loader.ImageLoader
;
import
ocgcore.data.Card
;
import
ocgcore.data.LimitList
;
import
ocgcore.enums.LimitType
;
public
class
DeckAdapater2
extends
RecyclerView
.
Adapter
<
DeckViewHolder
>
{
private
final
ImageLoader
mImageLoader
;
private
final
DeckInfo
mDeck
;
private
LimitList
mLimitList
;
private
ImageTop
mImageTop
;
private
final
LabelInfo
mLabelInfo
;
private
Context
mContext
;
private
LayoutInflater
mLayoutInflater
;
public
final
static
int
MainLabel
=
0
;
public
final
static
int
MainStart
=
MainLabel
+
1
;
public
final
static
int
MainEnd
=
MainStart
+
Constants
.
DECK_MAIN_MAX
-
1
;
public
final
static
int
ExtraLabel
=
MainEnd
+
1
;
public
final
static
int
ExtraStart
=
ExtraLabel
+
1
;
public
final
static
int
ExtraEnd
=
ExtraStart
+
Constants
.
DECK_EXTRA_MAX
-
1
;
public
final
static
int
SideLabel
=
ExtraEnd
+
1
;
public
final
static
int
SideStart
=
SideLabel
+
1
;
public
final
static
int
SideEnd
=
SideStart
+
Constants
.
DECK_SIDE_MAX
-
1
;
private
int
cardWidth
,
cardHeight
;
public
DeckAdapater2
(
Context
context
,
int
width
,
int
height
)
{
mContext
=
context
;
cardWidth
=
width
;
cardHeight
=
height
;
mLayoutInflater
=
LayoutInflater
.
from
(
context
);
mImageLoader
=
ImageLoader
.
get
(
context
);
mDeck
=
new
DeckInfo
();
mLabelInfo
=
new
LabelInfo
(
context
);
}
public
Context
getContext
()
{
return
mContext
;
}
public
void
updateDeck
(
DeckInfo
deck
)
{
mDeck
.
update
(
deck
);
mLabelInfo
.
update
(
deck
);
}
public
void
setLimitList
(
LimitList
limitList
)
{
mLimitList
=
limitList
;
}
public
ImageTop
getImageTop
()
{
if
(
mImageTop
==
null
)
{
mImageTop
=
new
ImageTop
(
getContext
());
}
return
mImageTop
;
}
public
boolean
isLabel
(
int
pos
)
{
return
pos
==
ExtraLabel
||
pos
==
MainLabel
||
pos
==
SideLabel
;
}
@Override
public
DeckViewHolder
onCreateViewHolder
(
ViewGroup
parent
,
int
viewType
)
{
View
view
=
mLayoutInflater
.
inflate
(
R
.
layout
.
item_deck_card2
,
parent
,
false
);
return
new
DeckViewHolder
(
view
);
}
@Override
public
int
getItemCount
()
{
return
Constants
.
DECK_EXTRA_MAX
+
Constants
.
DECK_MAIN_MAX
+
Constants
.
DECK_SIDE_MAX
+
3
;
}
@Override
public
void
onBindViewHolder
(
DeckViewHolder
holder
,
int
position
)
{
if
(
position
==
ExtraLabel
)
{
//61 62-76
holder
.
setText
(
mLabelInfo
.
getExtraString
());
}
else
if
(
position
==
MainLabel
)
{
//0 1-60
holder
.
setText
(
mLabelInfo
.
getMainString
());
}
else
if
(
position
==
SideLabel
)
{
//77 78-92
holder
.
setText
(
mLabelInfo
.
getSideString
());
}
else
{
holder
.
setSize
(
cardWidth
,
cardHeight
);
Card
card
=
null
;
if
(
inMain
(
position
))
{
card
=
mDeck
.
getMainCard
(
getMainIndex
(
position
));
}
else
if
(
inExtra
(
position
))
{
card
=
mDeck
.
getExtraCard
(
getExtraIndex
(
position
));
}
else
if
(
inSide
(
position
))
{
card
=
mDeck
.
getSideCard
(
getSideIndex
(
position
));
}
if
(
card
==
null
)
{
holder
.
showEmpty
();
}
else
{
holder
.
showImage
();
if
(
mLimitList
!=
null
)
{
if
(
mLimitList
.
check
(
card
,
LimitType
.
Forbidden
))
{
holder
.
setRightImage
(
getImageTop
().
forbidden
);
}
else
if
(
mLimitList
.
check
(
card
,
LimitType
.
Limit
))
{
holder
.
setRightImage
(
getImageTop
().
limit
);
}
else
if
(
mLimitList
.
check
(
card
,
LimitType
.
SemiLimit
))
{
holder
.
setRightImage
(
getImageTop
().
semiLimit
);
}
else
{
holder
.
setRightImage
(
null
);
}
}
else
{
holder
.
setRightImage
(
null
);
}
mImageLoader
.
bindImage
(
holder
.
cardImage
,
card
.
Code
);
}
}
}
private
int
getMainIndex
(
int
pos
)
{
return
pos
-
MainStart
;
}
private
int
getExtraIndex
(
int
pos
)
{
return
pos
-
ExtraStart
;
}
private
int
getSideIndex
(
int
pos
)
{
return
pos
-
SideStart
;
}
private
boolean
inMain
(
int
pos
)
{
return
pos
>=
MainStart
&&
pos
<=
MainEnd
;
}
private
boolean
inExtra
(
int
pos
)
{
return
pos
>=
ExtraStart
&&
pos
<=
ExtraEnd
;
}
private
boolean
inSide
(
int
pos
)
{
return
pos
>=
SideStart
&&
pos
<=
SideEnd
;
}
}
class
DeckData
{
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck/DeckLayoutManager2.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards.deck
;
import
android.content.Context
;
import
androidx.recyclerview.widget.GridLayoutManager
;
public
class
DeckLayoutManager2
extends
GridLayoutManager
{
private
static
final
int
DEF_LINE_COUNT
=
10
;
private
static
final
int
DEF_LINE_MAX_COUNT
=
15
;
public
DeckLayoutManager2
(
Context
context
,
int
span
)
{
super
(
context
,
span
);
setSpanSizeLookup
(
new
SpanSizeLookup
()
{
@Override
public
int
getSpanSize
(
int
position
)
{
if
(
DeckItemUtils
.
isLabel
(
position
))
{
return
getChildCount
();
}
return
1
;
}
});
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/DeckAdapter.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards.deck2
;
import
android.content.Context
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
androidx.recyclerview.widget.ItemTouchHelperPlus
;
import
androidx.recyclerview.widget.OnItemDragListener
;
import
androidx.recyclerview.widget.RecyclerView
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.bean.DeckInfo
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.loader.ImageLoader
;
import
ocgcore.data.Card
;
import
static
cn
.
garymb
.
ygomobile
.
bean
.
DeckInfo
.
Type
.
Extra
;
import
static
cn
.
garymb
.
ygomobile
.
bean
.
DeckInfo
.
Type
.
Main
;
import
static
cn
.
garymb
.
ygomobile
.
bean
.
DeckInfo
.
Type
.
Side
;
public
class
DeckAdapter
extends
RecyclerView
.
Adapter
<
DeckViewHolder
>
implements
IDeckLayout
{
private
final
Context
mContext
;
private
final
RecyclerView
mRecyclerView
;
private
final
LayoutInflater
mLayoutInflater
;
private
final
DeckLayoutManager
mDeckLayoutManager
;
private
int
mWidth
;
private
int
mHeight
;
private
int
mPWidth
;
private
final
DeckInfo
mDeckInfo
;
private
ImageLoader
mImageLoader
;
public
DeckAdapter
(
Context
context
,
RecyclerView
recyclerView
,
OnItemDragListener
listener
)
{
mDeckInfo
=
new
DeckInfo
();
mImageLoader
=
ImageLoader
.
get
(
context
);
mContext
=
context
;
mRecyclerView
=
recyclerView
;
mLayoutInflater
=
LayoutInflater
.
from
(
context
);
recyclerView
.
addItemDecoration
(
new
DeckItemDecoration
(
this
));
mDeckLayoutManager
=
new
DeckLayoutManager
(
getContext
(),
getLineLimitCount
(),
this
);
recyclerView
.
setLayoutManager
(
mDeckLayoutManager
);
DeckHelperCallback
deckHelperCallback
=
new
DeckHelperCallback
(
this
);
ItemTouchHelperPlus
touchHelper
=
new
ItemTouchHelperPlus
(
getContext
(),
deckHelperCallback
);
touchHelper
.
setEnableClickDrag
(
true
);
touchHelper
.
attachToRecyclerView
(
recyclerView
);
touchHelper
.
setItemDragListener
(
listener
);
deckHelperCallback
.
setItemTouchHelper
(
touchHelper
);
}
public
Context
getContext
()
{
return
mContext
;
}
@Override
public
DeckViewHolder
onCreateViewHolder
(
ViewGroup
parent
,
int
viewType
)
{
View
view
=
mLayoutInflater
.
inflate
(
R
.
layout
.
item_deck_card2
,
parent
,
false
);
return
new
DeckViewHolder
(
view
);
}
@Override
public
int
getLineLimitCount
()
{
return
15
;
}
//region width/height
private
void
makeHeight
()
{
mWidth
=
getWidth10
();
mHeight
=
scaleHeight
(
mWidth
);
}
public
void
setDeckInfo
(
DeckInfo
deckInfo
)
{
mDeckInfo
.
update
(
deckInfo
);
}
@Override
public
int
getMaxWidth
()
{
if
(
mPWidth
==
0
)
{
mPWidth
=
mRecyclerView
.
getMeasuredWidth
()
-
mRecyclerView
.
getPaddingRight
()
-
mRecyclerView
.
getPaddingLeft
();
}
return
mPWidth
;
}
@Override
public
int
getWidth15
()
{
return
getMaxWidth
()
/
15
;
}
@Override
public
int
getWidth10
()
{
return
getMaxWidth
()
/
10
;
}
private
int
scaleHeight
(
int
width
)
{
return
Math
.
round
((
float
)
width
*
((
float
)
255
/
177
));
}
//endregion
//region count/limit
@Override
public
int
getMainCount
()
{
return
Math
.
max
(
31
,
getMainRealCount
());
}
public
int
getMainRealCount
()
{
return
mDeckInfo
.
getMainCount
();
}
@Override
public
int
getExtraCount
()
{
return
Math
.
max
(
1
,
getExtraRealCount
());
}
public
int
getExtraRealCount
()
{
return
mDeckInfo
.
getExtraCount
();
}
@Override
public
int
getSideCount
()
{
return
Math
.
max
(
1
,
getSideRealCount
());
}
public
int
getSideRealCount
()
{
return
mDeckInfo
.
getSideCount
();
}
@Override
public
int
getMainLimit
()
{
return
Math
.
max
(
10
,
(
int
)
Math
.
ceil
(
getMainCount
()
/
4.0f
));
}
@Override
public
int
getExtraLimit
()
{
return
Math
.
max
(
getLineCardCount
(),
getExtraCount
());
}
@Override
public
int
getSideLimit
()
{
return
Math
.
max
(
getLineCardCount
(),
getSideCount
());
}
//endregion
//region index
@Override
public
boolean
isMain
(
int
pos
)
{
return
pos
>=
getMainStart
()
&&
pos
<=
getMainEnd
();
}
@Override
public
boolean
isExtra
(
int
pos
)
{
return
pos
>=
getExtraStart
()
&&
pos
<=
getExtraEnd
();
}
@Override
public
boolean
isSide
(
int
pos
)
{
return
pos
>=
getSideStart
()
&&
pos
<=
getSideEnd
();
}
@Override
public
boolean
isLabel
(
int
position
)
{
if
(
position
==
getMainLabel
()
||
position
==
getExtraLabel
()
||
position
==
getSideLabel
())
{
return
true
;
}
return
false
;
}
private
int
getMainLabel
()
{
return
0
;
}
private
int
getMainStart
()
{
return
getMainLabel
()
+
1
;
}
private
int
getMainEnd
()
{
return
getMainStart
()
+
getMainCount
()
-
1
;
}
private
int
getExtraLabel
()
{
return
getMainEnd
()
+
1
;
}
private
int
getExtraStart
()
{
return
getExtraLabel
()
+
1
;
}
private
int
getExtraEnd
()
{
return
getExtraStart
()
+
getExtraCount
()
-
1
;
}
private
int
getSideLabel
()
{
return
getExtraEnd
()
+
1
;
}
private
int
getSideStart
()
{
return
getSideLabel
()
+
1
;
}
private
int
getSideEnd
()
{
return
getSideStart
()
+
getSideCount
()
-
1
;
}
@Override
public
int
getMainIndex
(
int
pos
)
{
return
pos
-
getMainStart
();
}
@Override
public
int
getExtraIndex
(
int
pos
)
{
return
pos
-
getExtraStart
();
}
@Override
public
int
getSideIndex
(
int
pos
)
{
return
pos
-
getSideStart
();
}
//endregion
@Override
public
int
getItemCount
()
{
return
getMainCount
()
+
getExtraCount
()
+
getSideCount
()
+
3
;
}
@Override
public
int
getLineCardCount
()
{
return
10
;
}
@Override
public
void
onBindViewHolder
(
DeckViewHolder
holder
,
int
position
)
{
if
(
isLabel
(
position
))
{
if
(
position
==
getMainLabel
())
{
holder
.
setText
(
"main"
);
}
else
if
(
position
==
getExtraLabel
())
{
holder
.
setText
(
"extra"
);
}
else
if
(
position
==
getSideLabel
())
{
holder
.
setText
(
"side"
);
}
holder
.
setSize
(-
1
,
-
1
);
}
else
{
holder
.
showImage
();
if
(
mHeight
<=
0
)
{
makeHeight
();
}
holder
.
setSize
(
mWidth
,
mHeight
);
if
(
isMain
(
position
))
{
position
=
getMainIndex
(
position
);
if
(
position
>=
getMainRealCount
())
{
holder
.
empty
();
}
else
{
Card
card
=
mDeckInfo
.
getMainCard
(
position
);
if
(
card
==
null
)
{
holder
.
useDefault
();
}
else
{
mImageLoader
.
bindImage
(
holder
.
getCardImage
(),
card
.
Code
);
}
}
}
else
if
(
isExtra
(
position
))
{
position
=
getExtraIndex
(
position
);
if
(
position
>=
getExtraRealCount
())
{
holder
.
empty
();
}
else
{
Card
card
=
mDeckInfo
.
getExtraCard
(
position
);
if
(
card
==
null
)
{
holder
.
useDefault
();
}
else
{
mImageLoader
.
bindImage
(
holder
.
getCardImage
(),
card
.
Code
);
}
}
}
else
if
(
isSide
(
position
))
{
position
=
getSideIndex
(
position
);
if
(
position
>=
getSideRealCount
())
{
holder
.
empty
();
}
else
{
Card
card
=
mDeckInfo
.
getSideCard
(
position
);
if
(
card
==
null
)
{
holder
.
useDefault
();
}
else
{
mImageLoader
.
bindImage
(
holder
.
getCardImage
(),
card
.
Code
);
}
}
}
}
}
@Override
public
boolean
moveItem
(
int
from
,
int
to
)
{
if
(
isMain
(
from
))
{
if
(
isMain
(
to
))
{
int
pos
=
getMainIndex
(
to
);
if
(
pos
>=
getMainRealCount
())
{
to
=
getMainRealCount
()
-
1
+
getMainStart
();
}
mDeckInfo
.
move
(
Main
,
getMainIndex
(
from
),
getMainIndex
(
to
));
notifyItemMoved
(
from
,
to
);
return
true
;
}
if
(
isSide
(
to
))
{
//TODO check side
if
(
getSideRealCount
()
>=
Constants
.
DECK_SIDE_MAX
)
{
return
false
;
}
boolean
resize
=
getMainRealCount
()
%
4
==
1
;
Card
card
=
mDeckInfo
.
removeMain
(
getMainIndex
(
from
));
mDeckInfo
.
addSideCards
(
getSideIndex
(
to
),
card
);
Log
.
d
(
"kk"
,
"move main -> side "
+
getMainIndex
(
from
)
+
"->"
+
getSideIndex
(
to
));
notifyItemMoved
(
from
,
to
);
notifyItemRemoved
(
getSideEnd
());
notifyItemInserted
(
getMainEnd
());
notifyItemChanged
(
getMainLabel
());
notifyItemChanged
(
getSideLabel
());
if
(
resize
)
{
notifyItemRangeChanged
(
getMainStart
(),
getMainStart
()
+
getMainEnd
());
}
return
true
;
}
}
else
if
(
isExtra
(
from
))
{
if
(
isExtra
(
to
))
{
mDeckInfo
.
move
(
Extra
,
getExtraIndex
(
from
),
getExtraIndex
(
to
));
notifyItemMoved
(
from
,
to
);
return
true
;
}
if
(
isSide
(
to
))
{
//TODO check side
if
(
getSideRealCount
()
>=
Constants
.
DECK_SIDE_MAX
)
{
return
false
;
}
Card
card
=
mDeckInfo
.
removeExtra
(
getExtraIndex
(
from
));
mDeckInfo
.
addSideCards
(
getSideIndex
(
to
),
card
);
Log
.
d
(
"kk"
,
"move extra -> side "
+
getExtraIndex
(
from
)
+
"->"
+
getSideIndex
(
to
));
notifyItemMoved
(
from
,
to
);
notifyItemRemoved
(
getSideEnd
());
notifyItemInserted
(
getExtraEnd
());
notifyItemChanged
(
getExtraLabel
());
notifyItemChanged
(
getSideLabel
());
return
true
;
}
}
else
if
(
isSide
(
from
))
{
if
(
isSide
(
to
))
{
mDeckInfo
.
move
(
Side
,
getSideIndex
(
from
),
getSideIndex
(
to
));
notifyItemMoved
(
from
,
to
);
return
true
;
}
if
(
isExtra
(
to
))
{
//TODO check extra
if
(
getExtraRealCount
()
>=
Constants
.
DECK_EXTRA_MAX
)
{
return
false
;
}
Card
card
=
mDeckInfo
.
removeSide
(
getSideIndex
(
from
));
mDeckInfo
.
addExtraCards
(
getExtraIndex
(
to
),
card
);
Log
.
d
(
"kk"
,
"move side -> extra "
+
getSideIndex
(
from
)
+
"->"
+
getExtraIndex
(
to
));
notifyItemMoved
(
from
,
to
);
notifyItemRemoved
(
getExtraEnd
());
notifyItemInserted
(
getSideEnd
());
notifyItemChanged
(
getExtraLabel
());
notifyItemChanged
(
getSideLabel
());
return
true
;
}
if
(
isMain
(
to
))
{
//TODO check main
if
(
getMainRealCount
()
>=
Constants
.
DECK_MAIN_MAX
)
{
return
false
;
}
int
pos
=
getMainIndex
(
to
);
if
(
pos
>=
getMainRealCount
())
{
to
=
getMainRealCount
()
-
1
+
getMainStart
();
}
boolean
resize
=
getMainRealCount
()
%
4
==
0
;
Card
card
=
mDeckInfo
.
removeSide
(
getSideIndex
(
from
));
mDeckInfo
.
addMainCards
(
getMainIndex
(
to
),
card
);
Log
.
d
(
"kk"
,
"move side -> main "
+
getSideIndex
(
from
)
+
"->"
+
getMainIndex
(
to
));
notifyItemMoved
(
from
,
to
);
notifyItemRemoved
(
getMainEnd
());
notifyItemInserted
(
getSideEnd
());
notifyItemChanged
(
getMainLabel
());
notifyItemChanged
(
getSideLabel
());
if
(
resize
)
{
notifyItemRangeChanged
(
getMainStart
(),
getMainStart
()
+
getMainEnd
());
}
return
true
;
}
}
return
false
;
}
}
\ No newline at end of file
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/DeckHelperCallback.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards.deck2
;
import
androidx.recyclerview.widget.GridLayoutManager
;
import
androidx.recyclerview.widget.ItemTouchHelper
;
import
androidx.recyclerview.widget.ItemTouchHelperPlus
;
import
androidx.recyclerview.widget.RecyclerView
;
class
DeckHelperCallback
extends
ItemTouchHelperPlus
.
Callback2
{
private
IDeckLayout
mDeckAdapter
;
DeckHelperCallback
(
IDeckLayout
deckAdapter
)
{
mDeckAdapter
=
deckAdapter
;
}
private
boolean
isLabel
(
int
position
)
{
return
mDeckAdapter
.
isLabel
(
position
);
}
@Override
public
int
getMovementFlags
(
RecyclerView
recyclerView
,
RecyclerView
.
ViewHolder
viewHolder
)
{
int
id
=
viewHolder
.
getAdapterPosition
();
if
(
isLabel
(
id
))
{
return
makeMovementFlags
(
0
,
0
);
}
int
dragFlags
;
if
(
recyclerView
.
getLayoutManager
()
instanceof
GridLayoutManager
)
{
dragFlags
=
ItemTouchHelper
.
UP
|
ItemTouchHelper
.
DOWN
|
ItemTouchHelper
.
RIGHT
|
ItemTouchHelper
.
LEFT
;
}
else
{
dragFlags
=
ItemTouchHelper
.
UP
|
ItemTouchHelper
.
DOWN
;
}
return
makeMovementFlags
(
dragFlags
,
0
);
}
@Override
public
boolean
onMove
(
RecyclerView
recyclerView
,
RecyclerView
.
ViewHolder
viewHolder
,
RecyclerView
.
ViewHolder
target
)
{
return
mDeckAdapter
.
moveItem
(
viewHolder
.
getAdapterPosition
(),
target
.
getAdapterPosition
());
}
@Override
public
void
onSwiped
(
RecyclerView
.
ViewHolder
viewHolder
,
int
direction
)
{
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/DeckItemDecoration.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards.deck2
;
import
android.graphics.Rect
;
import
android.view.View
;
import
androidx.recyclerview.widget.RecyclerView
;
class
DeckItemDecoration
extends
RecyclerView
.
ItemDecoration
{
private
IDeckLayout
mDeckLayout
;
DeckItemDecoration
(
IDeckLayout
deckLayout
)
{
mDeckLayout
=
deckLayout
;
}
@Override
public
void
getItemOffsets
(
Rect
outRect
,
View
view
,
RecyclerView
parent
,
RecyclerView
.
State
state
)
{
final
int
LINE_COUNT
=
mDeckLayout
.
getLineLimitCount
();
final
int
CARD_COUNT
=
mDeckLayout
.
getLineCardCount
();
int
position
=
((
RecyclerView
.
LayoutParams
)
view
.
getLayoutParams
()).
getViewLayoutPosition
();
if
(
mDeckLayout
.
isLabel
(
position
))
{
super
.
getItemOffsets
(
outRect
,
view
,
parent
,
state
);
return
;
}
float
w
=
mDeckLayout
.
getWidth10
()
-
mDeckLayout
.
getWidth15
();
int
limit
;
if
(
mDeckLayout
.
isMain
(
position
))
{
position
=
mDeckLayout
.
getMainIndex
(
position
);
limit
=
mDeckLayout
.
getMainLimit
();
}
else
if
(
mDeckLayout
.
isExtra
(
position
))
{
position
=
mDeckLayout
.
getExtraIndex
(
position
);
limit
=
mDeckLayout
.
getExtraLimit
();
//10
}
else
if
(
mDeckLayout
.
isSide
(
position
))
{
position
=
mDeckLayout
.
getSideIndex
(
position
);
limit
=
mDeckLayout
.
getSideLimit
();
//10
}
else
{
return
;
}
float
_w
=
w
/
(
limit
-
1.0f
);
float
w2
;
if
(
limit
<
LINE_COUNT
-
1
)
{
//10-13
w
=
mDeckLayout
.
getWidth15
()
*
(
LINE_COUNT
-
limit
);
w2
=
(
w
/
(
limit
-
1.0f
))
-
_w
;
}
else
if
(
limit
==
LINE_COUNT
-
1
)
{
//14
w
=
mDeckLayout
.
getWidth15
()
*
(
LINE_COUNT
-
limit
);
_w
=
_w
/
64.0f
*
65.0f
;
w2
=
(
w
/
(
limit
-
1.0f
))
-
_w
;
}
else
{
//15
w
=
mDeckLayout
.
getWidth15
()
*
(
LINE_COUNT
-
limit
);
_w
=
_w
/
32.0f
*
33.0f
;
w2
=
(
w
/
(
limit
-
1.0f
))
-
_w
;
}
int
linePos
=
position
%
limit
;
outRect
.
left
=
(
int
)
(
w2
*
linePos
);
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/DeckLayoutManager.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards.deck2
;
import
android.content.Context
;
import
androidx.recyclerview.widget.GridLayoutManagerPlus
;
class
DeckLayoutManager
extends
GridLayoutManagerPlus
{
DeckLayoutManager
(
Context
context
,
final
int
span
,
final
IDeckLayout
deckAdapter
)
{
super
(
context
,
span
);
setSpanSizeLookup
(
new
SpanSizeLookup
()
{
@Override
public
int
getSpanSize
(
int
position
)
{
if
(
deckAdapter
.
isLabel
(
position
))
{
return
span
;
}
else
if
(
deckAdapter
.
isMain
(
position
))
{
position
=
deckAdapter
.
getMainIndex
(
position
);
int
limit
=
deckAdapter
.
getMainLimit
();
if
(
position
%
limit
==
(
limit
-
1
))
{
return
span
-
limit
+
1
;
}
}
else
if
(
deckAdapter
.
isExtra
(
position
))
{
position
=
deckAdapter
.
getExtraIndex
(
position
);
if
(
deckAdapter
.
getExtraCount
()
<
deckAdapter
.
getLineCardCount
())
{
if
(
position
==
deckAdapter
.
getExtraCount
()
-
1
)
{
return
deckAdapter
.
getLineCardCount
()
-
position
;
}
}
}
else
if
(
deckAdapter
.
isSide
(
position
))
{
}
return
1
;
}
});
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/DeckViewHolder.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards.deck2
;
import
android.graphics.Bitmap
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
androidx.recyclerview.widget.GridLayoutManagerPlus
;
import
cn.garymb.ygomobile.lite.R
;
import
ocgcore.data.Card
;
class
DeckViewHolder
extends
GridLayoutManagerPlus
.
GridViewHolder
{
DeckViewHolder
(
View
view
)
{
super
(
view
);
this
.
view
=
view
;
view
.
setTag
(
view
.
getId
(),
this
);
cardImage
=
$
(
R
.
id
.
card_image
);
labelText
=
$
(
R
.
id
.
label
);
textLayout
=
$
(
R
.
id
.
layout_label
);
rightImage
=
$
(
R
.
id
.
right_top
);
}
@SuppressWarnings
(
"unchecked"
)
private
<
T
extends
View
>
T
$
(
int
id
)
{
return
(
T
)
view
.
findViewById
(
id
);
}
void
setSize
(
int
width
,
int
height
)
{
view
.
setMinimumWidth
(
width
);
view
.
setMinimumHeight
(
height
);
ViewGroup
.
LayoutParams
layoutParams
=
view
.
getLayoutParams
();
if
(
layoutParams
!=
null
)
{
if
(
width
>
0
)
{
layoutParams
.
width
=
width
;
}
else
{
layoutParams
.
width
=
ViewGroup
.
LayoutParams
.
MATCH_PARENT
;
}
if
(
height
>
0
)
{
layoutParams
.
height
=
height
;
}
else
{
layoutParams
.
height
=
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
;
}
}
view
.
setLayoutParams
(
layoutParams
);
}
public
void
empty
()
{
showEmpty
();
}
public
void
useDefault
()
{
cardImage
.
setImageResource
(
R
.
drawable
.
unknown
);
//TODO sdcard的卡背
// File outFile = new File(AppsSettings.get().getCoreSkinPath(), Constants.UNKNOWN_IMAGE);
// ViewGroup.LayoutParams layoutParams = cardImage.getLayoutParams();
// if (layoutParams != null) {
// layoutParams.height = h;
// }
// imageLoader.$(outFile, cardImage, outFile.getName().endsWith(Constants.BPG), 0, null);
}
public
void
setText
(
String
text
)
{
labelText
.
setText
(
text
);
textLayout
.
setVisibility
(
View
.
VISIBLE
);
cardImage
.
setVisibility
(
View
.
GONE
);
rightImage
.
setVisibility
(
View
.
GONE
);
}
public
void
showImage
()
{
textLayout
.
setVisibility
(
View
.
GONE
);
cardImage
.
setVisibility
(
View
.
VISIBLE
);
rightImage
.
setVisibility
(
View
.
VISIBLE
);
//
cardImage
.
setImageResource
(
R
.
drawable
.
unknown
);
}
public
void
showEmpty
()
{
textLayout
.
setVisibility
(
View
.
GONE
);
cardImage
.
setVisibility
(
View
.
INVISIBLE
);
rightImage
.
setVisibility
(
View
.
GONE
);
}
public
ImageView
getCardImage
()
{
return
cardImage
;
}
/**
* 左上角图标
* @param bitmap
*/
public
void
setRightImage
(
Bitmap
bitmap
)
{
rightImage
.
setImageBitmap
(
bitmap
);
}
public
void
setHeadVisibility
(
int
visibility
)
{
}
private
final
View
view
;
private
final
View
textLayout
;
private
final
TextView
labelText
;
private
final
ImageView
cardImage
;
private
final
ImageView
rightImage
;
private
Card
mCard
;
private
Type
mType
;
public
Card
getCard
()
{
return
mCard
;
}
public
void
setCard
(
Card
card
)
{
mCard
=
card
;
}
public
Type
getType
()
{
return
mType
;
}
public
void
setType
(
Type
type
)
{
mType
=
type
;
}
public
enum
Type
{
None
,
Main
,
Extra
,
Side
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck2/IDeckLayout.java
deleted
100644 → 0
View file @
712747e2
package
cn.garymb.ygomobile.ui.cards.deck2
;
public
interface
IDeckLayout
{
int
getMaxWidth
();
int
getWidth15
();
int
getWidth10
();
boolean
isLabel
(
int
position
);
boolean
isMain
(
int
position
);
boolean
isExtra
(
int
position
);
boolean
isSide
(
int
position
);
int
getMainCount
();
int
getExtraCount
();
int
getSideCount
();
int
getMainLimit
();
int
getExtraLimit
();
int
getSideLimit
();
int
getMainIndex
(
int
pos
);
int
getExtraIndex
(
int
pos
);
int
getSideIndex
(
int
pos
);
int
getLineLimitCount
();
int
getLineCardCount
();
boolean
moveItem
(
int
fromPosition
,
int
toPosition
);
}
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
View file @
53c30ec3
package
cn.garymb.ygomobile.ui.home
;
import
android.content.ComponentName
;
import
android.content.Intent
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
...
...
@@ -12,6 +11,7 @@ import android.os.Build;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.util.SparseArray
;
import
android.view.Gravity
;
import
android.view.Menu
;
...
...
@@ -62,7 +62,6 @@ import java.util.List;
import
cn.garymb.ygodata.YGOGameOptions
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.YGOMobileActivity
;
import
cn.garymb.ygomobile.YGOStarter
;
import
cn.garymb.ygomobile.bean.Deck
;
import
cn.garymb.ygomobile.bean.ServerInfo
;
...
...
@@ -76,7 +75,7 @@ import cn.garymb.ygomobile.ui.activities.WebActivity;
import
cn.garymb.ygomobile.ui.adapters.ServerListAdapter
;
import
cn.garymb.ygomobile.ui.adapters.SimpleListAdapter
;
import
cn.garymb.ygomobile.ui.cards.CardDetailRandom
;
import
cn.garymb.ygomobile.ui.cards.CardSearchAc
i
tivity
;
import
cn.garymb.ygomobile.ui.cards.CardSearchActivity
;
import
cn.garymb.ygomobile.ui.cards.DeckManagerActivity
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckUtils
;
import
cn.garymb.ygomobile.ui.mycard.MyCardActivity
;
...
...
@@ -86,16 +85,14 @@ import cn.garymb.ygomobile.ui.plus.VUiKit;
import
cn.garymb.ygomobile.ui.preference.SettingsActivity
;
import
cn.garymb.ygomobile.ui.widget.Shimmer
;
import
cn.garymb.ygomobile.ui.widget.ShimmerTextView
;
import
cn.garymb.ygomobile.utils.ComponentUtils
;
import
cn.garymb.ygomobile.utils.FileLogUtil
;
import
cn.garymb.ygomobile.utils.ScreenUtil
;
import
cn.garymb.ygomobile.utils.YGOUtil
;
import
ocgcore.CardManager
;
import
ocgcore.DataManager
;
import
ocgcore.data.Card
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
ASSET_SERVER_LIST
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
URL_DONATE
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
URL_DONATE_CN
;
public
abstract
class
HomeActivity
extends
BaseActivity
implements
NavigationView
.
OnNavigationItemSelectedListener
,
OnDuelAssistantListener
{
...
...
@@ -116,7 +113,7 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_home
);
setExitAnimEnable
(
false
);
mCardManager
=
new
CardManager
(
AppsSettings
.
get
().
getDataBaseFile
().
getAbsolutePath
(),
null
);
mCardManager
=
DataManager
.
get
().
getCardManager
(
);
//server list
initServerlist
();
//event
...
...
@@ -125,7 +122,6 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
AnimationShake
();
tv
=
(
ShimmerTextView
)
findViewById
(
R
.
id
.
shimmer_tv
);
toggleAnimation
(
tv
);
QbSdk
.
PreInitCallback
cb
=
new
QbSdk
.
PreInitCallback
()
{
@Override
public
void
onViewInitFinished
(
boolean
arg0
)
{
...
...
@@ -143,8 +139,13 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
};
//x5内核初始化接口
QbSdk
.
initX5Environment
(
this
,
cb
);
if
(!
Constants
.
ACTION_OPEN_GAME
.
equals
(
getIntent
().
getAction
()))
{
Log
.
d
(
Constants
.
TAG
,
"start check update"
);
//check update
Beta
.
checkUpgrade
(
false
,
false
);
}
else
{
Log
.
d
(
Constants
.
TAG
,
"skip check update"
);
}
//初始化决斗助手
initDuelAssistant
();
//萌卡
...
...
@@ -192,8 +193,8 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
@Override
public
void
onCardSearch
(
String
key
,
int
id
)
{
if
(
id
==
ID_MAINACTIVITY
)
{
Intent
intent
=
new
Intent
(
this
,
CardSearchAc
i
tivity
.
class
);
intent
.
putExtra
(
CardSearchAc
i
tivity
.
SEARCH_MESSAGE
,
key
);
Intent
intent
=
new
Intent
(
this
,
CardSearchActivity
.
class
);
intent
.
putExtra
(
CardSearchActivity
.
SEARCH_MESSAGE
,
key
);
startActivity
(
intent
);
}
}
...
...
@@ -294,13 +295,8 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
switch
(
id
)
{
case
R
.
id
.
nav_webpage
:
{
String
url
;
if
(
BuildConfig
.
APPLICATION_ID
==
"cn.garymb.ygomobile.EN"
||
BuildConfig
.
APPLICATION_ID
==
"cn.garymb.ygomobile.KO"
)
{
url
=
URL_DONATE
;
}
else
{
url
=
URL_DONATE_CN
;
}
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
);
intent
.
setData
(
Uri
.
parse
(
url
));
intent
.
setData
(
Uri
.
parse
(
BuildConfig
.
URL_DONATE
));
startActivity
(
intent
);
}
break
;
...
...
@@ -331,10 +327,10 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
mServerListManager
.
addServer
();
break
;
case
R
.
id
.
action_card_search
:
startActivity
(
new
Intent
(
this
,
CardSearchAc
i
tivity
.
class
));
startActivity
(
new
Intent
(
this
,
CardSearchActivity
.
class
));
break
;
case
R
.
id
.
action_deck_manager
:
startActivity
(
new
Intent
(
this
,
DeckManagerActivity
.
getDeckManager
())
);
DeckManagerActivity
.
start
(
this
,
null
);
break
;
case
R
.
id
.
action_join_qq_group
:
String
key
=
"anEjPCDdhLgxtfLre-nT52G1Coye3LkK"
;
...
...
@@ -350,7 +346,7 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
Button
btnTutorial
=
viewDialog
.
findViewById
(
R
.
id
.
tutorial
);
btnMasterRule
.
setOnClickListener
((
v
)
->
{
WebActivity
.
open
(
this
,
getString
(
R
.
string
.
masterrule
),
Constants
.
URL_MASTERRULE_CN
);
WebActivity
.
open
(
this
,
getString
(
R
.
string
.
masterrule
),
Constants
.
URL_MASTER
_
RULE_CN
);
dialog
.
dismiss
();
});
btnTutorial
.
setOnClickListener
((
v
)
->
{
...
...
@@ -595,17 +591,13 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
if
(
isUrl
)
{
Deck
deckInfo
=
new
Deck
(
getString
(
R
.
string
.
rename_deck
)
+
System
.
currentTimeMillis
(),
Uri
.
parse
(
deckMessage
));
File
file
=
deckInfo
.
saveTemp
(
AppsSettings
.
get
().
getDeckDir
());
Intent
startdeck
=
new
Intent
(
this
,
DeckManagerActivity
.
getDeckManager
());
startdeck
.
putExtra
(
Intent
.
EXTRA_TEXT
,
file
.
getAbsolutePath
());
startActivity
(
startdeck
);
DeckManagerActivity
.
start
(
this
,
file
.
getAbsolutePath
());
}
else
{
//如果是卡组文本
try
{
//以当前时间戳作为卡组名保存卡组
File
file
=
DeckUtils
.
save
(
getString
(
R
.
string
.
rename_deck
)
+
System
.
currentTimeMillis
(),
deckMessage
);
Intent
startdeck
=
new
Intent
(
this
,
DeckManagerActivity
.
getDeckManager
());
startdeck
.
putExtra
(
Intent
.
EXTRA_TEXT
,
file
.
getAbsolutePath
());
startActivity
(
startdeck
);
DeckManagerActivity
.
start
(
this
,
file
.
getAbsolutePath
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
Toast
.
makeText
(
this
,
getString
(
R
.
string
.
save_failed_bcos
)
+
e
,
Toast
.
LENGTH_SHORT
).
show
();
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/home/MainActivity.java
View file @
53c30ec3
...
...
@@ -22,16 +22,15 @@ import cn.garymb.ygomobile.AppsSettings;
import
cn.garymb.ygomobile.Constants
;
import
cn.garymb.ygomobile.GameUriManager
;
import
cn.garymb.ygomobile.YGOStarter
;
import
cn.garymb.ygomobile.core.IrrlichtBridge
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.activities.WebActivity
;
import
cn.garymb.ygomobile.ui.cards.CardFavorites
;
import
cn.garymb.ygomobile.ui.plus.DialogPlus
;
import
cn.garymb.ygomobile.ui.plus.VUiKit
;
import
cn.garymb.ygomobile.utils.FileUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
cn.garymb.ygomobile.utils.NetUtils
;
import
cn.garymb.ygomobile.utils.YGOUtil
;
import
ocgcore.ConfigManager
;
import
ocgcore.DataManager
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
ACTION_RELOAD
;
...
...
@@ -50,7 +49,6 @@ public class MainActivity extends HomeActivity {
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
,
};
public
ConfigManager
favConf
=
DataManager
.
openConfig
(
AppsSettings
.
get
().
getSystemConfig
());
ResCheckTask
mResCheckTask
;
private
GameUriManager
mGameUriManager
;
private
ImageUpdater
mImageUpdater
;
...
...
@@ -66,7 +64,7 @@ public class MainActivity extends HomeActivity {
//资源复制
checkRes
();
//加载收藏夹
favConf
.
re
ad
();
CardFavorites
.
get
().
lo
ad
();
}
@SuppressLint
({
"StringFormatMatches"
,
"StringFormatInvalid"
})
...
...
@@ -106,7 +104,7 @@ public class MainActivity extends HomeActivity {
Button
btnTutorial
=
viewDialog
.
findViewById
(
R
.
id
.
tutorial
);
btnMasterRule
.
setOnClickListener
((
v
)
->
{
WebActivity
.
open
(
this
,
getString
(
R
.
string
.
masterrule
),
Constants
.
URL_MASTERRULE_CN
);
WebActivity
.
open
(
this
,
getString
(
R
.
string
.
masterrule
),
Constants
.
URL_MASTER
_
RULE_CN
);
dialog
.
dismiss
();
});
btnTutorial
.
setOnClickListener
((
v
)
->
{
...
...
@@ -190,10 +188,6 @@ public class MainActivity extends HomeActivity {
protected
void
onResume
()
{
super
.
onResume
();
YGOStarter
.
onResumed
(
this
);
//如果游戏Activity已经不存在了,则
if
(!
YGOStarter
.
isGameRunning
(
getActivity
()))
{
sendBroadcast
(
new
Intent
(
IrrlichtBridge
.
ACTION_STOP
).
setPackage
(
getPackageName
()));
}
}
@Override
...
...
@@ -316,5 +310,4 @@ public class MainActivity extends HomeActivity {
/* checkResourceDownload((result, isNewVersion) -> {
Toast.makeText(this, R.string.tip_reset_game_res, Toast.LENGTH_SHORT).show();
});*/
}
mobile/src/main/java/cn/garymb/ygomobile/ui/home/ResCheckTask.java
View file @
53c30ec3
...
...
@@ -379,9 +379,8 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
}
private
void
fixString
(
String
stringfile
)
{
String
encoding
=
"utf-8"
;
List
<
String
>
lines
=
FileUtils
.
readLines
(
stringfile
,
encoding
);
FileUtils
.
writeLines
(
stringfile
,
lines
,
encoding
,
"\n"
);
List
<
String
>
lines
=
FileUtils
.
readLines
(
stringfile
,
Constants
.
DEF_ENCODING
);
FileUtils
.
writeLines
(
stringfile
,
lines
,
Constants
.
DEF_ENCODING
,
"\n"
);
}
public
void
checkWindbot
()
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/fragments/SettingFragment.java
View file @
53c30ec3
...
...
@@ -58,7 +58,6 @@ import static cn.garymb.ygomobile.Constants.PERF_TEST_REPLACE_KERNEL;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_CHANGE_LOG
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_CHECK_UPDATE
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_DECK_DELETE_DILAOG
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_DECK_MANAGER_V2
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_DEL_EX
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_FONT_ANTIALIAS
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
PREF_FONT_SIZE
;
...
...
@@ -138,7 +137,6 @@ public class SettingFragment extends PreferenceFragmentPlus {
bind
(
PREF_GAME_FONT
,
mSettings
.
getFontPath
());
bind
(
PREF_READ_EX
,
mSettings
.
isReadExpansions
());
bind
(
PREF_DEL_EX
,
getString
(
R
.
string
.
about_delete_ex
));
bind
(
PREF_DECK_MANAGER_V2
,
mSettings
.
isUseDeckManagerV2
());
bind
(
PERF_TEST_REPLACE_KERNEL
,
"需root权限,请在开发者的指导下食用"
);
Preference
preference
=
findPreference
(
PREF_READ_EX
);
if
(
preference
!=
null
)
{
...
...
mobile/src/main/java/com/ourygo/assistant/service/DuelAssistantService.java
View file @
53c30ec3
...
...
@@ -42,7 +42,7 @@ import cn.garymb.ygomobile.bean.ServerInfo;
import
cn.garymb.ygomobile.bean.ServerList
;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.adapters.ServerListAdapter
;
import
cn.garymb.ygomobile.ui.cards.CardSearchAc
i
tivity
;
import
cn.garymb.ygomobile.ui.cards.CardSearchActivity
;
import
cn.garymb.ygomobile.ui.cards.DeckManagerActivity
;
import
cn.garymb.ygomobile.ui.cards.deck.DeckUtils
;
import
cn.garymb.ygomobile.ui.home.MainActivity
;
...
...
@@ -236,19 +236,13 @@ public class DuelAssistantService extends Service implements OnDuelAssistantList
if
(
isUrl
)
{
Deck
deckInfo
=
new
Deck
(
getString
(
R
.
string
.
rename_deck
)
+
System
.
currentTimeMillis
(),
Uri
.
parse
(
deckMessage
));
File
file
=
deckInfo
.
saveTemp
(
AppsSettings
.
get
().
getDeckDir
());
Intent
startdeck
=
new
Intent
(
DuelAssistantService
.
this
,
DeckManagerActivity
.
getDeckManager
());
startdeck
.
putExtra
(
Intent
.
EXTRA_TEXT
,
file
.
getAbsolutePath
());
startdeck
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
startActivity
(
startdeck
);
DeckManagerActivity
.
start
(
DuelAssistantService
.
this
,
file
.
getAbsolutePath
());
}
else
{
//如果是卡组文本
try
{
//以当前时间戳作为卡组名保存卡组
File
file
=
DeckUtils
.
save
(
getString
(
R
.
string
.
rename_deck
)
+
System
.
currentTimeMillis
(),
deckMessage
);
Intent
startdeck
=
new
Intent
(
DuelAssistantService
.
this
,
DeckManagerActivity
.
getDeckManager
());
startdeck
.
putExtra
(
Intent
.
EXTRA_TEXT
,
file
.
getAbsolutePath
());
startdeck
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
startActivity
(
startdeck
);
DeckManagerActivity
.
start
(
DuelAssistantService
.
this
,
file
.
getAbsolutePath
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
Toast
.
makeText
(
DuelAssistantService
.
this
,
getString
(
R
.
string
.
save_failed_bcos
)
+
e
,
Toast
.
LENGTH_SHORT
).
show
();
...
...
@@ -378,9 +372,9 @@ public class DuelAssistantService extends Service implements OnDuelAssistantList
@Override
public
void
onCardSearch
(
String
key
,
int
id
)
{
if
(
id
==
ClipManagement
.
ID_CLIP_LISTENER
)
{
Intent
intent
=
new
Intent
(
DuelAssistantService
.
this
,
CardSearchAc
i
tivity
.
class
);
Intent
intent
=
new
Intent
(
DuelAssistantService
.
this
,
CardSearchActivity
.
class
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
intent
.
putExtra
(
CardSearchAc
i
tivity
.
SEARCH_MESSAGE
,
key
);
intent
.
putExtra
(
CardSearchActivity
.
SEARCH_MESSAGE
,
key
);
startActivity
(
intent
);
}
}
...
...
mobile/src/main/java/ocgcore/ConfigManager.java
deleted
100644 → 0
View file @
712747e2
package
ocgcore
;
import
java.io.BufferedReader
;
import
java.io.BufferedWriter
;
import
java.io.Closeable
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStreamWriter
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Locale
;
import
cn.garymb.ygomobile.utils.IOUtils
;
public
class
ConfigManager
implements
Closeable
{
public
static
List
<
Integer
>
mLines
=
new
ArrayList
<>();
private
File
file
;
ConfigManager
(
File
file
)
{
this
.
file
=
file
;
}
@Override
public
void
close
()
{
mLines
.
clear
();
}
public
void
read
()
{
mLines
.
clear
();
InputStreamReader
in
=
null
;
FileInputStream
inputStream
=
null
;
try
{
inputStream
=
new
FileInputStream
(
file
);
in
=
new
InputStreamReader
(
inputStream
,
"utf-8"
);
BufferedReader
reader
=
new
BufferedReader
(
in
);
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
if
(
line
.
startsWith
(
"#"
))
continue
;
mLines
.
add
(
Integer
.
parseInt
(
line
));
}
}
catch
(
Exception
e
)
{
}
finally
{
IOUtils
.
close
(
in
);
IOUtils
.
close
(
inputStream
);
}
}
//暂时弃用
public
boolean
isLoad
()
{
return
mLines
.
size
()
>
0
;
}
public
void
save
(
String
words
)
{
//if (!isLoad()) {
// read();
//}
OutputStreamWriter
out
=
null
;
FileOutputStream
outputStream
=
null
;
File
tmp
=
new
File
(
file
.
getAbsolutePath
()
+
".tmp"
);
boolean
ok
=
false
;
try
{
outputStream
=
new
FileOutputStream
(
tmp
);
out
=
new
OutputStreamWriter
(
outputStream
,
"utf-8"
);
BufferedWriter
writer
=
new
BufferedWriter
(
out
);
if
(
words
!=
null
||
words
!=
""
)
{
writer
.
write
(
words
);
writer
.
newLine
();
}
int
count
=
mLines
.
size
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
writer
.
write
((
mLines
.
get
(
i
)).
toString
());
if
(
i
<
count
-
1
)
{
writer
.
newLine
();
}
}
writer
.
flush
();
ok
=
true
;
}
catch
(
Exception
e
)
{
}
finally
{
IOUtils
.
close
(
out
);
IOUtils
.
close
(
outputStream
);
}
if
(
ok
)
{
if
(
file
.
exists
())
{
file
.
delete
();
}
tmp
.
renameTo
(
file
);
}
}
//已弃用通过system.conf设置字体大小
public
void
setFontSize
(
int
size
)
{
if
(!
isLoad
())
{
read
();
}
int
count
=
mLines
.
size
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
String
line
=
mLines
.
get
(
i
).
toString
();
if
(
line
==
null
)
continue
;
line
=
line
.
toLowerCase
(
Locale
.
US
);
if
(
line
.
contains
(
"textfont"
))
{
String
[]
values
=
line
.
split
(
"="
);
if
(
values
.
length
>
1
)
{
String
key
=
values
[
0
];
String
val
=
values
[
1
];
String
newline
=
key
+
"= "
;
String
[]
vs
=
val
.
trim
().
split
(
" "
);
newline
+=
vs
[
0
]
+
" "
+
size
;
mLines
.
add
(
i
,
Integer
.
parseInt
(
newline
));
mLines
.
remove
(
i
+
1
);
}
}
}
save
(
""
);
}
}
mobile/src/main/res/color/selector_text_color_white_gold.xml
0 → 100644
View file @
53c30ec3
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item
android:color=
"@color/gold"
android:state_selected=
"true"
/>
<item
android:color=
"@color/white"
/>
</selector>
\ No newline at end of file
mobile/src/main/res/layout/activity_deck_cards2.xml
deleted
100644 → 0
View file @
712747e2
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<androidx.drawerlayout.widget.DrawerLayout
android:id=
"@+id/drawer_layout"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<FrameLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<include
layout=
"@layout/content_toolbar_list"
/>
<LinearLayout
android:id=
"@+id/layout_main"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@drawable/bg3"
android:orientation=
"vertical"
>
<View
android:layout_width=
"match_parent"
android:layout_height=
"?attr/actionBarSize"
/>
<cn.garymb.ygomobile.ui.widget.DeckGroupView
android:id=
"@+id/deck_group"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
<cn.garymb.ygomobile.ui.widget.DeckView
android:id=
"@+id/deckview"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:visibility=
"gone"
/>
<CheckBox
android:id=
"@+id/chk_autosort"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:checked=
"true"
android:text=
"自动排序"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"horizontal"
>
<Button
android:id=
"@+id/btn_edit_delete"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:text=
"删除模式"
/>
<Button
android:id=
"@+id/btn_edit_main2side"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:text=
"主卡组到副卡组"
/>
<Button
android:id=
"@+id/btn_edit_side2main"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:text=
"副卡组到主卡组"
/>
<Button
android:id=
"@+id/btn_delete"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:enabled=
"false"
android:text=
"完成"
/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_gravity=
"left"
android:background=
"@android:color/transparent"
android:orientation=
"vertical"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"@drawable/blue"
android:orientation=
"vertical"
android:paddingLeft=
"4dp"
android:paddingTop=
"2dp"
android:paddingRight=
"4dp"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"@dimen/item_height"
android:layout_marginLeft=
"20dp"
android:layout_marginTop=
"10dp"
android:layout_marginRight=
"30dp"
android:layout_marginBottom=
"4dp"
>
<androidx.appcompat.widget.AppCompatSpinner
android:id=
"@+id/sp_limit_list"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
</LinearLayout>
<com.tubb.smrv.SwipeMenuRecyclerView
android:id=
"@+id/list_cards"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:divider=
"@android:color/transparent"
android:dividerHeight=
"4dp"
android:padding=
"2dp"
android:scrollbars=
"none"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_gravity=
"right"
android:background=
"@android:color/transparent"
android:orientation=
"vertical"
>
<include
android:id=
"@+id/nav_view_list"
layout=
"@layout/nav_card_search"
/>
</LinearLayout>
</androidx.drawerlayout.widget.DrawerLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
mobile/src/main/res/layout/activity_deck_cards3.xml
deleted
100644 → 0
View file @
712747e2
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<androidx.drawerlayout.widget.DrawerLayout
android:id=
"@+id/drawer_layout"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<FrameLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<include
layout=
"@layout/content_toolbar_list"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@drawable/bg3"
android:orientation=
"vertical"
>
<View
android:layout_width=
"match_parent"
android:layout_height=
"?attr/actionBarSize"
android:layout_marginBottom=
"5dp"
/>
<androidx.recyclerview.widget.RecyclerView
android:id=
"@+id/recyclerview"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
>
<Button
android:id=
"@+id/refresh"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:text=
"refresh"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_gravity=
"left"
android:background=
"@android:color/transparent"
android:orientation=
"vertical"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"@drawable/blue"
android:orientation=
"vertical"
android:paddingLeft=
"4dp"
android:paddingTop=
"2dp"
android:paddingRight=
"4dp"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"@dimen/item_height"
android:layout_marginLeft=
"20dp"
android:layout_marginTop=
"10dp"
android:layout_marginRight=
"30dp"
android:layout_marginBottom=
"4dp"
>
<androidx.appcompat.widget.AppCompatSpinner
android:id=
"@+id/sp_limit_list"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
</LinearLayout>
<com.tubb.smrv.SwipeMenuRecyclerView
android:id=
"@+id/list_cards"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:divider=
"@android:color/transparent"
android:dividerHeight=
"4dp"
android:padding=
"2dp"
android:scrollbars=
"none"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_gravity=
"right"
android:background=
"@android:color/transparent"
android:orientation=
"vertical"
>
<include
android:id=
"@+id/nav_view_list"
layout=
"@layout/nav_card_search"
/>
</LinearLayout>
</androidx.drawerlayout.widget.DrawerLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
mobile/src/main/res/layout/nav_card_search.xml
View file @
53c30ec3
...
...
@@ -46,6 +46,7 @@
android:layout_weight=
"1"
android:background=
"@color/transparent"
android:text=
"@string/my_favorites"
android:textColor=
"@color/selector_text_color_white_gold"
android:visibility=
"visible"
/>
</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