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 b41bea83
authored
May 18, 2021
by
amateur
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1
1 parent
96ad7691
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
154 additions
and
31 deletions
app/src/main/java/com/polysoft/nafmii/activity/HomeActivity.java
app/src/main/java/com/polysoft/nafmii/activity/home/ModuleUrlHandle.java
app/src/main/java/com/polysoft/nafmii/activity/home/ModulesFragmentMgr.java
app/src/main/java/com/polysoft/nafmii/constants/Constants.java
app/src/main/java/com/polysoft/nafmii/activity/HomeActivity.java
View file @
b41bea8
...
@@ -8,10 +8,9 @@ import androidx.fragment.app.Fragment;
...
@@ -8,10 +8,9 @@ import androidx.fragment.app.Fragment;
import
androidx.fragment.app.FragmentManager
;
import
androidx.fragment.app.FragmentManager
;
import
com.polysoft.nafmii.R
;
import
com.polysoft.nafmii.R
;
import
com.polysoft.nafmii.activity.home.ModulesFragmentMgr
;
import
com.polysoft.nafmii.bean.MenuBean
;
import
com.polysoft.nafmii.bean.MenuBean
;
import
com.polysoft.nafmii.enums.ModulesEnum
;
import
com.polysoft.nafmii.enums.ModulesEnum
;
import
com.polysoft.nafmii.activity.home.ModulesFragmentMgr
;
import
com.polysoft.nafmii.utils.SpUtils
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Iterator
;
...
@@ -52,12 +51,12 @@ public class HomeActivity extends WebviewActivity implements View.OnClickListene
...
@@ -52,12 +51,12 @@ public class HomeActivity extends WebviewActivity implements View.OnClickListene
private
void
initHomeModule
()
{
private
void
initHomeModule
()
{
FragmentManager
fragmentManager
=
super
.
getSupportFragmentManager
();
FragmentManager
fragmentManager
=
super
.
getSupportFragmentManager
();
int
containerId
=
R
.
id
.
home_container_framelayout
;
int
containerId
=
R
.
id
.
home_container_framelayout
;
this
.
modulesMgr
=
new
ModulesFragmentMgr
(
fragmentManager
,
containerId
);
this
.
modulesMgr
=
new
ModulesFragmentMgr
(
this
,
containerId
);
this
.
modulesMgr
.
addChangeModuleLsitener
(
this
);
this
.
modulesMgr
.
addChangeModuleLsitener
(
this
);
this
.
modulesMgr
.
showInitFragment
(
new
ModulesEnum
[]{
this
.
modulesMgr
.
showInitFragment
(
new
ModulesEnum
[]{
ModulesEnum
.
HOME
,
ModulesEnum
.
MEMBER
,
ModulesEnum
.
HOME
,
ModulesEnum
.
MEMBER
,
ModulesEnum
.
LEARN
,
ModulesEnum
.
MY
ModulesEnum
.
LEARN
,
ModulesEnum
.
MY
}
,
getIntent
().
getStringExtra
(
ModulesEnum
.
HOME
.
name
)
);
});
}
}
...
...
app/src/main/java/com/polysoft/nafmii/activity/home/ModuleUrlHandle.java
0 → 100644
View file @
b41bea8
package
com
.
polysoft
.
nafmii
.
activity
.
home
;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.text.TextUtils
;
import
com.polysoft.nafmii.bean.MenuBean
;
import
com.polysoft.nafmii.constants.Constants
;
import
com.polysoft.nafmii.constants.JsApi
;
import
com.polysoft.nafmii.enums.ModulesEnum
;
import
com.polysoft.nafmii.webview.IWebview
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
ModuleUrlHandle
{
private
Map
<
String
,
IModuleHandle
>
handleMap
=
new
HashMap
<>();
private
Activity
activity
;
ModuleUrlHandle
(
Activity
activity
)
{
this
.
activity
=
activity
;
}
public
IModuleHandle
getModuleHandle
(
ModulesEnum
module
)
{
return
new
ModuleUrlImpl
(
activity
,
module
);
}
public
IModuleHandle
getModuleHandle
(
MenuBean
bean
)
{
return
new
ModuleBeanImpl
(
bean
);
}
public
String
getModuleUrl
(
ModulesEnum
module
)
{
Intent
intent
=
activity
.
getIntent
();
String
url
=
intent
.
getStringExtra
(
module
.
name
);
if
(!
TextUtils
.
isEmpty
(
url
))
{
return
url
;
}
if
(
module
==
ModulesEnum
.
HOME
)
{
return
Constants
.
MODULE_URL_HOME
;
}
else
if
(
module
==
ModulesEnum
.
LEARN
)
{
return
Constants
.
MODULE_URL_LEARN
;
}
return
""
;
}
public
interface
IModuleHandle
{
ModulesEnum
getModule
();
void
loadUrl
(
IWebview
webview
);
}
class
ModuleBeanImpl
implements
IModuleHandle
{
private
MenuBean
bean
;
ModuleBeanImpl
(
MenuBean
bean
)
{
this
.
bean
=
bean
;
}
@Override
public
ModulesEnum
getModule
()
{
return
ModulesEnum
.
findModule
(
this
.
bean
.
getModuleName
());
}
@Override
public
void
loadUrl
(
IWebview
webview
)
{
if
(!
TextUtils
.
isEmpty
(
bean
.
getUrl
()))
{
webview
.
loadUrl
(
bean
.
getUrl
());
}
else
if
(!
TextUtils
.
isEmpty
(
bean
.
getRouteName
()))
{
webview
.
callJs
(
JsApi
.
API_ROUTE
,
""
);
}
else
if
(!
TextUtils
.
isEmpty
(
bean
.
getRoutePath
()))
{
webview
.
callJs
(
JsApi
.
API_ROUTE
,
""
);
}
}
}
class
ModuleUrlImpl
implements
IModuleHandle
{
private
Activity
mActivity
;
private
ModulesEnum
module
;
ModuleUrlImpl
(
Activity
mActivity
,
ModulesEnum
module
)
{
this
.
mActivity
=
mActivity
;
this
.
module
=
module
;
}
@Override
public
ModulesEnum
getModule
()
{
return
this
.
module
;
}
@Override
public
void
loadUrl
(
IWebview
webview
)
{
Intent
intent
=
activity
.
getIntent
();
String
url
=
intent
.
getStringExtra
(
module
.
name
);
if
(!
TextUtils
.
isEmpty
(
url
))
{
if
(
module
==
ModulesEnum
.
MEMBER
)
{
webview
.
callJs
(
JsApi
.
API_ROUTE
,
""
);
}
else
if
(
module
==
ModulesEnum
.
MY
)
{
webview
.
callJs
(
JsApi
.
API_ROUTE
,
""
);
}
else
{
webview
.
loadUrl
(
url
);
}
return
;
}
if
(
module
==
ModulesEnum
.
HOME
)
{
webview
.
loadUrl
(
Constants
.
MODULE_URL_HOME
);
}
else
if
(
ModulesEnum
.
LEARN
==
module
)
{
webview
.
loadUrl
(
Constants
.
MODULE_URL_LEARN
);
}
else
if
(
ModulesEnum
.
MEMBER
==
module
)
{
webview
.
loadUrl
(
Constants
.
MODULE_URL_MEMBER
);
}
else
if
(
ModulesEnum
.
MY
==
module
)
{
webview
.
loadUrl
(
Constants
.
MODULE_URL_MY
);
}
}
}
}
app/src/main/java/com/polysoft/nafmii/activity/home/ModulesFragmentMgr.java
View file @
b41bea8
package
com
.
polysoft
.
nafmii
.
activity
.
home
;
package
com
.
polysoft
.
nafmii
.
activity
.
home
;
import
android.text.TextUtils
;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.FragmentActivity
;
import
androidx.fragment.app.FragmentManager
;
import
androidx.fragment.app.FragmentManager
;
import
androidx.fragment.app.FragmentTransaction
;
import
androidx.fragment.app.FragmentTransaction
;
...
@@ -19,10 +18,12 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
...
@@ -19,10 +18,12 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
private
int
containerId
;
private
int
containerId
;
private
ModulesEnum
currentModule
;
private
ModulesEnum
currentModule
;
private
OnChangeModuleListener
changeListener
;
private
OnChangeModuleListener
changeListener
;
private
ModuleUrlHandle
moduleHandle
;
public
ModulesFragmentMgr
(
Fragment
Manager
manager
,
int
containerId
)
{
public
ModulesFragmentMgr
(
Fragment
Activity
activity
,
int
containerId
)
{
this
.
manager
=
manager
;
this
.
manager
=
activity
.
getSupportFragmentManager
()
;
this
.
containerId
=
containerId
;
this
.
containerId
=
containerId
;
this
.
moduleHandle
=
new
ModuleUrlHandle
(
activity
);
manager
.
addOnBackStackChangedListener
(
this
);
manager
.
addOnBackStackChangedListener
(
this
);
}
}
...
@@ -31,14 +32,12 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
...
@@ -31,14 +32,12 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
this
.
changeListener
=
listener
;
this
.
changeListener
=
listener
;
}
}
public
void
showInitFragment
(
ModulesEnum
[]
modules
,
String
url
)
{
public
void
showInitFragment
(
ModulesEnum
[]
modules
)
{
WebViewFragment
fragment
=
this
.
addModuleFragment
(
modules
[
0
],
url
);
for
(
int
i
=
0
;
i
<
modules
.
length
;
i
++)
{
for
(
int
i
=
1
;
i
<
modules
.
length
;
i
++)
{
this
.
addModuleFragment
(
modules
[
i
]);
this
.
addModuleFragment
(
modules
[
i
]);
}
}
//
WebViewFragment fragment = this.findFragment(modules[0]);
WebViewFragment
fragment
=
this
.
findFragment
(
modules
[
0
]);
FragmentTransaction
transaction
=
this
.
manager
.
beginTransaction
();
FragmentTransaction
transaction
=
this
.
manager
.
beginTransaction
();
transaction
.
show
(
fragment
).
commitNow
();
transaction
.
show
(
fragment
).
commitNow
();
this
.
setCurrentModule
(
modules
[
0
]);
this
.
setCurrentModule
(
modules
[
0
]);
...
@@ -65,28 +64,23 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
...
@@ -65,28 +64,23 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
if
(
module
==
this
.
currentModule
)
{
if
(
module
==
this
.
currentModule
)
{
return
;
return
;
}
}
WebViewFragment
fragment
=
this
.
findFragment
(
module
);
this
.
showModule
(
this
.
moduleHandle
.
getModuleHandle
(
module
));
if
(!
module
.
fmtKey
.
equals
(
this
.
currentModule
.
fmtKey
))
{
FragmentTransaction
transaction
=
this
.
manager
.
beginTransaction
();
transaction
.
hide
(
this
.
getCurrentFragment
());
transaction
.
addToBackStack
(
""
).
show
(
fragment
).
commit
();
}
else
{
fragment
.
getWebview
().
loadUrl
(
module
.
webUrl
);
}
this
.
setCurrentModule
(
module
);
}
}
public
void
showModule
(
MenuBean
bean
)
{
public
void
showModule
(
MenuBean
bean
)
{
ModulesEnum
module
=
ModulesEnum
.
findModule
(
bean
.
getModuleName
());
this
.
showModule
(
moduleHandle
.
getModuleHandle
(
bean
));
}
private
void
showModule
(
ModuleUrlHandle
.
IModuleHandle
handle
)
{
ModulesEnum
module
=
handle
.
getModule
();
WebViewFragment
fragment
=
this
.
findFragment
(
module
);
WebViewFragment
fragment
=
this
.
findFragment
(
module
);
if
(!
TextUtils
.
isEmpty
(
bean
.
getUrl
()))
{
fragment
.
getWebview
().
loadUrl
(
bean
.
getUrl
());
}
if
(!
module
.
fmtKey
.
equals
(
this
.
currentModule
.
fmtKey
))
{
if
(!
module
.
fmtKey
.
equals
(
this
.
currentModule
.
fmtKey
))
{
FragmentTransaction
transaction
=
this
.
manager
.
beginTransaction
();
FragmentTransaction
transaction
=
this
.
manager
.
beginTransaction
();
transaction
.
hide
(
this
.
getCurrentFragment
());
transaction
.
hide
(
this
.
getCurrentFragment
());
transaction
.
addToBackStack
(
""
).
show
(
fragment
).
commit
();
transaction
.
addToBackStack
(
""
).
show
(
fragment
).
commit
();
}
else
{
handle
.
loadUrl
(
fragment
.
getWebview
());
}
}
this
.
setCurrentModule
(
module
);
this
.
setCurrentModule
(
module
);
}
}
...
@@ -96,14 +90,10 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
...
@@ -96,14 +90,10 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
}
}
private
WebViewFragment
addModuleFragment
(
ModulesEnum
module
)
{
private
WebViewFragment
addModuleFragment
(
ModulesEnum
module
)
{
return
addModuleFragment
(
module
,
null
);
}
private
WebViewFragment
addModuleFragment
(
ModulesEnum
module
,
String
url
)
{
WebViewFragment
fragment
=
(
WebViewFragment
)
this
.
manager
.
findFragmentByTag
(
module
.
fmtKey
);
WebViewFragment
fragment
=
(
WebViewFragment
)
this
.
manager
.
findFragmentByTag
(
module
.
fmtKey
);
if
(
null
==
fragment
)
{
if
(
null
==
fragment
)
{
FragmentTransaction
transaction
=
this
.
manager
.
beginTransaction
();
FragmentTransaction
transaction
=
this
.
manager
.
beginTransaction
();
fragment
=
WebViewFragment
.
newInstances
(
!
TextUtils
.
isEmpty
(
url
)
?
url
:
module
.
webUrl
);
fragment
=
WebViewFragment
.
newInstances
(
this
.
moduleHandle
.
getModuleUrl
(
module
)
);
transaction
.
add
(
this
.
containerId
,
fragment
,
module
.
fmtKey
).
hide
(
fragment
).
commitNow
();
transaction
.
add
(
this
.
containerId
,
fragment
,
module
.
fmtKey
).
hide
(
fragment
).
commitNow
();
}
}
return
fragment
;
return
fragment
;
...
...
app/src/main/java/com/polysoft/nafmii/constants/Constants.java
0 → 100644
View file @
b41bea8
package
com
.
polysoft
.
nafmii
.
constants
;
public
class
Constants
{
public
static
final
String
MODULE_URL_HOME
=
"file:///android_asset/dist/index.html#/"
;
public
static
final
String
MODULE_URL_MY
=
""
;
public
static
final
String
MODULE_URL_MEMBER
=
""
;
public
static
final
String
MODULE_URL_LEARN
=
"http://debugtbs.qq.com"
;
public
static
final
String
MODULE_ROUTE_MY
=
""
;
public
static
final
String
MODULE_ROUTE_MEMBER
=
""
;
}
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