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
823d7c33
Commit
823d7c33
authored
Jun 24, 2022
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
实现fragment切换无需重载
删除无用布局
parent
495261d1
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
54 additions
and
162 deletions
+54
-162
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
...c/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
+45
-13
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeFragment.java
...c/main/java/cn/garymb/ygomobile/ui/home/HomeFragment.java
+0
-7
mobile/src/main/res/layout/activity_home.xml
mobile/src/main/res/layout/activity_home.xml
+8
-1
mobile/src/main/res/layout/nav_card_search.xml
mobile/src/main/res/layout/nav_card_search.xml
+1
-4
mobile/src/main/res/menu/bottom_nav_menu.xml
mobile/src/main/res/menu/bottom_nav_menu.xml
+0
-29
mobile/src/main/res/menu/card_search2.xml
mobile/src/main/res/menu/card_search2.xml
+0
-10
mobile/src/main/res/menu/main.xml
mobile/src/main/res/menu/main.xml
+0
-19
mobile/src/main/res/menu/nav_main_menu.xml
mobile/src/main/res/menu/nav_main_menu.xml
+0
-50
mobile/src/main/res/navigation/mobile_navigation.xml
mobile/src/main/res/navigation/mobile_navigation.xml
+0
-29
No files found.
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
View file @
823d7c33
...
...
@@ -7,9 +7,12 @@ import android.os.Handler;
import
android.view.Gravity
;
import
android.view.Menu
;
import
android.view.MenuItem
;
import
android.widget.FrameLayout
;
import
android.widget.Toast
;
import
androidx.annotation.Nullable
;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.FragmentTransaction
;
import
androidx.navigation.ui.AppBarConfiguration
;
import
com.ashokvarma.bottomnavigation.BottomNavigationBar
;
...
...
@@ -45,6 +48,11 @@ public abstract class HomeActivity extends BaseActivity implements OnDuelAssista
long
exitLasttime
=
0
;
private
BottomNavigationBar
bottomNavigationBar
;
private
FrameLayout
frameLayout
;
private
FragmentTransaction
transaction
;
private
Fragment
mFragment
;
private
HomeFragment
fragment_home
;
private
CardSearchFragment
fragment_search
;
private
DeckManagerFragment
fragment_deck_cards
;
...
...
@@ -93,8 +101,9 @@ public abstract class HomeActivity extends BaseActivity implements OnDuelAssista
}
private
void
initBottomNavigationBar
()
{
frameLayout
=
(
FrameLayout
)
findViewById
(
R
.
id
.
fragment_content
);
// 获取页面上的底部导航栏控件
BottomNavigationBar
bottomNavigationBar
=
(
BottomNavigationBar
)
findViewById
(
R
.
id
.
bottom_navigation_bar
);
bottomNavigationBar
=
(
BottomNavigationBar
)
findViewById
(
R
.
id
.
bottom_navigation_bar
);
bottomNavigationBar
.
addItem
(
new
BottomNavigationItem
(
R
.
drawable
.
ic_home
,
R
.
string
.
mc_home
))
.
addItem
(
new
BottomNavigationItem
(
R
.
drawable
.
ic_search
,
R
.
string
.
search
))
...
...
@@ -104,11 +113,27 @@ public abstract class HomeActivity extends BaseActivity implements OnDuelAssista
.
setActiveColor
(
R
.
color
.
holo_blue_bright
)
.
setBarBackgroundColor
(
R
.
color
.
transparent
)
.
setMode
(
BottomNavigationBar
.
MODE_FIXED
)
.
setFirstSelectedPosition
(
0
)
.
initialise
();
//所有的设置需在调用该方法前完成
bottomNavigationBar
.
setTabSelectedListener
(
new
BottomNavigationBar
.
OnTabSelectedListener
()
{
@Override
public
void
onTabSelected
(
int
position
)
{
//未选中->选中
switch
(
position
)
{
case
0
:
switchFragment
(
fragment_home
);
break
;
case
1
:
switchFragment
(
fragment_search
);
break
;
case
2
:
switchFragment
(
fragment_deck_cards
);
break
;
case
3
:
switchFragment
(
fragment_mycard
);
break
;
case
4
:
break
;
}
}
@Override
...
...
@@ -125,16 +150,29 @@ public abstract class HomeActivity extends BaseActivity implements OnDuelAssista
fragment_search
=
new
CardSearchFragment
();
fragment_deck_cards
=
new
DeckManagerFragment
();
fragment_mycard
=
new
MycardFragment
();
mFragment
=
fragment_home
;
getSupportFragmentManager
().
beginTransaction
()
.
add
(
R
.
id
.
fragment_home
,
fragment_home
)
.
add
(
R
.
id
.
fragment_search
,
fragment_search
)
.
add
(
R
.
id
.
fragment_deck_cards
,
fragment_deck_cards
)
.
add
(
R
.
id
.
fragment_mycard
,
fragment_mycard
)
//.add(R.id.fragment_settings,new Fragment())
.
add
(
R
.
id
.
fragment_content
,
fragment_home
)
.
commit
();
getSupportActionBar
().
hide
();
}
private
void
switchFragment
(
Fragment
fragment
)
{
//判断当前显示的Fragment是不是切换的Fragment
if
(
mFragment
!=
fragment
)
{
//判断切换的Fragment是否已经添加过
if
(!
fragment
.
isAdded
())
{
//如果没有,则先把当前的Fragment隐藏,把切换的Fragment添加上
getSupportFragmentManager
().
beginTransaction
().
hide
(
mFragment
)
.
add
(
R
.
id
.
fragment_content
,
fragment
).
commit
();
}
else
{
//如果已经添加过,则先把当前的Fragment隐藏,把切换的Fragment显示出来
getSupportFragmentManager
().
beginTransaction
().
hide
(
mFragment
).
show
(
fragment
).
commit
();
}
mFragment
=
fragment
;
}
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
...
...
@@ -217,12 +255,6 @@ public abstract class HomeActivity extends BaseActivity implements OnDuelAssista
duelAssistantManagement
.
removeDuelAssistantListener
(
this
);
}
@Override
public
boolean
onCreateOptionsMenu
(
Menu
menu
)
{
getMenuInflater
().
inflate
(
R
.
menu
.
main
,
menu
);
return
true
;
}
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
return
super
.
onOptionsItemSelected
(
item
);
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeFragment.java
View file @
823d7c33
...
...
@@ -512,8 +512,6 @@ public class HomeFragment extends BaseFragemnt implements View.OnClickListener {
@Override
public
void
onClick
(
View
v
)
{
switch
(
v
.
getId
())
{
case
R
.
id
.
action_about
:
break
;
case
R
.
id
.
action_game
:
setRandomCardDetail
();
if
(
mCardDetailRandom
!=
null
)
{
...
...
@@ -527,11 +525,6 @@ public class HomeFragment extends BaseFragemnt implements View.OnClickListener {
case
R
.
id
.
action_bot
:
YGOStarter
.
startGame
(
getActivity
(),
null
,
"-k"
,
"-s"
);
break
;
case
R
.
id
.
action_settings
:
{
Intent
intent
=
new
Intent
(
getContext
(),
SettingsActivity
.
class
);
startActivity
(
intent
);
break
;
}
case
R
.
id
.
action_download_ex
:
WebActivity
.
open
(
getContext
(),
getString
(
R
.
string
.
action_download_expansions
),
Constants
.
URL_YGO233_ADVANCE
);
break
;
...
...
mobile/src/main/res/layout/activity_home.xml
View file @
823d7c33
...
...
@@ -7,9 +7,16 @@
android:fitsSystemWindows=
"true"
app:layout_behavior=
"@string/appbar_scrolling_view_behavior"
>
<FrameLayout
android:id=
"@+id/fragment_content"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_weight=
"1"
>
</FrameLayout>
<com.ashokvarma.bottomnavigation.BottomNavigationBar
android:id=
"@+id/bottom_navigation_bar"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_gravity=
"bottom"
/>
android:layout_gravity=
"bottom"
/>
</FrameLayout>
\ No newline at end of file
mobile/src/main/res/layout/nav_card_search.xml
View file @
823d7c33
...
...
@@ -17,10 +17,7 @@
android:layout_marginTop=
"6dp"
android:orientation=
"vertical"
>
<com.google.android.material.textfield.TextInputLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"18dp"
/>
<LinearLayout
android:layout_width=
"match_parent"
...
...
mobile/src/main/res/menu/bottom_nav_menu.xml
deleted
100644 → 0
View file @
495261d1
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<item
android:id=
"@+id/home_fragment"
android:icon=
"@drawable/start"
android:title=
"@string/mc_home"
app:showAsAction=
"always"
/>
<item
android:id=
"@+id/cardSearcher_fragment"
android:icon=
"@drawable/search"
android:title=
"@string/search"
app:showAsAction=
"always"
/>
<item
android:id=
"@+id/deckManager_fragment"
android:icon=
"@drawable/deck"
android:title=
"@string/deck_manager"
app:showAsAction=
"always"
/>
<item
android:id=
"@+id/mycard_fragment"
android:icon=
"@drawable/mycard"
android:title=
"@string/mycard"
app:showAsAction=
"always"
/>
<item
android:id=
"@+id/setting_fragment"
android:icon=
"@drawable/setting"
android:title=
"@string/settings"
app:showAsAction=
"always"
/>
</menu>
\ No newline at end of file
mobile/src/main/res/menu/card_search2.xml
deleted
100644 → 0
View file @
495261d1
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<item
android:id=
"@+id/action_search"
android:icon=
"@drawable/search"
android:title=
"@string/search"
app:showAsAction=
"always"
/>
</menu>
\ No newline at end of file
mobile/src/main/res/menu/main.xml
deleted
100644 → 0
View file @
495261d1
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<item
android:id=
"@+id/action_game"
android:icon=
"@drawable/start"
android:title=
"@string/action_game"
app:showAsAction=
"always"
/>
<item
android:id=
"@+id/action_card_search"
android:icon=
"@drawable/search"
android:title=
"@string/card_search"
app:showAsAction=
"always"
/>
<item
android:id=
"@+id/action_deck_manager"
android:icon=
"@drawable/deck"
android:title=
"@string/deck_manager"
app:showAsAction=
"always"
/>
</menu>
\ No newline at end of file
mobile/src/main/res/menu/nav_main_menu.xml
deleted
100644 → 0
View file @
495261d1
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<item
android:id=
"@+id/action_deck_manager"
android:icon=
"@drawable/ic_edit"
android:title=
"@string/deck_manager"
/>
<item
android:id=
"@+id/action_download_ex"
android:icon=
"@drawable/ic_add"
android:title=
"@string/action_add_server"
/>
<item
android:id=
"@+id/action_join_qq_group"
android:icon=
"@drawable/ic_home_black"
android:title=
"@string/mycard"
/>
<item
android:id=
"@+id/action_reset_game_res"
android:icon=
"@drawable/ic_file_download_black_24dp"
android:title=
"@string/reset_game_res"
/>
<item
android:id=
"@+id/action_replay"
android:icon=
"@drawable/ic_album"
android:title=
"@string/replay"
/>
<item
android:id=
"@+id/action_bot"
android:icon=
"@drawable/ic_copy"
android:title=
"@string/bot_mode"
/>
<item
android:title=
"@string/menu"
>
<menu>
<item
android:id=
"@+id/action_settings"
android:icon=
"@drawable/ic_settings"
android:title=
"@string/action_settings"
/>
<item
android:id=
"@+id/action_help"
android:icon=
"@drawable/ic_live_help"
android:title=
"@string/help"
/>
<item
android:id=
"@+id/action_about"
android:icon=
"@drawable/ic_about"
android:title=
"@string/action_about"
/>
<item
android:id=
"@+id/action_quit"
android:icon=
"@drawable/ic_close_black_24dp"
android:title=
"@string/quit"
/>
</menu>
</item>
</menu>
\ No newline at end of file
mobile/src/main/res/navigation/mobile_navigation.xml
deleted
100644 → 0
View file @
495261d1
<?xml version="1.0" encoding="utf-8"?>
<navigation
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/mobile_navigation"
app:startDestination=
"@+id/home_fragment"
>
<fragment
android:id=
"@+id/home_fragment"
android:name=
"cn.garymb.ygomobile.ui.home.HomeFragment"
tools:layout=
"@layout/fragment_home"
/>
<fragment
android:id=
"@+id/cardSearcher_fragment"
android:name=
"cn.garymb.ygomobile.ui.cards.CardSearchFragment"
tools:layout=
"@layout/fragment_search"
/>
<fragment
android:id=
"@+id/deckManager_fragment"
android:name=
"cn.garymb.ygomobile.ui.cards.DeckManagerFragment"
tools:layout=
"@layout/fragment_deck_cards"
/>
<fragment
android:id=
"@+id/mycard_fragment"
android:name=
"cn.garymb.ygomobile.ui.mycard.MycardFragment"
tools:layout=
"@layout/fragment_mycard"
/>
<fragment
android:id=
"@+id/setting_fragment"
android:name=
"cn.garymb.ygomobile.ui.preference.fragments.SettingFragment"
tools:layout=
"@layout/fragment_settings"
/>
</navigation>
\ No newline at end of file
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