Skip to content

Commit 18771a3

Browse files
committed
重构Kit
1 parent 40f03c2 commit 18771a3

5 files changed

Lines changed: 105 additions & 14 deletions

File tree

PowerSupportKit/src/main/java/tech/jiangtao/support/kit/SupportIM.java

Lines changed: 99 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
package tech.jiangtao.support.kit;
22

33
import android.content.Context;
4+
import android.content.Intent;
45
import io.realm.Realm;
56
import io.realm.RealmConfiguration;
7+
import java.lang.annotation.Annotation;
8+
import java.util.Properties;
9+
import java.util.UUID;
10+
import tech.jiangtao.support.kit.annotation.ChatRouter;
11+
import tech.jiangtao.support.kit.annotation.GroupChatRouter;
12+
import tech.jiangtao.support.kit.annotation.InvitedRouter;
13+
import tech.jiangtao.support.kit.service.SupportService;
14+
import tech.jiangtao.support.kit.service.XMPPService;
15+
import tech.jiangtao.support.kit.util.PropertyUtils;
616
import xiaofei.library.hermeseventbus.HermesEventBus;
717

818
/**
@@ -40,29 +50,110 @@ public class SupportIM {
4050
public static final String MUC_GROUP = "muc-group";
4151
public static final String GROUP = "group";
4252

43-
private static void initialize(Context context){
53+
private static String MM_APPID = "MM_APPID";
54+
private static String MM_AppSecret = "MM_APPSECRET";
55+
private static String PORT = "PORT";
56+
private static String SERVICE_NAME = "SERVICE_NAME";
57+
58+
// server
59+
private static String HOST = "HOST";
60+
public static String RESOURCE_ADDRESS_CONFIG = "RESOURCE_ADDRESS";
61+
private static String API_ADDRESS_CONFIG = "API_ADDRESS";
62+
63+
// company
64+
private static String HOST1 = "HOST1";
65+
public static String RESOURCE_ADDRESS1 = "RESOURCE_ADDRESS1";
66+
private static String API_ADDRESS1 = "API_ADDRESS1";
67+
68+
// home
69+
private static String HOST2 = "HOST2";
70+
public static String RESOURCE_ADDRESS2 = "RESOURCE_ADDRESS2";
71+
private static String API_ADDRESS2 = "API_ADDRESS2";
72+
73+
private static void initialize(Context context) {
74+
HermesEventBus.getDefault().init(context);
75+
}
76+
77+
public static void initialize(Context context, String resourceName) {
78+
initValue(context, resourceName);
79+
String resource = UUID.randomUUID().toString();
80+
//---------------------------------------配置中心--------------------------------
81+
//------------------------------------------------------------------------------
82+
initialize(context, SERVICE_NAME, resource, HOST, Integer.parseInt(PORT), RESOURCE_ADDRESS,
83+
API_ADDRESS);
84+
Realm.init(context);
4485
HermesEventBus.getDefault().init(context);
4586
}
4687

47-
private static void initialize(Context context, String serviceName){
88+
private static void initValue(Context context, String resourceName) {
89+
Properties properties = PropertyUtils.getProperties(context, resourceName);
90+
MM_APPID = properties.getProperty(MM_APPID);
91+
MM_AppSecret = properties.getProperty(MM_AppSecret);
92+
PORT = properties.getProperty(PORT);
93+
SERVICE_NAME = properties.getProperty(SERVICE_NAME);
94+
95+
// 线上
96+
HOST = properties.getProperty(HOST);
97+
RESOURCE_ADDRESS = properties.getProperty(RESOURCE_ADDRESS_CONFIG);
98+
API_ADDRESS = properties.getProperty(API_ADDRESS_CONFIG);
99+
100+
// 公司
101+
HOST1 = properties.getProperty(HOST1);
102+
RESOURCE_ADDRESS1 = properties.getProperty(RESOURCE_ADDRESS1);
103+
API_ADDRESS1 = properties.getProperty(API_ADDRESS1);
104+
105+
// 家里
106+
HOST2 = properties.getProperty(HOST2);
107+
RESOURCE_ADDRESS2 = properties.getProperty(RESOURCE_ADDRESS2);
108+
API_ADDRESS2 = properties.getProperty(API_ADDRESS2);
109+
}
110+
111+
private static void initializeContext(Context context, String serviceName) {
48112
initialize(context);
49113
mDomain = serviceName;
50114
}
51115

52-
private static void initialize(Context context, String serviceName, String resource){
53-
initialize(context,serviceName);
116+
private static void initialize(Context context, String serviceName, String resource) {
117+
initializeContext(context, serviceName);
54118
mResource = resource;
55119
}
56120

57-
private static void initialize(Context context, String serviceName, String resource, String host){
58-
initialize(context,serviceName,resource);
121+
private static void initialize(Context context, String serviceName, String resource,
122+
String host) {
123+
initialize(context, serviceName, resource);
59124
mHost = host;
60125
}
61126

62-
public static void initialize(Context context,String serviceName,String resource,String host,int port,String resourceAddress,String apiAddress){
63-
initialize(context,serviceName,resource,host);
127+
public static void initialize(Context context, String serviceName, String resource, String host,
128+
int port, String resourceAddress, String apiAddress) {
129+
initialize(context, serviceName, resource, host);
64130
RESOURCE_ADDRESS = resourceAddress;
65131
API_ADDRESS = apiAddress;
66132
mPort = port;
133+
134+
Class clazz = context.getApplicationContext().getClass();
135+
Annotation[] annotations = clazz.getAnnotations();
136+
Class chatClazz = null;
137+
Class groupChatClazz = null;
138+
Class invitedClass = null;
139+
for (int i = 0; i < annotations.length; i++) {
140+
Annotation annotation = annotations[i];
141+
if (annotation instanceof ChatRouter) {
142+
chatClazz = ((ChatRouter) annotation).router();
143+
}
144+
if (annotation instanceof GroupChatRouter) {
145+
groupChatClazz = ((GroupChatRouter) annotation).router();
146+
}
147+
if (annotation instanceof InvitedRouter) {
148+
invitedClass = ((InvitedRouter) annotation).router();
149+
}
150+
}
151+
Intent intent = new Intent(context, XMPPService.class);
152+
intent.putExtra(XMPPService.CHAT_CLASS, chatClazz);
153+
intent.putExtra(XMPPService.GROUP_CHAT_CLASS, groupChatClazz);
154+
intent.putExtra(XMPPService.INVITED_CLASS, invitedClass);
155+
context.startService(intent);
156+
Intent intent1 = new Intent(context, SupportService.class);
157+
context.startService(intent1);
67158
}
68159
}

PowerSupportUI/src/main/java/tech/jiangtao/support/ui/utils/PropertyUtils.java renamed to PowerSupportKit/src/main/java/tech/jiangtao/support/kit/util/PropertyUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tech.jiangtao.support.ui.utils;
1+
package tech.jiangtao.support.kit.util;
22

33
import android.content.Context;
44
import java.io.InputStream;

PowerSupportUI/javadoc/tech/jiangtao/support/ui/utils/PropertyUtils.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ <h2 title="Class PropertyUtils" class="title">Class PropertyUtils</h2>
101101
<li><a href="https://developer.android.com/reference/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</a></li>
102102
<li>
103103
<ul class="inheritance">
104-
<li>tech.jiangtao.support.ui.utils.PropertyUtils</li>
104+
<li>tech.jiangtao.support.kit.util.PropertyUtils</li>
105105
</ul>
106106
</li>
107107
</ul>

PowerSupportUI/javadoc/tech/jiangtao/support/ui/utils/class-use/PropertyUtils.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<head>
55
<!-- Generated by javadoc (1.8.0_112-release) on Fri Apr 28 03:21:16 CST 2017 -->
66
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7-
<title>Uses of Class tech.jiangtao.support.ui.utils.PropertyUtils</title>
7+
<title>Uses of Class tech.jiangtao.support.kit.util.PropertyUtils</title>
88
<meta name="date" content="2017-04-28">
99
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
1010
<script type="text/javascript" src="../../../../../../script.js"></script>
@@ -71,9 +71,9 @@
7171
</a></div>
7272
<!-- ========= END OF TOP NAVBAR ========= -->
7373
<div class="header">
74-
<h2 title="Uses of Class tech.jiangtao.support.ui.utils.PropertyUtils" class="title">Uses of Class<br>tech.jiangtao.support.ui.utils.PropertyUtils</h2>
74+
<h2 title="Uses of Class tech.jiangtao.support.kit.util.PropertyUtils" class="title">Uses of Class<br>tech.jiangtao.support.ui.utils.PropertyUtils</h2>
7575
</div>
76-
<div class="classUseContainer">No usage of tech.jiangtao.support.ui.utils.PropertyUtils</div>
76+
<div class="classUseContainer">No usage of tech.jiangtao.support.kit.util.PropertyUtils</div>
7777
<!-- ======= START OF BOTTOM NAVBAR ====== -->
7878
<div class="bottomNav"><a name="navbar.bottom">
7979
<!-- -->

PowerSupportUI/src/main/java/tech/jiangtao/support/ui/SupportUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import tech.jiangtao.support.kit.annotation.InvitedRouter;
1414
import tech.jiangtao.support.kit.service.SupportService;
1515
import tech.jiangtao.support.kit.service.XMPPService;
16-
import tech.jiangtao.support.ui.utils.PropertyUtils;
16+
import tech.jiangtao.support.kit.util.PropertyUtils;
1717

1818
public class SupportUI {
1919

0 commit comments

Comments
 (0)