Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-android
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5b24f83e
authored
May 13, 2021
by
amateur
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改多个模块支持同一个fragment
1 parent
4e6ad246
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
13 deletions
app/src/main/java/com/polysoft/nafmii/enums/ModulesEnum.java
app/src/main/java/com/polysoft/nafmii/fragment/ModulesFragmentMgr.java
app/src/main/java/com/polysoft/nafmii/enums/ModulesEnum.java
View file @
5b24f83
...
...
@@ -2,16 +2,18 @@ package com.polysoft.nafmii.enums;
public
enum
ModulesEnum
{
HOME
(
"home"
,
"
file:///android_asset/webpage/fileChooser
.html"
),
MEMBER
(
"member"
,
"
file:///android_asset/webpage/fileChooser
.html"
),
LEARN
(
"learn"
,
"http://debugtbs.qq.com"
),
MY
(
"my"
,
"h
ttp://192.168.43.183:8080
"
);
HOME
(
"home"
,
"
home"
,
"file:///android_asset/dist/index
.html"
),
MEMBER
(
"member"
,
"
home"
,
"file:///android_asset/dict/index
.html"
),
LEARN
(
"learn"
,
"
learn"
,
"
http://debugtbs.qq.com"
),
MY
(
"my"
,
"h
ome"
,
"file:///android_asset/dist/index.html/#/user/center
"
);
public
final
String
name
;
public
final
String
fmtKey
;
public
final
String
webUrl
;
ModulesEnum
(
String
tag
,
String
url
)
{
this
.
name
=
tag
;
ModulesEnum
(
String
name
,
String
fmtKey
,
String
url
)
{
this
.
name
=
name
;
this
.
fmtKey
=
fmtKey
;
this
.
webUrl
=
url
;
}
...
...
app/src/main/java/com/polysoft/nafmii/fragment/ModulesFragmentMgr.java
View file @
5b24f83
...
...
@@ -25,17 +25,18 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
}
public
void
showInitFragment
(
ModulesEnum
[]
modules
)
{
for
(
int
i
=
1
;
i
<
modules
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
modules
.
length
;
i
++)
{
this
.
addModuleFragment
(
modules
[
i
]);
}
Fragment
fragment
=
this
.
addModuleFragment
(
modules
[
0
]);
Fragment
fragment
=
this
.
manager
.
findFragmentByTag
(
modules
[
0
].
fmtKey
);
FragmentTransaction
transaction
=
this
.
manager
.
beginTransaction
();
transaction
.
show
(
fragment
).
commitNow
();
this
.
setCurrentModule
(
modules
[
0
]);
}
public
Fragment
getCurrentFragment
()
{
String
tag
=
this
.
currentModule
.
name
;
String
tag
=
this
.
currentModule
.
fmtKey
;
return
this
.
manager
.
findFragmentByTag
(
tag
);
}
...
...
@@ -54,13 +55,15 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
}
Fragment
fragment
=
this
.
findFragment
(
module
);
FragmentTransaction
transaction
=
this
.
manager
.
beginTransaction
();
if
(!
module
.
fmtKey
.
equals
(
this
.
currentModule
.
fmtKey
))
{
transaction
.
hide
(
this
.
getCurrentFragment
());
transaction
.
addToBackStack
(
""
).
show
(
fragment
).
commit
();
}
this
.
setCurrentModule
(
module
);
}
public
Fragment
findFragment
(
ModulesEnum
module
)
{
Fragment
fragment
=
this
.
manager
.
findFragmentByTag
(
module
.
name
);
Fragment
fragment
=
this
.
manager
.
findFragmentByTag
(
module
.
fmtKey
);
if
(
null
==
fragment
)
{
return
this
.
addModuleFragment
(
module
);
}
...
...
@@ -68,9 +71,12 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
}
private
Fragment
addModuleFragment
(
ModulesEnum
module
)
{
Fragment
fragment
=
this
.
manager
.
findFragmentByTag
(
module
.
fmtKey
);
if
(
null
==
fragment
)
{
FragmentTransaction
transaction
=
this
.
manager
.
beginTransaction
();
Fragment
fragment
=
WebViewFragment
.
newInstances
(
module
.
webUrl
);
transaction
.
add
(
this
.
containerId
,
fragment
,
module
.
name
).
hide
(
fragment
).
commitNow
();
fragment
=
WebViewFragment
.
newInstances
(
module
.
webUrl
);
transaction
.
add
(
this
.
containerId
,
fragment
,
module
.
fmtKey
).
hide
(
fragment
).
commitNow
();
}
return
fragment
;
}
...
...
@@ -89,7 +95,7 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
Fragment
fragment
=
fragments
.
get
(
i
);
if
(
fragment
.
isVisible
())
{
setCurrentModule
(
ModulesEnum
.
findModule
(
fragment
.
getTag
()));
return
;
return
;
}
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment