Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
component
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王涛55
component
Commits
0820eb0b
Commit
0820eb0b
authored
Sep 25, 2019
by
王涛55
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:module通信方式优化
parent
e733e5a0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
116 additions
and
12 deletions
+116
-12
ModuleProject/app/src/main/java/com/hikcreate/ui/testActivity.java
+12
-8
ModuleProject/lib_module_common/build.gradle
+1
-0
ModuleProject/lib_module_common/src/main/java/com/hikcreate/module_router/tools/ModuleRouterUtil.java
+88
-4
ModuleProject/lib_module_common/src/main/java/com/hikcreate/module_router/tools/RouterCallBack.java
+15
-0
No files found.
ModuleProject/app/src/main/java/com/hikcreate/ui/testActivity.java
View file @
0820eb0b
...
@@ -11,6 +11,7 @@ import com.hikcreate.data.config.AppProvider;
...
@@ -11,6 +11,7 @@ import com.hikcreate.data.config.AppProvider;
import
com.hikcreate.library.util.LogCat
;
import
com.hikcreate.library.util.LogCat
;
import
com.hikcreate.module_router.router.RouterResponse
;
import
com.hikcreate.module_router.router.RouterResponse
;
import
com.hikcreate.module_router.tools.ModuleRouterUtil
;
import
com.hikcreate.module_router.tools.ModuleRouterUtil
;
import
com.hikcreate.module_router.tools.RouterCallBack
;
import
com.message.bean.GeneralMessageBean
;
import
com.message.bean.GeneralMessageBean
;
import
com.message.driver.MessageWrap
;
import
com.message.driver.MessageWrap
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
...
@@ -36,7 +37,7 @@ public class testActivity extends AppCompatActivity {
...
@@ -36,7 +37,7 @@ public class testActivity extends AppCompatActivity {
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
app_test
);
setContentView
(
R
.
layout
.
app_test
);
findViewById
(
R
.
id
.
mBtnLogin
).
setOnClickListener
(
v
->
{
findViewById
(
R
.
id
.
mBtnLogin
).
setOnClickListener
(
v
->
{
RouterResponse
response
=
ModuleRouterUtil
.
getRouterResponse
(
getApplicationContext
(),
RouterResponse
response
=
ModuleRouterUtil
.
router
(
getApplicationContext
(),
AppProvider
.
LOGIN_PROVIDER
,
AppProvider
.
GET_USER_INFO_ACTION
);
AppProvider
.
LOGIN_PROVIDER
,
AppProvider
.
GET_USER_INFO_ACTION
);
if
(
response
!=
null
)
{
if
(
response
!=
null
)
{
if
(
response
.
getObject
()
!=
null
)
{
if
(
response
.
getObject
()
!=
null
)
{
...
@@ -50,16 +51,19 @@ public class testActivity extends AppCompatActivity {
...
@@ -50,16 +51,19 @@ public class testActivity extends AppCompatActivity {
findViewById
(
R
.
id
.
mBtnLoginSync
).
setOnClickListener
(
v
->
{
findViewById
(
R
.
id
.
mBtnLoginSync
).
setOnClickListener
(
v
->
{
new
Thread
(()
->
{
HashMap
<
String
,
String
>
value
=
new
HashMap
<>();
HashMap
<
String
,
String
>
value
=
new
HashMap
<>();
value
.
put
(
"name"
,
"wangtao"
);
value
.
put
(
"name"
,
"wangtao"
);
value
.
put
(
"mobile"
,
"150000000000"
);
value
.
put
(
"mobile"
,
"150000000000"
);
RouterResponse
response
=
ModuleRouterUtil
.
getRouterResponse
(
getApplicationContext
(),
ModuleRouterUtil
.
routeSyncToUi
(
getApplicationContext
(),
AppProvider
.
USER_INFO_CHANGE_PROVIDER
,
AppProvider
.
USER_INFO_CHANGE_ACTION
,
value
);
AppProvider
.
USER_INFO_CHANGE_PROVIDER
,
AppProvider
.
USER_INFO_CHANGE_ACTION
,
value
,
new
RouterCallBack
()
{
final
String
result
=
response
.
get
();
@Override
runOnUiThread
(()
->
Toast
.
makeText
(
testActivity
.
this
,
result
,
Toast
.
LENGTH_SHORT
).
show
());
public
void
callSuccess
(
RouterResponse
response
)
{
Toast
.
makeText
(
testActivity
.
this
,
response
.
get
(),
Toast
.
LENGTH_SHORT
).
show
();
}).
start
();
}
@Override
public
void
callFail
(
RouterResponse
response
)
{
}
});
});
});
...
...
ModuleProject/lib_module_common/build.gradle
View file @
0820eb0b
...
@@ -34,4 +34,5 @@ android {
...
@@ -34,4 +34,5 @@ android {
dependencies
{
dependencies
{
implementation
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
implementation
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
implementation
deps
.
multidex
implementation
deps
.
multidex
implementation
deps
.
rxandroid2
}
}
ModuleProject/lib_module_common/src/main/java/com/hikcreate/module_router/tools/ModuleRouterUtil.java
View file @
0820eb0b
package
com
.
hikcreate
.
module_router
.
tools
;
package
com
.
hikcreate
.
module_router
.
tools
;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
import
android.content.Context
;
import
com.hikcreate.module_router.LocalRouter
;
import
com.hikcreate.module_router.LocalRouter
;
import
com.hikcreate.module_router.ModuleActionResult
;
import
com.hikcreate.module_router.router.RouterRequest
;
import
com.hikcreate.module_router.router.RouterRequest
;
import
com.hikcreate.module_router.router.RouterResponse
;
import
com.hikcreate.module_router.router.RouterResponse
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
io.reactivex.Observable
;
import
io.reactivex.ObservableEmitter
;
import
io.reactivex.ObservableOnSubscribe
;
import
io.reactivex.ObservableTransformer
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.functions.Consumer
;
import
io.reactivex.schedulers.Schedulers
;
/**
/**
* author : taowang
* author : taowang
* date :2019/9/25
* date :2019/9/25
...
@@ -15,13 +25,87 @@ import java.util.HashMap;
...
@@ -15,13 +25,87 @@ import java.util.HashMap;
**/
**/
public
class
ModuleRouterUtil
{
public
class
ModuleRouterUtil
{
public
static
RouterResponse
getRouterResponse
(
Context
context
,
String
provider
,
String
action
)
{
public
static
RouterResponse
router
(
Context
context
,
String
provider
,
String
action
)
{
return
LocalRouter
.
getInstance
(
context
).
route
(
RouterRequest
.
obtain
(
context
).
provider
(
provider
).
action
(
action
));
return
LocalRouter
.
getInstance
(
context
).
route
(
RouterRequest
.
obtain
(
context
).
provider
(
provider
).
action
(
action
));
}
}
public
static
RouterResponse
getRouterResponse
(
Context
context
,
String
provider
,
String
action
,
public
static
RouterResponse
router
(
Context
context
,
String
provider
,
String
action
,
HashMap
<
String
,
String
>
value
)
{
HashMap
<
String
,
String
>
value
)
{
return
LocalRouter
.
getInstance
(
context
).
route
(
RouterRequest
.
obtain
(
context
).
provider
(
provider
).
data
(
value
).
action
(
action
));
return
LocalRouter
.
getInstance
(
context
).
route
(
RouterRequest
.
obtain
(
context
).
provider
(
provider
).
data
(
value
).
action
(
action
));
}
@SuppressLint
(
"CheckResult"
)
public
static
void
routeSyncToUi
(
Context
context
,
String
provider
,
String
action
,
RouterCallBack
callBack
)
{
Observable
.
create
((
ObservableOnSubscribe
<
RouterResponse
>)
emitter
->
{
emitter
.
onNext
(
LocalRouter
.
getInstance
(
context
).
route
(
RouterRequest
.
obtain
(
context
).
provider
(
provider
).
action
(
action
)));
}).
compose
(
applySchedulers
()).
subscribe
(
routerResponse
->
{
if
(
routerResponse
.
getCode
()
==
ModuleActionResult
.
CODE_SUCCESS
){
callBack
.
callSuccess
(
routerResponse
);
}
else
{
callBack
.
callFail
(
routerResponse
);
}
});
}
@SuppressLint
(
"CheckResult"
)
public
static
void
routeSyncToUi
(
Context
context
,
String
provider
,
String
action
,
HashMap
<
String
,
String
>
value
,
RouterCallBack
callBack
)
{
Observable
.
create
((
ObservableOnSubscribe
<
RouterResponse
>)
emitter
->
{
emitter
.
onNext
(
LocalRouter
.
getInstance
(
context
).
route
(
RouterRequest
.
obtain
(
context
).
data
(
value
).
provider
(
provider
).
action
(
action
)));
}).
compose
(
applySchedulers
()).
subscribe
(
routerResponse
->
{
if
(
routerResponse
.
getCode
()
==
ModuleActionResult
.
CODE_SUCCESS
){
callBack
.
callSuccess
(
routerResponse
);
}
else
{
callBack
.
callFail
(
routerResponse
);
}
});
}
}
@SuppressLint
(
"CheckResult"
)
public
static
void
routerSyncNewThread
(
Context
context
,
String
provider
,
String
action
,
RouterCallBack
callBack
)
{
Observable
.
create
((
ObservableOnSubscribe
<
RouterResponse
>)
emitter
->
{
emitter
.
onNext
(
LocalRouter
.
getInstance
(
context
).
route
(
RouterRequest
.
obtain
(
context
).
provider
(
provider
).
action
(
action
)));
}).
compose
(
applyNewThreadSchedulers
()).
subscribe
(
routerResponse
->
{
if
(
routerResponse
.
getCode
()
==
ModuleActionResult
.
CODE_SUCCESS
){
callBack
.
callSuccess
(
routerResponse
);
}
else
{
callBack
.
callFail
(
routerResponse
);
}
});
}
@SuppressLint
(
"CheckResult"
)
public
static
void
routerSyncNewThread
(
Context
context
,
String
provider
,
String
action
,
HashMap
<
String
,
String
>
value
,
RouterCallBack
callBack
)
{
Observable
.
create
((
ObservableOnSubscribe
<
RouterResponse
>)
emitter
->
{
emitter
.
onNext
(
LocalRouter
.
getInstance
(
context
).
route
(
RouterRequest
.
obtain
(
context
).
provider
(
provider
).
action
(
action
)));
}).
compose
(
applyNewThreadSchedulers
()).
subscribe
(
routerResponse
->
{
if
(
routerResponse
.
getCode
()
==
ModuleActionResult
.
CODE_SUCCESS
){
callBack
.
callSuccess
(
routerResponse
);
}
else
{
callBack
.
callFail
(
routerResponse
);
}
});
}
public
static
<
T
>
ObservableTransformer
<
T
,
T
>
applySchedulers
()
{
return
observable
->
observable
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
());
}
public
static
<
T
>
ObservableTransformer
<
T
,
T
>
applyNewThreadSchedulers
()
{
return
observable
->
observable
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
Schedulers
.
newThread
());
}
}
}
ModuleProject/lib_module_common/src/main/java/com/hikcreate/module_router/tools/RouterCallBack.java
0 → 100644
View file @
0820eb0b
package
com
.
hikcreate
.
module_router
.
tools
;
import
com.hikcreate.module_router.router.RouterResponse
;
/**
* 异步操作回调
*
* @author wangtao55
* @date 2019/9/25
* @mail wangtao55@hikcreate.com
*/
public
interface
RouterCallBack
{
void
callSuccess
(
RouterResponse
response
);
void
callFail
(
RouterResponse
response
);
}
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