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
5 years ago
by
王涛55
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:module通信方式优化
parent
e733e5a0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
15 deletions
+119
-15
ModuleProject/app/src/main/java/com/hikcreate/ui/testActivity.java
+15
-11
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;
import
com.hikcreate.library.util.LogCat
;
import
com.hikcreate.module_router.router.RouterResponse
;
import
com.hikcreate.module_router.tools.ModuleRouterUtil
;
import
com.hikcreate.module_router.tools.RouterCallBack
;
import
com.message.bean.GeneralMessageBean
;
import
com.message.driver.MessageWrap
;
import
com.google.gson.Gson
;
...
...
@@ -36,7 +37,7 @@ public class testActivity extends AppCompatActivity {
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
app_test
);
findViewById
(
R
.
id
.
mBtnLogin
).
setOnClickListener
(
v
->
{
RouterResponse
response
=
ModuleRouterUtil
.
getRouterResponse
(
getApplicationContext
(),
RouterResponse
response
=
ModuleRouterUtil
.
router
(
getApplicationContext
(),
AppProvider
.
LOGIN_PROVIDER
,
AppProvider
.
GET_USER_INFO_ACTION
);
if
(
response
!=
null
)
{
if
(
response
.
getObject
()
!=
null
)
{
...
...
@@ -50,16 +51,19 @@ public class testActivity extends AppCompatActivity {
findViewById
(
R
.
id
.
mBtnLoginSync
).
setOnClickListener
(
v
->
{
new
Thread
(()
->
{
HashMap
<
String
,
String
>
value
=
new
HashMap
<>();
value
.
put
(
"name"
,
"wangtao"
);
value
.
put
(
"mobile"
,
"150000000000"
);
RouterResponse
response
=
ModuleRouterUtil
.
getRouterResponse
(
getApplicationContext
(),
AppProvider
.
USER_INFO_CHANGE_PROVIDER
,
AppProvider
.
USER_INFO_CHANGE_ACTION
,
value
);
final
String
result
=
response
.
get
();
runOnUiThread
(()
->
Toast
.
makeText
(
testActivity
.
this
,
result
,
Toast
.
LENGTH_SHORT
).
show
());
}).
start
();
HashMap
<
String
,
String
>
value
=
new
HashMap
<>();
value
.
put
(
"name"
,
"wangtao"
);
value
.
put
(
"mobile"
,
"150000000000"
);
ModuleRouterUtil
.
routeSyncToUi
(
getApplicationContext
(),
AppProvider
.
USER_INFO_CHANGE_PROVIDER
,
AppProvider
.
USER_INFO_CHANGE_ACTION
,
value
,
new
RouterCallBack
()
{
@Override
public
void
callSuccess
(
RouterResponse
response
)
{
Toast
.
makeText
(
testActivity
.
this
,
response
.
get
(),
Toast
.
LENGTH_SHORT
).
show
();
}
@Override
public
void
callFail
(
RouterResponse
response
)
{
}
});
});
...
...
This diff is collapsed.
Click to expand it.
ModuleProject/lib_module_common/build.gradle
View file @
0820eb0b
...
...
@@ -34,4 +34,5 @@ android {
dependencies
{
implementation
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
implementation
deps
.
multidex
implementation
deps
.
rxandroid2
}
This diff is collapsed.
Click to expand it.
ModuleProject/lib_module_common/src/main/java/com/hikcreate/module_router/tools/ModuleRouterUtil.java
View file @
0820eb0b
package
com
.
hikcreate
.
module_router
.
tools
;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
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.RouterResponse
;
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
* date :2019/9/25
...
...
@@ -15,13 +25,87 @@ import java.util.HashMap;
**/
public
class
ModuleRouterUtil
{
public
static
RouterResponse
getRouterResponse
(
Context
context
,
String
provider
,
String
action
)
{
return
LocalRouter
.
getInstance
(
context
).
route
(
RouterRequest
.
obtain
(
context
).
provider
(
provider
).
action
(
action
));
public
static
RouterResponse
router
(
Context
context
,
String
provider
,
String
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
)
{
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
());
}
}
This diff is collapsed.
Click to expand it.
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
);
}
This diff is collapsed.
Click to expand it.
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