22 | * Created by JessYan on 30/03/2018 17:32
23 | * Contact me
24 | * Follow me
25 | * ================================================
26 | */
27 | public interface Constants {
28 | //电话号码正则
29 | String PHONE_REGULAR = "^1[3-9]\\d{9}$";
30 | }
31 |
--------------------------------------------------------------------------------
/component/CommonSDK/src/main/java/me/jessyan/armscomponent/commonsdk/core/EventBusHub.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonsdk.core;
17 |
18 | /**
19 | * ================================================
20 | * AndroidEventBus 作为本方案提供的另一种跨组件通信方式 (第一种是接口下沉, 在 app 的 MainActivity 中已展示, 通过 ARouter 实现)
21 | * AndroidEventBus 比 greenrobot 的 EventBus 多了一个 Tag, 在组件化中更容定位和管理事件
22 | *
23 | * EventBusHub 用来定义 AndroidEventBus 的 Tag 字符串, 以组件名作为 Tag 前缀, 对每个组件的事件进行分组
24 | * Tag 的命名规则为 组件名 + 页面名 + 动作
25 | * 比如需要使用 AndroidEventBus 通知订单组件的订单详情页进行刷新, 可以将这个刷新方法的 Tag 命名为 "order/OrderDetailActivity/refresh"
26 | *
27 | * Tips: 基础库中的 EventBusHub 仅用来存放需要跨组件通信的事件的 Tag, 如果某个事件只想在组件内使用 AndroidEventBus 进行通信
28 | * 那就让组件自行管理这个事件的 Tag
29 | *
30 | * @see EventBusHub wiki 官方文档
31 | * Created by JessYan on 30/03/2018 17:46
32 | * Contact me
33 | * Follow me
34 | * ================================================
35 | */
36 | public interface EventBusHub {
37 | /**
38 | * 组名
39 | */
40 | String APP = "app";//宿主 App 组件
41 | String ZHIHU = "zhihu";//知乎组件
42 | String GANK = "gank";//干货集中营组件
43 | String GOLD = "gold";//稀土掘金组件
44 | }
45 |
--------------------------------------------------------------------------------
/component/CommonSDK/src/main/java/me/jessyan/armscomponent/commonsdk/core/GlobalHttpHandlerImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonsdk.core;
17 |
18 | import android.content.Context;
19 |
20 | import com.jess.arms.http.GlobalHttpHandler;
21 |
22 | import okhttp3.Interceptor;
23 | import okhttp3.Request;
24 | import okhttp3.Response;
25 |
26 | /**
27 | * ================================================
28 | * 展示 {@link GlobalHttpHandler} 的用法
29 | *
30 | * Created by JessYan on 04/09/2017 17:06
31 | * Contact me
32 | * Follow me
33 | * ================================================
34 | */
35 | public class GlobalHttpHandlerImpl implements GlobalHttpHandler {
36 | private Context context;
37 |
38 | public GlobalHttpHandlerImpl(Context context) {
39 | this.context = context;
40 | }
41 |
42 | /**
43 | * 这里可以先客户端一步拿到每一次 Http 请求的结果, 可以先解析成 Json, 再做一些操作, 如检测到 token 过期后
44 | * 重新请求 token, 并重新执行请求
45 | *
46 | * @param httpResult 服务器返回的结果 (已被框架自动转换为字符串)
47 | * @param chain {@link okhttp3.Interceptor.Chain}
48 | * @param response {@link Response}
49 | * @return
50 | */
51 | @Override
52 | public Response onHttpResultResponse(String httpResult, Interceptor.Chain chain, Response response) {
53 | /* 这里如果发现 token 过期, 可以先请求最新的 token, 然后在拿新的 token 放入 Request 里去重新请求
54 | 注意在这个回调之前已经调用过 proceed(), 所以这里必须自己去建立网络请求, 如使用 Okhttp 使用新的 Request 去请求
55 | create a new request and modify it accordingly using the new token
56 | Request newRequest = chain.request().newBuilder().header("token", newToken)
57 | .build();
58 |
59 | retry the request
60 |
61 | response.body().close();
62 | 如果使用 Okhttp 将新的请求, 请求成功后, 再将 Okhttp 返回的 Response return 出去即可
63 | 如果不需要返回新的结果, 则直接把参数 response 返回出去即可 */
64 | return response;
65 | }
66 |
67 | /**
68 | * 这里可以在请求服务器之前拿到 {@link Request}, 做一些操作比如给 {@link Request} 统一添加 token 或者 header 以及参数加密等操作
69 | *
70 | * @param chain {@link okhttp3.Interceptor.Chain}
71 | * @param request {@link Request}
72 | * @return
73 | */
74 | @Override
75 | public Request onHttpRequestBefore(Interceptor.Chain chain, Request request) {
76 | /* 如果需要再请求服务器之前做一些操作, 则重新返回一个做过操作的的 Request 如增加 Header, 不做操作则直接返回参数 request
77 | return chain.request().newBuilder().header("token", tokenId)
78 | .build(); */
79 | return request;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/component/CommonSDK/src/main/java/me/jessyan/armscomponent/commonsdk/core/ResponseErrorListenerImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonsdk.core;
17 |
18 | import android.content.Context;
19 | import android.net.ParseException;
20 |
21 | import com.google.gson.JsonIOException;
22 | import com.google.gson.JsonParseException;
23 | import com.jess.arms.utils.ArmsUtils;
24 |
25 | import org.json.JSONException;
26 |
27 | import java.net.SocketTimeoutException;
28 | import java.net.UnknownHostException;
29 |
30 | import me.jessyan.rxerrorhandler.handler.listener.ResponseErrorListener;
31 | import retrofit2.HttpException;
32 | import timber.log.Timber;
33 |
34 | /**
35 | * ================================================
36 | * 展示 {@link ResponseErrorListener} 的用法
37 | *
38 | * Created by JessYan on 04/09/2017 17:18
39 | * Contact me
40 | * Follow me
41 | * ================================================
42 | */
43 | public class ResponseErrorListenerImpl implements ResponseErrorListener {
44 |
45 | @Override
46 | public void handleResponseError(Context context, Throwable t) {
47 | Timber.tag("Catch-Error").w(t.getMessage());
48 | //这里不光只能打印错误, 还可以根据不同的错误做出不同的逻辑处理
49 | //这里只是对几个常用错误进行简单的处理, 展示这个类的用法, 在实际开发中请您自行对更多错误进行更严谨的处理
50 | String msg = "未知错误";
51 | if (t instanceof UnknownHostException) {
52 | msg = "网络不可用";
53 | } else if (t instanceof SocketTimeoutException) {
54 | msg = "请求网络超时";
55 | } else if (t instanceof HttpException) {
56 | HttpException httpException = (HttpException) t;
57 | msg = convertStatusCode(httpException);
58 | } else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
59 | msg = "数据解析错误";
60 | }
61 | ArmsUtils.snackbarText(msg);
62 | }
63 |
64 | private String convertStatusCode(HttpException httpException) {
65 | String msg;
66 | if (httpException.code() == 500) {
67 | msg = "服务器发生错误";
68 | } else if (httpException.code() == 404) {
69 | msg = "请求地址不存在";
70 | } else if (httpException.code() == 403) {
71 | msg = "请求被服务器拒绝";
72 | } else if (httpException.code() == 401) {
73 | msg = "未授权";
74 | } else if (httpException.code() == 307) {
75 | msg = "请求被重定向到其他页面";
76 | } else {
77 | msg = httpException.message();
78 | }
79 | return msg;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/component/CommonSDK/src/main/java/me/jessyan/armscomponent/commonsdk/core/RouterHub.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonsdk.core;
17 |
18 | /**
19 | * ================================================
20 | * RouterHub 用来定义路由器的路由地址, 以组件名作为前缀, 对每个组件的路由地址进行分组, 可以统一查看和管理所有分组的路由地址
21 | *
31 | * ARouter 将路由地址中第一个 '/' 后面的字符称为 Group, 比如上面的示例路由地址中 order 就是 Group, 以 order 开头的地址都被分配该 Group 下
32 | * 切记不同的组件中不能出现名称一样的 Group, 否则会发生该 Group 下的部分路由地址找不到的情况!!!
33 | * 所以每个组件使用自己的组件名作为 Group 是比较好的选择, 毕竟组件不会重名
34 | *
35 | * @see RouterHub wiki 官方文档
36 | * Created by JessYan on 30/03/2018 18:07
37 | * Contact me
38 | * Follow me
39 | * ================================================
40 | */
41 | public interface RouterHub {
42 | /**
43 | * 组名
44 | */
45 | String APP = "/app";//宿主 App 组件
46 | String ZHIHU = "/zhihu";//知乎组件
47 | String GANK = "/gank";//干货集中营组件
48 | String GOLD = "/gold";//稀土掘金组件
49 |
50 | /**
51 | * 服务组件, 用于给每个组件暴露特有的服务
52 | */
53 | String SERVICE = "/service";
54 |
55 |
56 | /**
57 | * 宿主 App 分组
58 | */
59 | String APP_SPLASHACTIVITY = APP + "/SplashActivity";
60 | String APP_MAINACTIVITY = APP + "/MainActivity";
61 |
62 |
63 | /**
64 | * 知乎分组
65 | */
66 | String ZHIHU_SERVICE_ZHIHUINFOSERVICE = ZHIHU + SERVICE + "/ZhihuInfoService";
67 |
68 | String ZHIHU_HOMEACTIVITY = ZHIHU + "/HomeActivity";
69 | String ZHIHU_DETAILACTIVITY = ZHIHU + "/DetailActivity";
70 |
71 | /**
72 | * 干货集中营分组
73 | */
74 | String GANK_SERVICE_GANKINFOSERVICE = GANK + SERVICE + "/GankInfoService";
75 |
76 | String GANK_HOMEACTIVITY = GANK + "/HomeActivity";
77 |
78 | /**
79 | * 稀土掘金分组
80 | */
81 | String GOLD_SERVICE_GOLDINFOSERVICE = GOLD + SERVICE + "/GoldInfoService";
82 |
83 | String GOLD_HOMEACTIVITY = GOLD + "/HomeActivity";
84 | String GOLD_DETAILACTIVITY = GOLD + "/DetailActivity";
85 | }
86 |
--------------------------------------------------------------------------------
/component/CommonSDK/src/main/java/me/jessyan/armscomponent/commonsdk/http/Api.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonsdk.http;
17 |
18 | /**
19 | * ================================================
20 | * CommonSDK 的 Api 可以定义公用的关于 API 的相关常量, 比如说请求地址, 错误码等, 每个组件的 Api 可以定义组件自己的私有常量
21 | *
22 | * Created by JessYan on 30/03/2018 17:16
23 | * Contact me
24 | * Follow me
25 | * ================================================
26 | */
27 | public interface Api {
28 | String APP_DOMAIN = "https://api.github.com";
29 |
30 | String REQUEST_SUCCESS = "200";
31 |
32 | // 错误码
33 | String ERROR_USER_INCORRECT = "1001";
34 | String ERROR_PHONE_EXIST = "1019";
35 | String VALIDATION_OVERTIME = "1020";
36 | String NOT_PERMISSIONS = "403";
37 | String API_EXCPTION = "500";
38 | String REQUEST_PARAM_INCORRECT = "1000";
39 | String VADATION_INCORRECT = "1002";
40 | String FIRST_STOP_AFTER_DELETE = "1003";
41 | String UPLOADING_FILE_OVERSIZE = "1004";
42 | String EDIT_COMMO_LEVEL = "1005";
43 | String COMMO_CLASS_RE = "1006";
44 | String COMMO_TRADEMARK_RE = "1007";
45 | String LOGISTICS_TEMPLATE_RE = "1008";
46 | String COMMO_ATTRIBUTE_RE = "1009";
47 | String USER_NOT_REGISTER = "1010";
48 | String USER_ALREADY_ADD = "1011";
49 | String COMMO_CLASS_DELETE = "1012";
50 | String COMMO_TRANDMARK_DELETE = "1013";
51 | String COMMO_STORE_OFF = "1014";
52 | String USER_FORBIDDEN = "1015";
53 | String ONLY_FIVE_OPERATION = "1024";
54 | String NAME_ONE_MODIFICATION = "1017";
55 | String NAME_EXIST = "1018";
56 | String FIVE_ERR_PWDD = "1016";
57 | String PWD_NOT_LIKE = "1053";
58 | String BINDPHONELIKE = "1025";
59 | String MODIFICOUNTTHREE = "1026";
60 | String MODIFIPHONEOVERTHREE = "1027";
61 | String NOTLOGININ = "1052";
62 | String PASSOWRDINCOREECT = "1055";
63 | String NOTMATCHIMGBANKCARD = "1041";
64 | String IDCARDEXIT = "1038";
65 | String STORENAMEEXIT = "1028";
66 | String COMPANYNAMEEXIT = "1030";
67 | String CODEEXIT = "1029";
68 | String BANKREPETION = "1074";
69 | String REPETITION = "1032";
70 | String SERIVENULL ="1044";
71 | String LIMITMESSAGE = "1082";
72 | String NO_DEAL = "1081";
73 | }
74 |
--------------------------------------------------------------------------------
/component/CommonSDK/src/main/java/me/jessyan/armscomponent/commonsdk/http/SSLSocketClient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonsdk.http;
17 |
18 | import java.security.SecureRandom;
19 | import java.security.cert.CertificateException;
20 | import java.security.cert.X509Certificate;
21 |
22 | import javax.net.ssl.HostnameVerifier;
23 | import javax.net.ssl.SSLContext;
24 | import javax.net.ssl.SSLSession;
25 | import javax.net.ssl.TrustManager;
26 | import javax.net.ssl.X509TrustManager;
27 |
28 | /**
29 | * ================================================
30 | * Created by JessYan on 30/03/2018 17:16
31 | * Contact me
32 | * Follow me
33 | * ================================================
34 | */
35 | public class SSLSocketClient {
36 |
37 | //获取这个SSLSocketFactory
38 | public static javax.net.ssl.SSLSocketFactory getSSLSocketFactory() {
39 | try {
40 | SSLContext sslContext = SSLContext.getInstance("SSL");
41 | sslContext.init(null, getTrustManagers(), new SecureRandom());
42 | return sslContext.getSocketFactory();
43 | } catch (Exception e) {
44 | throw new RuntimeException(e);
45 | }
46 | }
47 |
48 | //获取TrustManager
49 | private static TrustManager[] getTrustManagers() {
50 | TrustManager[] trustAllCerts = new TrustManager[]{getTrustManager()};
51 | return trustAllCerts;
52 | }
53 |
54 | //获取HostnameVerifier
55 | public static HostnameVerifier getHostnameVerifier() {
56 | HostnameVerifier hostnameVerifier = new HostnameVerifier() {
57 | @Override
58 | public boolean verify(String s, SSLSession sslSession) {
59 | return true;
60 | }
61 | };
62 | return hostnameVerifier;
63 | }
64 |
65 | public static X509TrustManager getTrustManager(){
66 | return new MyTrustManager();
67 | }
68 |
69 | private static final class MyTrustManager implements X509TrustManager {
70 |
71 | @Override
72 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
73 |
74 | }
75 |
76 | @Override
77 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
78 |
79 | }
80 |
81 | @Override
82 | public X509Certificate[] getAcceptedIssuers() {
83 | return new X509Certificate[0];
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/component/CommonSDK/src/main/java/me/jessyan/armscomponent/commonsdk/utils/Utils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonsdk.utils;
17 |
18 | import android.app.Activity;
19 | import android.content.Context;
20 |
21 | import com.alibaba.android.arouter.launcher.ARouter;
22 |
23 | /**
24 | * ================================================
25 | * Created by JessYan on 30/03/2018 17:16
26 | * Contact me
27 | * Follow me
28 | * ================================================
29 | */
30 | public class Utils {
31 | private Utils() {
32 | throw new IllegalStateException("you can't instantiate me!");
33 | }
34 |
35 | /**
36 | * 使用 {@link ARouter} 根据 {@code path} 跳转到对应的页面, 这个方法因为没有使用 {@link Activity}跳转
37 | * 所以 {@link ARouter} 会自动给 {@link android.content.Intent} 加上 Intent.FLAG_ACTIVITY_NEW_TASK
38 | * 如果不想自动加上这个 Flag 请使用 {@link ARouter#getInstance()#navigation(Context, String)} 并传入 {@link Activity}
39 | *
40 | * @param path {@code path}
41 | */
42 | public static void navigation(String path) {
43 | ARouter.getInstance().build(path).navigation();
44 | }
45 |
46 | /**
47 | * 使用 {@link ARouter} 根据 {@code path} 跳转到对应的页面, 如果参数 {@code context} 传入的不是 {@link Activity}
48 | * {@link ARouter} 就会自动给 {@link android.content.Intent} 加上 Intent.FLAG_ACTIVITY_NEW_TASK
49 | * 如果不想自动加上这个 Flag 请使用 {@link Activity} 作为 {@code context} 传入
50 | *
51 | * @param context
52 | * @param path
53 | */
54 | public static void navigation(Context context, String path) {
55 | ARouter.getInstance().build(path).navigation(context);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/component/CommonService/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/component/CommonService/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.android["compileSdkVersion"]
5 | buildToolsVersion rootProject.ext.android["buildToolsVersion"]
6 |
7 | defaultConfig {
8 | minSdkVersion rootProject.ext.android["minSdkVersion"]
9 | targetSdkVersion rootProject.ext.android["targetSdkVersion"]
10 | versionCode rootProject.ext.android["versionCode"]
11 | versionName rootProject.ext.android["versionName"]
12 |
13 | testInstrumentationRunner rootProject.ext.dependencies["androidJUnitRunner"]
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 |
23 | }
24 |
25 | dependencies {
26 | compileOnly rootProject.ext.dependencies["arouter"]
27 | compileOnly rootProject.ext.dependencies["appcompat-v7"]
28 | }
29 |
--------------------------------------------------------------------------------
/component/CommonService/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/component/CommonService/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/component/CommonService/src/main/java/me/jessyan/armscomponent/commonservice/gank/bean/GankInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonservice.gank.bean;
17 |
18 | /**
19 | * ================================================
20 | * Created by JessYan on 2018/4/27 14:11
21 | * Contact me
22 | * Follow me
23 | * ================================================
24 | */
25 | public class GankInfo {
26 | private String name;
27 |
28 | public GankInfo(String name) {
29 | this.name = name;
30 | }
31 |
32 | public String getName() {
33 | return name;
34 | }
35 |
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/component/CommonService/src/main/java/me/jessyan/armscomponent/commonservice/gank/service/GankInfoService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonservice.gank.service;
17 |
18 | import com.alibaba.android.arouter.facade.template.IProvider;
19 |
20 | import me.jessyan.armscomponent.commonservice.gank.bean.GankInfo;
21 |
22 | /**
23 | * ================================================
24 | * 向外提供服务的接口, 在此接口中声明一些具有特定功能的方法提供给外部, 即可让一个组件与其他组件或宿主进行交互
25 | *
26 | * @see CommonService wiki 官方文档
27 | * Created by JessYan on 2018/4/27 14:16
28 | * Contact me
29 | * Follow me
30 | * ================================================
31 | */
32 | public interface GankInfoService extends IProvider {
33 | GankInfo getInfo();
34 | }
35 |
--------------------------------------------------------------------------------
/component/CommonService/src/main/java/me/jessyan/armscomponent/commonservice/gold/bean/GoldInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonservice.gold.bean;
17 |
18 | /**
19 | * ================================================
20 | * Created by JessYan on 2018/4/27 14:11
21 | * Contact me
22 | * Follow me
23 | * ================================================
24 | */
25 | public class GoldInfo {
26 | private String name;
27 |
28 | public GoldInfo(String name) {
29 | this.name = name;
30 | }
31 |
32 | public String getName() {
33 | return name;
34 | }
35 |
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/component/CommonService/src/main/java/me/jessyan/armscomponent/commonservice/gold/service/GoldInfoService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonservice.gold.service;
17 |
18 | import com.alibaba.android.arouter.facade.template.IProvider;
19 |
20 | import me.jessyan.armscomponent.commonservice.gold.bean.GoldInfo;
21 |
22 | /**
23 | * ================================================
24 | * 向外提供服务的接口, 在此接口中声明一些具有特定功能的方法提供给外部, 即可让一个组件与其他组件或宿主进行交互
25 | *
26 | * @see CommonService wiki 官方文档
27 | * Created by JessYan on 2018/4/27 14:16
28 | * Contact me
29 | * Follow me
30 | * ================================================
31 | */
32 | public interface GoldInfoService extends IProvider {
33 | GoldInfo getInfo();
34 | }
35 |
--------------------------------------------------------------------------------
/component/CommonService/src/main/java/me/jessyan/armscomponent/commonservice/zhihu/bean/ZhihuInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonservice.zhihu.bean;
17 |
18 | /**
19 | * ================================================
20 | * Created by JessYan on 2018/4/27 14:11
21 | * Contact me
22 | * Follow me
23 | * ================================================
24 | */
25 | public class ZhihuInfo {
26 | private String name;
27 |
28 | public ZhihuInfo(String name) {
29 | this.name = name;
30 | }
31 |
32 | public String getName() {
33 | return name;
34 | }
35 |
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/component/CommonService/src/main/java/me/jessyan/armscomponent/commonservice/zhihu/service/ZhihuInfoService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.commonservice.zhihu.service;
17 |
18 | import com.alibaba.android.arouter.facade.template.IProvider;
19 |
20 | import me.jessyan.armscomponent.commonservice.zhihu.bean.ZhihuInfo;
21 |
22 | /**
23 | * ================================================
24 | * 向外提供服务的接口, 在此接口中声明一些具有特定功能的方法提供给外部, 即可让一个组件与其他组件或宿主进行交互
25 | *
26 | * @see CommonService wiki 官方文档
27 | * Created by JessYan on 2018/4/27 14:16
28 | * Contact me
29 | * Follow me
30 | * ================================================
31 | */
32 | public interface ZhihuInfoService extends IProvider {
33 | ZhihuInfo getInfo();
34 | }
35 |
--------------------------------------------------------------------------------
/fake/fake-app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/fake/fake-app/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
22 |
23 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
41 |
42 |
45 |
48 |
49 |
50 |
51 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/fake/fake-app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.android["compileSdkVersion"]
5 | buildToolsVersion rootProject.ext.android["buildToolsVersion"]
6 | defaultConfig {
7 | minSdkVersion rootProject.ext.android["minSdkVersion"]
8 | targetSdkVersion rootProject.ext.android["targetSdkVersion"]
9 | versionCode rootProject.ext.android["versionCode"]
10 | versionName rootProject.ext.android["versionName"]
11 | testInstrumentationRunner rootProject.ext.dependencies["androidJUnitRunner"]
12 | javaCompileOptions {
13 | annotationProcessorOptions {
14 | arguments = [AROUTER_MODULE_NAME: project.getName()]
15 | }
16 | }
17 | }
18 | buildTypes {
19 | debug {
20 | buildConfigField "boolean", "LOG_DEBUG", "true"
21 | buildConfigField "boolean", "USE_CANARY", "true"
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 |
26 | release {
27 | buildConfigField "boolean", "LOG_DEBUG", "false"
28 | buildConfigField "boolean", "USE_CANARY", "false"
29 | minifyEnabled true
30 | shrinkResources true
31 | zipAlignEnabled true
32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33 | }
34 | }
35 | useLibrary 'org.apache.http.legacy'
36 | compileOptions {
37 | targetCompatibility JavaVersion.VERSION_1_8
38 | sourceCompatibility JavaVersion.VERSION_1_8
39 | }
40 | dexOptions {
41 | //预编译
42 | preDexLibraries true
43 | //支持大工程
44 | jumboMode = true
45 | //线程数
46 | threadCount = 16
47 | //dex内存,公式:dex内存 + 1G < Gradle内存
48 | javaMaxHeapSize "4g"
49 | additionalParameters = [
50 | '--multi-dex',//多分包
51 | '--set-max-idx-number=60000'//每个包内方法数上限
52 | ]
53 | }
54 | lintOptions {
55 | checkReleaseBuilds false
56 | disable 'InvalidPackage'
57 | disable "ResourceType"
58 | // Or, if you prefer, you can continue to check for errors in release builds,
59 | // but continue the build even when errors are found:
60 | abortOnError false
61 | }
62 | sourceSets {
63 | main {
64 | manifest.srcFile './AndroidManifest.xml'
65 | }
66 | }
67 | }
68 |
69 | dependencies {
70 | //TODO 4. 修改要调试的组件
71 | runtimeOnly project(':module:module_app')
72 | runtimeOnly project(':module:module_zhihu')
73 |
74 | implementation project(":component:CommonRes")//因为 CommonRes 依赖了 CommonSDK, 所以如果业务模块需要公共 UI 组件就依赖 CommonRes, 如果不需要就只依赖 CommonSDK
75 | implementation project(":component:CommonService")
76 |
77 | //test
78 | testImplementation rootProject.ext.dependencies["junit"]
79 | debugImplementation rootProject.ext.dependencies["canary-debug"]
80 | releaseImplementation rootProject.ext.dependencies["canary-release"]
81 | testImplementation rootProject.ext.dependencies["canary-release"]
82 | }
83 |
--------------------------------------------------------------------------------
/fake/fake-template/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/fake/fake-template/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
22 |
23 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
41 |
42 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/fake/fake-template/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.android["compileSdkVersion"]
5 | buildToolsVersion rootProject.ext.android["buildToolsVersion"]
6 | defaultConfig {
7 | minSdkVersion rootProject.ext.android["minSdkVersion"]
8 | targetSdkVersion rootProject.ext.android["targetSdkVersion"]
9 | versionCode rootProject.ext.android["versionCode"]
10 | versionName rootProject.ext.android["versionName"]
11 | testInstrumentationRunner rootProject.ext.dependencies["androidJUnitRunner"]
12 | javaCompileOptions {
13 | annotationProcessorOptions {
14 | arguments = [AROUTER_MODULE_NAME: project.getName()]
15 | }
16 | }
17 | }
18 | buildTypes {
19 | debug {
20 | buildConfigField "boolean", "LOG_DEBUG", "true"
21 | buildConfigField "boolean", "USE_CANARY", "true"
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 |
26 | release {
27 | buildConfigField "boolean", "LOG_DEBUG", "false"
28 | buildConfigField "boolean", "USE_CANARY", "false"
29 | minifyEnabled true
30 | shrinkResources true
31 | zipAlignEnabled true
32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33 | }
34 | }
35 | useLibrary 'org.apache.http.legacy'
36 | compileOptions {
37 | targetCompatibility JavaVersion.VERSION_1_8
38 | sourceCompatibility JavaVersion.VERSION_1_8
39 | }
40 | dexOptions {
41 | //预编译
42 | preDexLibraries true
43 | //支持大工程
44 | jumboMode = true
45 | //线程数
46 | threadCount = 16
47 | //dex内存,公式:dex内存 + 1G < Gradle内存
48 | javaMaxHeapSize "4g"
49 | additionalParameters = [
50 | '--multi-dex',//多分包
51 | '--set-max-idx-number=60000'//每个包内方法数上限
52 | ]
53 | }
54 | lintOptions {
55 | checkReleaseBuilds false
56 | disable 'InvalidPackage'
57 | disable "ResourceType"
58 | // Or, if you prefer, you can continue to check for errors in release builds,
59 | // but continue the build even when errors are found:
60 | abortOnError false
61 | }
62 | sourceSets {
63 | main {
64 | manifest.srcFile './AndroidManifest.xml'
65 | }
66 | }
67 | }
68 |
69 | dependencies {
70 | //TODO 4. 修改要调试的组件
71 | runtimeOnly project(':module:module_zhihu')
72 |
73 | implementation project(":component:CommonRes")//因为 CommonRes 依赖了 CommonSDK, 所以如果业务模块需要公共 UI 组件就依赖 CommonRes, 如果不需要就只依赖 CommonSDK
74 | implementation project(":component:CommonService")
75 |
76 | //test
77 | testImplementation rootProject.ext.dependencies["junit"]
78 | debugImplementation rootProject.ext.dependencies["canary-debug"]
79 | releaseImplementation rootProject.ext.dependencies["canary-release"]
80 | testImplementation rootProject.ext.dependencies["canary-release"]
81 | }
82 |
--------------------------------------------------------------------------------
/fake/fake-zhihu/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/fake/fake-zhihu/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
20 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
35 |
38 |
41 |
42 |
46 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/fake/fake-zhihu/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.android["compileSdkVersion"]
5 | buildToolsVersion rootProject.ext.android["buildToolsVersion"]
6 | defaultConfig {
7 | minSdkVersion rootProject.ext.android["minSdkVersion"]
8 | targetSdkVersion rootProject.ext.android["targetSdkVersion"]
9 | versionCode rootProject.ext.android["versionCode"]
10 | versionName rootProject.ext.android["versionName"]
11 | testInstrumentationRunner rootProject.ext.dependencies["androidJUnitRunner"]
12 | javaCompileOptions {
13 | annotationProcessorOptions {
14 | arguments = [AROUTER_MODULE_NAME: project.getName()]
15 | }
16 | }
17 | }
18 | buildTypes {
19 | debug {
20 | buildConfigField "boolean", "LOG_DEBUG", "true"
21 | buildConfigField "boolean", "USE_CANARY", "true"
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 |
26 | release {
27 | buildConfigField "boolean", "LOG_DEBUG", "false"
28 | buildConfigField "boolean", "USE_CANARY", "false"
29 | minifyEnabled true
30 | shrinkResources true
31 | zipAlignEnabled true
32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33 | }
34 | }
35 | useLibrary 'org.apache.http.legacy'
36 | compileOptions {
37 | targetCompatibility JavaVersion.VERSION_1_8
38 | sourceCompatibility JavaVersion.VERSION_1_8
39 | }
40 | dexOptions {
41 | //预编译
42 | preDexLibraries true
43 | //支持大工程
44 | jumboMode = true
45 | //线程数
46 | threadCount = 16
47 | //dex内存,公式:dex内存 + 1G < Gradle内存
48 | javaMaxHeapSize "4g"
49 | additionalParameters = [
50 | '--multi-dex',//多分包
51 | '--set-max-idx-number=60000'//每个包内方法数上限
52 | ]
53 | }
54 | lintOptions {
55 | checkReleaseBuilds false
56 | disable 'InvalidPackage'
57 | disable "ResourceType"
58 | // Or, if you prefer, you can continue to check for errors in release builds,
59 | // but continue the build even when errors are found:
60 | abortOnError false
61 | }
62 | sourceSets {
63 | main {
64 | manifest.srcFile './AndroidManifest.xml'
65 | }
66 | }
67 | }
68 |
69 | dependencies {
70 | runtimeOnly project(':module:module_zhihu')
71 |
72 | implementation project(":component:CommonRes")//因为 CommonRes 依赖了 CommonSDK, 所以如果业务模块需要公共 UI 组件就依赖 CommonRes, 如果不需要就只依赖 CommonSDK
73 | implementation project(":component:CommonService")
74 | implementation project(":component:CommonResource")
75 |
76 | //test
77 | testImplementation rootProject.ext.dependencies["junit"]
78 | debugImplementation rootProject.ext.dependencies["canary-debug"]
79 | releaseImplementation rootProject.ext.dependencies["canary-release"]
80 | testImplementation rootProject.ext.dependencies["canary-release"]
81 | }
82 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Thu May 25 20:59:18 CST 2017
16 | org.gradle.jvmargs=-Xmx2048m
17 | android.enableBuildCache=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LinXueyuanStdio/lifecycle-component/b6233fc38af61370d67273be1b165a5c84cb9c5f/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Sep 26 10:55:24 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/module/module_app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module/module_app/build.gradle:
--------------------------------------------------------------------------------
1 | apply from:"../../common_component_build.gradle"
2 |
3 | android {
4 | resourcePrefix "app_" //给 Module 内的资源名增加前缀, 避免资源名冲突
5 | }
6 |
7 | dependencies {
8 | implementation fileTree(include: ['*.jar'], dir: 'libs')
9 | implementation project(":component:CommonRes")//因为 CommonRes 依赖了 CommonSDK, 所以如果业务模块需要公共 UI 组件就依赖 CommonRes, 如果不需要就只依赖 CommonSDK
10 | implementation project(":component:CommonService")
11 | implementation project(":component:CommonResource")
12 | }
13 |
--------------------------------------------------------------------------------
/module/module_app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/jess/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # 混淆规则在 arms moudule下的proguard-rules.pro中,混淆前先参阅https://github.com/JessYanCoding/MVPArms/wiki#1.5
--------------------------------------------------------------------------------
/module/module_app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
21 |
26 |
27 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/module/module_app/src/main/java/me/jessyan/armscomponent/app/app/AppLifecyclesImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.app.app;
17 |
18 | import android.app.Application;
19 | import android.content.Context;
20 | import android.support.annotation.NonNull;
21 |
22 | import com.jess.arms.base.delegate.AppLifecycles;
23 | import com.jess.arms.utils.ArmsUtils;
24 | import com.squareup.leakcanary.LeakCanary;
25 | import com.squareup.leakcanary.RefWatcher;
26 |
27 | import me.jessyan.armscomponent.app.BuildConfig;
28 |
29 | /**
30 | * ================================================
31 | * 展示 {@link AppLifecycles} 的用法
32 | *
33 | * Created by JessYan on 04/09/2017 17:12
34 | * Contact me
35 | * Follow me
36 | * ================================================
37 | */
38 | public class AppLifecyclesImpl implements AppLifecycles {
39 |
40 | @Override
41 | public void attachBaseContext(@NonNull Context base) {
42 | // MultiDex.install(base); //这里比 onCreate 先执行,常用于 MultiDex 初始化,插件化框架的初始化
43 | }
44 |
45 | @Override
46 | public void onCreate(@NonNull Application application) {
47 | if (LeakCanary.isInAnalyzerProcess(application)) {
48 | // This process is dedicated to LeakCanary for heap analysis.
49 | // You should not init your app in this process.
50 | return;
51 | }
52 | //leakCanary内存泄露检查
53 | ArmsUtils.obtainAppComponentFromContext(application).extras().put(RefWatcher.class.getName(), BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);
54 | }
55 |
56 | @Override
57 | public void onTerminate(@NonNull Application application) {
58 |
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/module/module_app/src/main/java/me/jessyan/armscomponent/app/app/GlobalConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.app.app;
17 |
18 | import android.app.Application;
19 | import android.content.Context;
20 | import android.support.v4.app.Fragment;
21 | import android.support.v4.app.FragmentManager;
22 |
23 | import com.jess.arms.base.delegate.AppLifecycles;
24 | import com.jess.arms.di.module.GlobalConfigModule;
25 | import com.jess.arms.integration.ConfigModule;
26 | import com.jess.arms.utils.ArmsUtils;
27 | import com.squareup.leakcanary.RefWatcher;
28 |
29 | import java.util.List;
30 |
31 | /**
32 | * ================================================
33 | * 组件的全局配置信息在此配置, 需要将此实现类声明到 AndroidManifest 中
34 | * CommonSDK 中已有 {@link me.jessyan.armscomponent.commonsdk.core.GlobalConfiguration} 配置有组件可公用的配置信息
35 | * 这里用来配置一些组件自身私有的配置信息
36 | *
37 | * @see com.jess.arms.base.delegate.AppDelegate
38 | * @see com.jess.arms.integration.ManifestParser
39 | * Created by JessYan on 12/04/2017 17:25
40 | * Contact me
41 | * Follow me
42 | * ================================================
43 | */
44 | public final class GlobalConfiguration implements ConfigModule {
45 |
46 | @Override
47 | public void applyOptions(Context context, GlobalConfigModule.Builder builder) {
48 |
49 | }
50 |
51 | @Override
52 | public void injectAppLifecycle(Context context, List lifecycles) {
53 | // AppLifecycles 的所有方法都会在基类 Application 的对应的生命周期中被调用,所以在对应的方法中可以扩展一些自己需要的逻辑
54 | // 可以根据不同的逻辑添加多个实现类
55 | lifecycles.add(new AppLifecyclesImpl());
56 | }
57 |
58 | @Override
59 | public void injectActivityLifecycle(Context context, List lifecycles) {
60 |
61 | }
62 |
63 | @Override
64 | public void injectFragmentLifecycle(Context context, List lifecycles) {
65 | lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
66 | @Override
67 | public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
68 | ((RefWatcher) ArmsUtils
69 | .obtainAppComponentFromContext(f.getActivity())
70 | .extras()
71 | .get(RefWatcher.class.getName()))
72 | .watch(f);
73 | }
74 | });
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/module/module_app/src/main/java/me/jessyan/armscomponent/app/app/RouterInterceptor.java:
--------------------------------------------------------------------------------
1 | package me.jessyan.armscomponent.app.app;
2 |
3 | import android.content.Context;
4 |
5 | import com.alibaba.android.arouter.facade.Postcard;
6 | import com.alibaba.android.arouter.facade.annotation.Interceptor;
7 | import com.alibaba.android.arouter.facade.callback.InterceptorCallback;
8 | import com.alibaba.android.arouter.facade.template.IInterceptor;
9 | import com.alibaba.android.arouter.launcher.ARouter;
10 |
11 | /**
12 | * ================================================
13 | * 声明 {@link ARouter} 拦截器, 可以根据需求自定义拦截逻辑, 比如用户没有登录就拦截其他页面
14 | *
15 | * Created by JessYan on 08/08/2017 15:54
16 | * Contact with jess.yan.effort@gmail.com
17 | * Follow me on https://github.com/JessYanCoding
18 | * ================================================
19 | */
20 | @Interceptor(priority = 8, name = "RouterInterceptor")
21 | public class RouterInterceptor implements IInterceptor {
22 | private Context mContext;
23 |
24 | @Override
25 | public void process(Postcard postcard, InterceptorCallback callback) {
26 | callback.onContinue(postcard);
27 | //这里示例的意思是, 如果用户没有登录就只能进入登录注册等划分到 ACCOUNT 分组的页面, 用户进入其他页面将全部被拦截
28 | // if (postcard.getGroup().equals(RouterHub.ACCOUNT.split("/")[1])
29 | // callback.onContinue(postcard);
30 | // } else {
31 | // callback.onInterrupt(new Exception("用户没有登陆"));
32 | // }
33 | }
34 |
35 | @Override
36 | public void init(Context context) {
37 | mContext = context;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/module/module_app/src/main/java/me/jessyan/armscomponent/app/mvp/ui/activity/SplashActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.app.mvp.ui.activity;
17 |
18 | import android.os.Bundle;
19 | import android.support.annotation.NonNull;
20 | import android.support.annotation.Nullable;
21 |
22 | import com.alibaba.android.arouter.facade.annotation.Route;
23 | import com.jess.arms.base.BaseActivity;
24 | import com.jess.arms.di.component.AppComponent;
25 |
26 | import java.util.concurrent.TimeUnit;
27 |
28 | import io.reactivex.Observable;
29 | import io.reactivex.android.schedulers.AndroidSchedulers;
30 | import io.reactivex.functions.Consumer;
31 | import me.jessyan.armscomponent.app.R;
32 | import me.jessyan.armscomponent.commonsdk.core.RouterHub;
33 | import me.jessyan.armscomponent.commonsdk.utils.Utils;
34 |
35 | /**
36 | * ================================================
37 | * Created by JessYan on 18/04/2018 17:03
38 | * Contact me
39 | * Follow me
40 | * ================================================
41 | */
42 | @Route(path = RouterHub.APP_SPLASHACTIVITY)
43 | public class SplashActivity extends BaseActivity {
44 | @Override
45 | public void setupActivityComponent(@NonNull AppComponent appComponent) {
46 |
47 | }
48 |
49 | @Override
50 | public int initView(@Nullable Bundle savedInstanceState) {
51 | return R.layout.app_activity_splash;
52 | }
53 |
54 | @Override
55 | public void initData(@Nullable Bundle savedInstanceState) {
56 | Observable.timer(2, TimeUnit.SECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer() {
57 | @Override
58 | public void accept(Long aLong) throws Exception {
59 | Utils.navigation(SplashActivity.this, RouterHub.APP_MAINACTIVITY);
60 | finish();
61 | overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
62 | }
63 | });
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/module/module_app/src/main/res/layout/app_activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
24 |
25 |
35 |
36 |
46 |
47 |
57 |
58 |
--------------------------------------------------------------------------------
/module/module_app/src/main/res/layout/app_activity_splash.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/module/module_gank/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module/module_gank/build.gradle:
--------------------------------------------------------------------------------
1 | apply from:"../../common_component_build.gradle"
2 |
3 | android {
4 | resourcePrefix "gank_" //给 Module 内的资源名增加前缀, 避免资源名冲突
5 | }
6 |
7 | dependencies {
8 | implementation fileTree(include: ['*.jar'], dir: 'libs')
9 | implementation project(":component:CommonRes")//因为 CommonRes 依赖了 CommonSDK, 所以如果业务模块需要公共 UI 组件就依赖 CommonRes, 如果不需要就只依赖 CommonSDK
10 | implementation project(":component:CommonService")
11 | implementation project(":component:CommonResource")
12 | }
13 |
--------------------------------------------------------------------------------
/module/module_gank/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/jess/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # 混淆规则在 arms moudule下的proguard-rules.pro中,混淆前先参阅https://github.com/JessYanCoding/MVPArms/wiki#1.5
--------------------------------------------------------------------------------
/module/module_gank/src/androidTest/java/me/jessyan/armscomponent/app/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package me.jessyan.armscomponent.zhihu;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/module/module_gank/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
11 |
12 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/app/AppLifecyclesImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.app;
17 |
18 | import android.app.Application;
19 | import android.content.Context;
20 | import android.support.annotation.NonNull;
21 |
22 | import com.jess.arms.base.delegate.AppLifecycles;
23 |
24 | import me.jessyan.retrofiturlmanager.RetrofitUrlManager;
25 |
26 | import static me.jessyan.armscomponent.gank.mvp.model.api.Api.GANK_DOMAIN;
27 | import static me.jessyan.armscomponent.gank.mvp.model.api.Api.GANK_DOMAIN_NAME;
28 |
29 | /**
30 | * ================================================
31 | * 展示 {@link AppLifecycles} 的用法
32 | *
33 | * Created by JessYan on 04/09/2017 17:12
34 | * Contact me
35 | * Follow me
36 | * ================================================
37 | */
38 | public class AppLifecyclesImpl implements AppLifecycles {
39 |
40 | @Override
41 | public void attachBaseContext(@NonNull Context base) {
42 |
43 | }
44 |
45 | @Override
46 | public void onCreate(@NonNull Application application) {
47 | //使用 RetrofitUrlManager 切换 BaseUrl
48 | RetrofitUrlManager.getInstance().putDomain(GANK_DOMAIN_NAME, GANK_DOMAIN);
49 | }
50 |
51 | @Override
52 | public void onTerminate(@NonNull Application application) {
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/app/GankConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.app;
17 |
18 | /**
19 | * ================================================
20 | * Created by JessYan on 25/04/2018 16:48
21 | * Contact me
22 | * Follow me
23 | * ================================================
24 | */
25 | public interface GankConstants {
26 | int NUMBER_OF_PAGE = 10;
27 | }
28 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/app/GlobalConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.app;
17 |
18 | import android.app.Application;
19 | import android.content.Context;
20 | import android.support.v4.app.FragmentManager;
21 |
22 | import com.jess.arms.base.delegate.AppLifecycles;
23 | import com.jess.arms.di.module.GlobalConfigModule;
24 | import com.jess.arms.integration.ConfigModule;
25 |
26 | import java.util.List;
27 |
28 | /**
29 | * ================================================
30 | * 组件的全局配置信息在此配置, 需要将此实现类声明到 AndroidManifest 中
31 | * CommonSDK 中已有 {@link me.jessyan.armscomponent.commonsdk.core.GlobalConfiguration} 配置有所有组件都可公用的配置信息
32 | * 这里用来配置一些组件自身私有的配置信息
33 | *
34 | * @see com.jess.arms.base.delegate.AppDelegate
35 | * @see com.jess.arms.integration.ManifestParser
36 | * @see ConfigModule wiki 官方文档
37 | * Created by JessYan on 12/04/2017 17:25
38 | * Contact me
39 | * Follow me
40 | * ================================================
41 | */
42 | public final class GlobalConfiguration implements ConfigModule {
43 |
44 | @Override
45 | public void applyOptions(Context context, GlobalConfigModule.Builder builder) {
46 |
47 | }
48 |
49 | @Override
50 | public void injectAppLifecycle(Context context, List lifecycles) {
51 | // AppLifecycles 的所有方法都会在基类 Application 的对应的生命周期中被调用,所以在对应的方法中可以扩展一些自己需要的逻辑
52 | // 可以根据不同的逻辑添加多个实现类
53 | lifecycles.add(new AppLifecyclesImpl());
54 | }
55 |
56 | @Override
57 | public void injectActivityLifecycle(Context context, List lifecycles) {
58 |
59 | }
60 |
61 | @Override
62 | public void injectFragmentLifecycle(Context context, List lifecycles) {
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/component/service/GankInfoServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.component.service;
17 |
18 | import android.content.Context;
19 |
20 | import com.alibaba.android.arouter.facade.annotation.Route;
21 | import com.jess.arms.utils.ArmsUtils;
22 |
23 | import me.jessyan.armscomponent.commonsdk.core.RouterHub;
24 | import me.jessyan.armscomponent.commonservice.gank.bean.GankInfo;
25 | import me.jessyan.armscomponent.commonservice.gank.service.GankInfoService;
26 | import me.jessyan.armscomponent.gank.R;
27 |
28 | /**
29 | * ================================================
30 | * 向外提供服务的接口实现类, 在此类中实现一些具有特定功能的方法提供给外部, 即可让一个组件与其他组件或宿主进行交互
31 | *
32 | * @see CommonService wiki 官方文档
33 | * Created by JessYan on 2018/4/27 14:27
34 | * Contact me
35 | * Follow me
36 | * ================================================
37 | */
38 | @Route(path = RouterHub.GANK_SERVICE_GANKINFOSERVICE, name = "干货集中营信息服务")
39 | public class GankInfoServiceImpl implements GankInfoService {
40 | private Context mContext;
41 |
42 | @Override
43 | public GankInfo getInfo() {
44 | return new GankInfo(ArmsUtils.getString(mContext, R.string.public_name_gank));
45 | }
46 |
47 | @Override
48 | public void init(Context context) {
49 | mContext = context;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/di/component/GankHomeComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.di.component;
17 |
18 | import com.jess.arms.di.component.AppComponent;
19 | import com.jess.arms.di.scope.ActivityScope;
20 |
21 | import dagger.BindsInstance;
22 | import dagger.Component;
23 | import me.jessyan.armscomponent.gank.di.module.GankHomeModule;
24 | import me.jessyan.armscomponent.gank.mvp.contract.GankHomeContract;
25 | import me.jessyan.armscomponent.gank.mvp.ui.activity.GankHomeActivity;
26 |
27 | /**
28 | * ================================================
29 | * 展示 Component 的用法
30 | *
31 | * @see Component wiki 官方文档
32 | * Created by JessYan on 09/04/2016 11:17
33 | * Contact me
34 | * Follow me
35 | * ================================================
36 | */
37 | @ActivityScope
38 | @Component(modules = GankHomeModule.class, dependencies = AppComponent.class)
39 | public interface GankHomeComponent {
40 | void inject(GankHomeActivity activity);
41 | @Component.Builder
42 | interface Builder {
43 | @BindsInstance
44 | GankHomeComponent.Builder view(GankHomeContract.View view);
45 | GankHomeComponent.Builder appComponent(AppComponent appComponent);
46 | GankHomeComponent build();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/di/module/GankHomeModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.di.module;
17 |
18 | import android.support.v7.widget.GridLayoutManager;
19 | import android.support.v7.widget.RecyclerView;
20 |
21 | import com.jess.arms.di.scope.ActivityScope;
22 |
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | import dagger.Binds;
27 | import dagger.Module;
28 | import dagger.Provides;
29 | import me.jessyan.armscomponent.gank.mvp.contract.GankHomeContract;
30 | import me.jessyan.armscomponent.gank.mvp.model.GankModel;
31 | import me.jessyan.armscomponent.gank.mvp.model.entity.GankItemBean;
32 | import me.jessyan.armscomponent.gank.mvp.ui.adapter.GankHomeAdapter;
33 |
34 | /**
35 | * ================================================
36 | * 展示 Module 的用法
37 | *
38 | * @see Module wiki 官方文档
39 | * Created by JessYan on 09/04/2016 11:10
40 | * Contact me
41 | * Follow me
42 | * ================================================
43 | */
44 | @Module
45 | public abstract class GankHomeModule {
46 | @Binds
47 | abstract GankHomeContract.Model bindGankModel(GankModel model);
48 |
49 | @ActivityScope
50 | @Provides
51 | static RecyclerView.LayoutManager provideLayoutManager(GankHomeContract.View view) {
52 | return new GridLayoutManager(view.getActivity(), 2);
53 | }
54 |
55 | @ActivityScope
56 | @Provides
57 | static List provideList() {
58 | return new ArrayList<>();
59 | }
60 |
61 | @ActivityScope
62 | @Provides
63 | static RecyclerView.Adapter provideGankHomeAdapter(List list) {
64 | return new GankHomeAdapter(list);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/mvp/contract/GankHomeContract.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.mvp.contract;
17 |
18 | import android.app.Activity;
19 |
20 | import com.jess.arms.mvp.IModel;
21 | import com.jess.arms.mvp.IView;
22 |
23 | import java.util.List;
24 |
25 | import io.reactivex.Observable;
26 | import me.jessyan.armscomponent.gank.mvp.model.entity.GankBaseResponse;
27 | import me.jessyan.armscomponent.gank.mvp.model.entity.GankItemBean;
28 |
29 | /**
30 | * ================================================
31 | * 展示 Contract 的用法
32 | *
33 | * @see Contract wiki 官方文档
34 | * Created by JessYan on 09/04/2016 10:47
35 | * Contact me
36 | * Follow me
37 | * ================================================
38 | */
39 | public interface GankHomeContract {
40 | //对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
41 | interface View extends IView {
42 | void startLoadMore();
43 | void endLoadMore();
44 | Activity getActivity();
45 | }
46 | //Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,如是否使用缓存
47 | interface Model extends IModel{
48 | Observable>> getGirlList(int num, int page);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/mvp/model/GankModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.mvp.model;
17 |
18 | import com.jess.arms.di.scope.ActivityScope;
19 | import com.jess.arms.integration.IRepositoryManager;
20 | import com.jess.arms.mvp.BaseModel;
21 |
22 | import java.util.List;
23 |
24 | import javax.inject.Inject;
25 |
26 | import io.reactivex.Observable;
27 | import me.jessyan.armscomponent.gank.mvp.contract.GankHomeContract;
28 | import me.jessyan.armscomponent.gank.mvp.model.api.service.GankService;
29 | import me.jessyan.armscomponent.gank.mvp.model.entity.GankBaseResponse;
30 | import me.jessyan.armscomponent.gank.mvp.model.entity.GankItemBean;
31 |
32 | /**
33 | * ================================================
34 | * 展示 Model 的用法
35 | *
36 | * @see Model wiki 官方文档
37 | * Created by JessYan on 09/04/2016 10:56
38 | * Contact me
39 | * Follow me
40 | * ================================================
41 | */
42 | @ActivityScope
43 | public class GankModel extends BaseModel implements GankHomeContract.Model {
44 |
45 | @Inject
46 | public GankModel(IRepositoryManager repositoryManager) {
47 | super(repositoryManager);
48 | }
49 |
50 | @Override
51 | public Observable>> getGirlList(int num, int page) {
52 | return mRepositoryManager
53 | .obtainRetrofitService(GankService.class)
54 | .getGirlList(num, page);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/mvp/model/api/Api.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.mvp.model.api;
17 |
18 | /**
19 | * ================================================
20 | * 存放一些与 API 有关的东西,如请求地址,请求码等
21 | *
22 | * Created by JessYan on 08/05/2016 11:25
23 | * Contact me
24 | * Follow me
25 | * ================================================
26 | */
27 | public interface Api {
28 | String GANK_DOMAIN_NAME = "gank";
29 | String GANK_DOMAIN = "http://gank.io";
30 | }
31 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/mvp/model/api/service/GankService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.mvp.model.api.service;
17 |
18 | import java.util.List;
19 |
20 | import io.reactivex.Observable;
21 | import me.jessyan.armscomponent.gank.mvp.model.entity.GankBaseResponse;
22 | import me.jessyan.armscomponent.gank.mvp.model.entity.GankItemBean;
23 | import retrofit2.Retrofit;
24 | import retrofit2.http.GET;
25 | import retrofit2.http.Headers;
26 | import retrofit2.http.Path;
27 |
28 | import static me.jessyan.armscomponent.gank.mvp.model.api.Api.GANK_DOMAIN_NAME;
29 | import static me.jessyan.retrofiturlmanager.RetrofitUrlManager.DOMAIN_NAME_HEADER;
30 |
31 | /**
32 | * ================================================
33 | * 展示 {@link Retrofit#create(Class)} 中需要传入的 ApiService 的使用方式
34 | * 存放关于 gank 的一些 API
35 | *
36 | * Created by JessYan on 08/05/2016 12:05
37 | * Contact me
38 | * Follow me
39 | * ================================================
40 | */
41 | public interface GankService {
42 | /**
43 | * 妹纸列表
44 | */
45 | @Headers({DOMAIN_NAME_HEADER + GANK_DOMAIN_NAME})
46 | @GET("/api/data/福利/{num}/{page}")
47 | Observable>> getGirlList(@Path("num") int num, @Path("page") int page);
48 | }
49 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/mvp/model/entity/GankBaseResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.mvp.model.entity;
17 |
18 | import java.io.Serializable;
19 |
20 | /**
21 | * ================================================
22 | * 如果你服务器返回的数据格式固定为这种方式(这里只提供思想,服务器返回的数据格式可能不一致,可根据自家服务器返回的格式作更改)
23 | * 指定范型即可改变 {@code data} 字段的类型, 达到重用 {@link GankBaseResponse}
24 | *
25 | * Created by JessYan on 26/09/2016 15:19
26 | * Contact me
27 | * Follow me
28 | * ================================================
29 | */
30 | public class GankBaseResponse implements Serializable {
31 | private boolean error;
32 | private T results;
33 |
34 | public T getResults() {
35 | return results;
36 | }
37 |
38 | public void setResults(T results) {
39 | this.results = results;
40 | }
41 |
42 | public boolean getError() {
43 | return error;
44 | }
45 |
46 | public void setError(boolean error) {
47 | this.error = error;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/mvp/ui/adapter/GankHomeAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.mvp.ui.adapter;
17 |
18 | import android.view.View;
19 |
20 | import com.jess.arms.base.BaseHolder;
21 | import com.jess.arms.base.DefaultAdapter;
22 |
23 | import java.util.List;
24 |
25 | import me.jessyan.armscomponent.gank.R;
26 | import me.jessyan.armscomponent.gank.mvp.model.entity.GankItemBean;
27 | import me.jessyan.armscomponent.gank.mvp.ui.holder.GankHomeItemHolder;
28 |
29 | /**
30 | * ================================================
31 | * 展示 {@link DefaultAdapter} 的用法
32 | *
33 | * Created by JessYan on 09/04/2016 12:57
34 | * Contact me
35 | * Follow me
36 | * ================================================
37 | */
38 | public class GankHomeAdapter extends DefaultAdapter {
39 | public GankHomeAdapter(List infos) {
40 | super(infos);
41 | }
42 |
43 | @Override
44 | public BaseHolder getHolder(View v, int viewType) {
45 | return new GankHomeItemHolder(v);
46 | }
47 |
48 | @Override
49 | public int getLayoutId(int viewType) {
50 | return R.layout.gank_recycle_list;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/java/me/jessyan/armscomponent/gank/mvp/ui/holder/GankHomeItemHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gank.mvp.ui.holder;
17 |
18 | import android.text.TextUtils;
19 | import android.view.View;
20 | import android.widget.ImageView;
21 |
22 | import com.jess.arms.base.BaseHolder;
23 | import com.jess.arms.di.component.AppComponent;
24 | import com.jess.arms.http.imageloader.ImageLoader;
25 | import com.jess.arms.utils.ArmsUtils;
26 |
27 | import butterknife.BindView;
28 | import me.jessyan.armscomponent.commonsdk.imgaEngine.config.CommonImageConfigImpl;
29 | import me.jessyan.armscomponent.gank.R;
30 | import me.jessyan.armscomponent.gank.R2;
31 | import me.jessyan.armscomponent.gank.mvp.model.entity.GankItemBean;
32 |
33 | /**
34 | * ================================================
35 | * 展示 {@link BaseHolder} 的用法
36 | *
37 | * Created by JessYan on 9/4/16 12:56
38 | * Contact me
39 | * Follow me
40 | * ================================================
41 | */
42 | public class GankHomeItemHolder extends BaseHolder {
43 |
44 | @BindView(R2.id.iv_avatar)
45 | ImageView mAvatar;
46 | private AppComponent mAppComponent;
47 | private ImageLoader mImageLoader;//用于加载图片的管理类,默认使用 Glide,使用策略模式,可替换框架
48 |
49 | public GankHomeItemHolder(View itemView) {
50 | super(itemView);
51 | //可以在任何可以拿到 Context 的地方,拿到 AppComponent,从而得到用 Dagger 管理的单例对象
52 | mAppComponent = ArmsUtils.obtainAppComponentFromContext(itemView.getContext());
53 | mImageLoader = mAppComponent.imageLoader();
54 | }
55 |
56 | @Override
57 | public void setData(GankItemBean data, int position) {
58 | //itemView 的 Context 就是 Activity, Glide 会自动处理并和该 Activity 的生命周期绑定
59 | if (!TextUtils.isEmpty(data.getUrl())) {
60 | mImageLoader.loadImage(itemView.getContext(),
61 | CommonImageConfigImpl
62 | .builder()
63 | .url(data.getUrl())
64 | .imageView(mAvatar)
65 | .build());
66 | } else {
67 | mAvatar.setImageResource(R.mipmap.gank_ic_logo);
68 | }
69 | }
70 |
71 | @Override
72 | protected void onRelease() {
73 | mImageLoader.clear(mAppComponent.application(), CommonImageConfigImpl.builder()
74 | .imageViews(mAvatar)
75 | .build());
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/res/layout/gank_activity_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
19 |
20 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/module/module_gank/src/main/res/layout/gank_recycle_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
15 |
--------------------------------------------------------------------------------
/module/module_gank/src/test/java/me/jessyan/armscomponent/app/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package me.jessyan.armscomponent.zhihu;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 |
16 | }
--------------------------------------------------------------------------------
/module/module_gold/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module/module_gold/build.gradle:
--------------------------------------------------------------------------------
1 | apply from:"../../common_component_build.gradle"
2 |
3 | android {
4 | resourcePrefix "gold_" //给 Module 内的资源名增加前缀, 避免资源名冲突
5 | }
6 |
7 | dependencies {
8 | implementation fileTree(include: ['*.jar'], dir: 'libs')
9 | implementation project(":component:CommonRes")//因为 CommonRes 依赖了 CommonSDK, 所以如果业务模块需要公共 UI 组件就依赖 CommonRes, 如果不需要就只依赖 CommonSDK
10 | implementation project(":component:CommonService")
11 | implementation project(":component:CommonResource")
12 | }
13 |
--------------------------------------------------------------------------------
/module/module_gold/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/jess/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # 混淆规则在 arms moudule下的proguard-rules.pro中,混淆前先参阅https://github.com/JessYanCoding/MVPArms/wiki#1.5
--------------------------------------------------------------------------------
/module/module_gold/src/androidTest/java/me/jessyan/armscomponent/app/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package me.jessyan.armscomponent.zhihu;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/module/module_gold/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
11 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/app/AppLifecyclesImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.app;
17 |
18 | import android.app.Application;
19 | import android.content.Context;
20 | import android.support.annotation.NonNull;
21 |
22 | import com.jess.arms.base.delegate.AppLifecycles;
23 |
24 | import me.jessyan.retrofiturlmanager.RetrofitUrlManager;
25 |
26 | import static me.jessyan.armscomponent.gold.mvp.model.api.Api.GOLD_DOMAIN;
27 | import static me.jessyan.armscomponent.gold.mvp.model.api.Api.GOLD_DOMAIN_NAME;
28 |
29 | /**
30 | * ================================================
31 | * 展示 {@link AppLifecycles} 的用法
32 | *
33 | * Created by JessYan on 04/09/2017 17:12
34 | * Contact me
35 | * Follow me
36 | * ================================================
37 | */
38 | public class AppLifecyclesImpl implements AppLifecycles {
39 |
40 | @Override
41 | public void attachBaseContext(@NonNull Context base) {
42 |
43 | }
44 |
45 | @Override
46 | public void onCreate(@NonNull Application application) {
47 | //使用 RetrofitUrlManager 切换 BaseUrl
48 | RetrofitUrlManager.getInstance().putDomain(GOLD_DOMAIN_NAME, GOLD_DOMAIN);
49 | }
50 |
51 | @Override
52 | public void onTerminate(@NonNull Application application) {
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/app/GlobalConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.app;
17 |
18 | import android.app.Application;
19 | import android.content.Context;
20 | import android.support.v4.app.FragmentManager;
21 |
22 | import com.jess.arms.base.delegate.AppLifecycles;
23 | import com.jess.arms.di.module.GlobalConfigModule;
24 | import com.jess.arms.integration.ConfigModule;
25 |
26 | import java.util.List;
27 |
28 | /**
29 | * ================================================
30 | * 组件的全局配置信息在此配置, 需要将此实现类声明到 AndroidManifest 中
31 | * CommonSDK 中已有 {@link me.jessyan.armscomponent.commonsdk.core.GlobalConfiguration} 配置有所有组件都可公用的配置信息
32 | * 这里用来配置一些组件自身私有的配置信息
33 | *
34 | * @see com.jess.arms.base.delegate.AppDelegate
35 | * @see com.jess.arms.integration.ManifestParser
36 | * @see ConfigModule wiki 官方文档
37 | * Created by JessYan on 12/04/2017 17:25
38 | * Contact me
39 | * Follow me
40 | * ================================================
41 | */
42 | public final class GlobalConfiguration implements ConfigModule {
43 |
44 | @Override
45 | public void applyOptions(Context context, GlobalConfigModule.Builder builder) {
46 |
47 | }
48 |
49 | @Override
50 | public void injectAppLifecycle(Context context, List lifecycles) {
51 | // AppLifecycles 的所有方法都会在基类 Application 的对应的生命周期中被调用,所以在对应的方法中可以扩展一些自己需要的逻辑
52 | // 可以根据不同的逻辑添加多个实现类
53 | lifecycles.add(new AppLifecyclesImpl());
54 | }
55 |
56 | @Override
57 | public void injectActivityLifecycle(Context context, List lifecycles) {
58 |
59 | }
60 |
61 | @Override
62 | public void injectFragmentLifecycle(Context context, List lifecycles) {
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/app/GoldConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.app;
17 |
18 | /**
19 | * ================================================
20 | * Created by JessYan on 25/04/2018 16:48
21 | * Contact me
22 | * Follow me
23 | * ================================================
24 | */
25 | public interface GoldConstants {
26 | int NUMBER_OF_PAGE = 10;
27 | String LEANCLOUD_ID = "mhke0kuv33myn4t4ghuid4oq2hjj12li374hvcif202y5bm6";
28 | String LEANCLOUD_SIGN = "badc5461a25a46291054b902887a68eb,1480438132702";
29 | String GOLD_TYPE_ANDROID = "android";
30 | String DETAIL_URL = "detail_url";
31 | String DETAIL_TITLE = "detail_title";
32 | }
33 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/component/service/GoldInfoServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.component.service;
17 |
18 | import android.content.Context;
19 |
20 | import com.alibaba.android.arouter.facade.annotation.Route;
21 | import com.jess.arms.utils.ArmsUtils;
22 |
23 | import me.jessyan.armscomponent.commonsdk.core.RouterHub;
24 | import me.jessyan.armscomponent.commonservice.gold.bean.GoldInfo;
25 | import me.jessyan.armscomponent.commonservice.gold.service.GoldInfoService;
26 | import me.jessyan.armscomponent.gold.R;
27 |
28 | /**
29 | * ================================================
30 | * 向外提供服务的接口实现类, 在此类中实现一些具有特定功能的方法提供给外部, 即可让一个组件与其他组件或宿主进行交互
31 | *
32 | * @see CommonService wiki 官方文档
33 | * Created by JessYan on 2018/4/27 14:27
34 | * Contact me
35 | * Follow me
36 | * ================================================
37 | */
38 | @Route(path = RouterHub.GOLD_SERVICE_GOLDINFOSERVICE, name = "稀土掘金信息服务")
39 | public class GoldInfoServiceImpl implements GoldInfoService {
40 | private Context mContext;
41 |
42 | @Override
43 | public GoldInfo getInfo() {
44 | return new GoldInfo(ArmsUtils.getString(mContext, R.string.public_name_gold));
45 | }
46 |
47 | @Override
48 | public void init(Context context) {
49 | mContext = context;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/di/component/GoldHomeComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.di.component;
17 |
18 | import com.jess.arms.di.component.AppComponent;
19 | import com.jess.arms.di.scope.ActivityScope;
20 |
21 | import dagger.BindsInstance;
22 | import dagger.Component;
23 | import me.jessyan.armscomponent.gold.di.module.GoldHomeModule;
24 | import me.jessyan.armscomponent.gold.mvp.contract.GoldHomeContract;
25 | import me.jessyan.armscomponent.gold.mvp.ui.activity.GoldHomeActivity;
26 |
27 | /**
28 | * ================================================
29 | * 展示 Component 的用法
30 | *
31 | * @see Component wiki 官方文档
32 | * Created by JessYan on 09/04/2016 11:17
33 | * Contact me
34 | * Follow me
35 | * ================================================
36 | */
37 | @ActivityScope
38 | @Component(modules = GoldHomeModule.class, dependencies = AppComponent.class)
39 | public interface GoldHomeComponent {
40 | void inject(GoldHomeActivity activity);
41 | @Component.Builder
42 | interface Builder {
43 | @BindsInstance
44 | GoldHomeComponent.Builder view(GoldHomeContract.View view);
45 | GoldHomeComponent.Builder appComponent(AppComponent appComponent);
46 | GoldHomeComponent build();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/di/module/GoldHomeModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.di.module;
17 |
18 | import android.support.v7.widget.LinearLayoutManager;
19 | import android.support.v7.widget.RecyclerView;
20 | import android.view.View;
21 |
22 | import com.alibaba.android.arouter.launcher.ARouter;
23 | import com.jess.arms.base.DefaultAdapter;
24 | import com.jess.arms.di.scope.ActivityScope;
25 |
26 | import java.util.ArrayList;
27 | import java.util.List;
28 |
29 | import dagger.Binds;
30 | import dagger.Module;
31 | import dagger.Provides;
32 | import me.jessyan.armscomponent.commonsdk.core.RouterHub;
33 | import me.jessyan.armscomponent.gold.app.GoldConstants;
34 | import me.jessyan.armscomponent.gold.mvp.contract.GoldHomeContract;
35 | import me.jessyan.armscomponent.gold.mvp.model.GoldModel;
36 | import me.jessyan.armscomponent.gold.mvp.model.entity.GoldListBean;
37 | import me.jessyan.armscomponent.gold.mvp.ui.adapter.GoldHomeAdapter;
38 |
39 | /**
40 | * ================================================
41 | * 展示 Module 的用法
42 | *
43 | * @see Module wiki 官方文档
44 | * Created by JessYan on 09/04/2016 11:10
45 | * Contact me
46 | * Follow me
47 | * ================================================
48 | */
49 | @Module
50 | public abstract class GoldHomeModule {
51 | @Binds
52 | abstract GoldHomeContract.Model bindGoldModel(GoldModel model);
53 |
54 | @ActivityScope
55 | @Provides
56 | static RecyclerView.LayoutManager provideLayoutManager(GoldHomeContract.View view) {
57 | return new LinearLayoutManager(view.getActivity());
58 | }
59 |
60 | @ActivityScope
61 | @Provides
62 | static List provideList() {
63 | return new ArrayList<>();
64 | }
65 |
66 | @ActivityScope
67 | @Provides
68 | static RecyclerView.Adapter provideGoldHomeAdapter(GoldHomeContract.View GoldHomeView, List list){
69 | GoldHomeAdapter adapter = new GoldHomeAdapter(list);
70 | adapter.setOnItemClickListener(new DefaultAdapter.OnRecyclerViewItemClickListener() {
71 | @Override
72 | public void onItemClick(View view, int viewType, GoldListBean data, int position) {
73 | ARouter.getInstance()
74 | .build(RouterHub.GOLD_DETAILACTIVITY)
75 | .withString(GoldConstants.DETAIL_URL, data.getUrl())
76 | .withString(GoldConstants.DETAIL_TITLE, data.getTitle())
77 | .navigation(GoldHomeView.getActivity());
78 | }
79 | });
80 | return adapter;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/mvp/contract/GoldHomeContract.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.mvp.contract;
17 |
18 | import android.app.Activity;
19 |
20 | import com.jess.arms.mvp.IModel;
21 | import com.jess.arms.mvp.IView;
22 |
23 | import java.util.List;
24 |
25 | import io.reactivex.Observable;
26 | import me.jessyan.armscomponent.gold.mvp.model.entity.GoldBaseResponse;
27 | import me.jessyan.armscomponent.gold.mvp.model.entity.GoldListBean;
28 |
29 | /**
30 | * ================================================
31 | * 展示 Contract 的用法
32 | *
33 | * @see Contract wiki 官方文档
34 | * Created by JessYan on 09/04/2016 10:47
35 | * Contact me
36 | * Follow me
37 | * ================================================
38 | */
39 | public interface GoldHomeContract {
40 | //对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
41 | interface View extends IView {
42 | void startLoadMore();
43 | void endLoadMore();
44 | Activity getActivity();
45 | }
46 | //Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,如是否使用缓存
47 | interface Model extends IModel{
48 | Observable>> getGoldList(String type, int num, int page);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/mvp/model/GoldModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.mvp.model;
17 |
18 | import com.jess.arms.di.scope.ActivityScope;
19 | import com.jess.arms.integration.IRepositoryManager;
20 | import com.jess.arms.mvp.BaseModel;
21 |
22 | import java.util.List;
23 |
24 | import javax.inject.Inject;
25 |
26 | import io.reactivex.Observable;
27 | import me.jessyan.armscomponent.gold.app.GoldConstants;
28 | import me.jessyan.armscomponent.gold.mvp.contract.GoldHomeContract;
29 | import me.jessyan.armscomponent.gold.mvp.model.api.service.GoldService;
30 | import me.jessyan.armscomponent.gold.mvp.model.entity.GoldBaseResponse;
31 | import me.jessyan.armscomponent.gold.mvp.model.entity.GoldListBean;
32 |
33 | /**
34 | * ================================================
35 | * 展示 Model 的用法
36 | *
37 | * @see Model wiki 官方文档
38 | * Created by JessYan on 09/04/2016 10:56
39 | * Contact me
40 | * Follow me
41 | * ================================================
42 | */
43 | @ActivityScope
44 | public class GoldModel extends BaseModel implements GoldHomeContract.Model {
45 |
46 | @Inject
47 | public GoldModel(IRepositoryManager repositoryManager) {
48 | super(repositoryManager);
49 | }
50 |
51 | @Override
52 | public Observable>> getGoldList(String type, int num, int page) {
53 | return mRepositoryManager
54 | .obtainRetrofitService(GoldService.class)
55 | .getGoldList(GoldConstants.LEANCLOUD_ID, GoldConstants.LEANCLOUD_SIGN,
56 | "{\"category\":\"" + type + "\"}", "-createdAt", "user,user.installation", num, page * num);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/mvp/model/api/Api.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.mvp.model.api;
17 |
18 | /**
19 | * ================================================
20 | * 存放一些与 API 有关的东西,如请求地址,请求码等
21 | *
22 | * Created by JessYan on 08/05/2016 11:25
23 | * Contact me
24 | * Follow me
25 | * ================================================
26 | */
27 | public interface Api {
28 | String GOLD_DOMAIN_NAME = "gold";
29 | String GOLD_DOMAIN = "https://api.leancloud.cn";
30 | }
31 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/mvp/model/api/service/GoldService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.mvp.model.api.service;
17 |
18 | import java.util.List;
19 |
20 | import io.reactivex.Observable;
21 | import me.jessyan.armscomponent.gold.mvp.model.entity.GoldBaseResponse;
22 | import me.jessyan.armscomponent.gold.mvp.model.entity.GoldListBean;
23 | import retrofit2.Retrofit;
24 | import retrofit2.http.GET;
25 | import retrofit2.http.Header;
26 | import retrofit2.http.Headers;
27 | import retrofit2.http.Query;
28 |
29 | import static me.jessyan.armscomponent.gold.mvp.model.api.Api.GOLD_DOMAIN_NAME;
30 | import static me.jessyan.retrofiturlmanager.RetrofitUrlManager.DOMAIN_NAME_HEADER;
31 |
32 | /**
33 | * ================================================
34 | * 展示 {@link Retrofit#create(Class)} 中需要传入的 ApiService 的使用方式
35 | * 存放关于 gold 的一些 API
36 | *
37 | * Created by JessYan on 08/05/2016 12:05
38 | * Contact me
39 | * Follow me
40 | * ================================================
41 | */
42 | public interface GoldService {
43 | /**
44 | * 文章列表
45 | */
46 | @Headers({DOMAIN_NAME_HEADER + GOLD_DOMAIN_NAME})
47 | @GET("/1.1/classes/Entry")
48 | Observable>> getGoldList(@Header("X-LC-Id") String id,
49 | @Header("X-LC-Sign") String sign,
50 | @Query("where") String where,
51 | @Query("order") String order,
52 | @Query("include") String include,
53 | @Query("limit") int limit,
54 | @Query("skip") int skip);
55 | }
56 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/mvp/model/entity/GoldBaseResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.mvp.model.entity;
17 |
18 | import java.io.Serializable;
19 |
20 | /**
21 | * ================================================
22 | * 如果你服务器返回的数据格式固定为这种方式(这里只提供思想,服务器返回的数据格式可能不一致,可根据自家服务器返回的格式作更改)
23 | * 指定范型即可改变 {@code data} 字段的类型, 达到重用 {@link GoldBaseResponse}
24 | *
25 | * Created by JessYan on 26/09/2016 15:19
26 | * Contact me
27 | * Follow me
28 | * ================================================
29 | */
30 | public class GoldBaseResponse implements Serializable {
31 | private T results;
32 |
33 | public T getResults() {
34 | return results;
35 | }
36 |
37 | public void setResults(T results) {
38 | this.results = results;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/mvp/ui/adapter/GoldHomeAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.mvp.ui.adapter;
17 |
18 | import android.view.View;
19 |
20 | import com.jess.arms.base.BaseHolder;
21 | import com.jess.arms.base.DefaultAdapter;
22 |
23 | import java.util.List;
24 |
25 | import me.jessyan.armscomponent.gold.R;
26 | import me.jessyan.armscomponent.gold.mvp.model.entity.GoldListBean;
27 | import me.jessyan.armscomponent.gold.mvp.ui.holder.GoldHomeItemHolder;
28 |
29 | /**
30 | * ================================================
31 | * 展示 {@link DefaultAdapter} 的用法
32 | *
33 | * Created by JessYan on 09/04/2016 12:57
34 | * Contact me
35 | * Follow me
36 | * ================================================
37 | */
38 | public class GoldHomeAdapter extends DefaultAdapter {
39 | public GoldHomeAdapter(List infos) {
40 | super(infos);
41 | }
42 |
43 | @Override
44 | public BaseHolder getHolder(View v, int viewType) {
45 | return new GoldHomeItemHolder(v);
46 | }
47 |
48 | @Override
49 | public int getLayoutId(int viewType) {
50 | return R.layout.gold_recycle_list;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/java/me/jessyan/armscomponent/gold/mvp/ui/holder/GoldHomeItemHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.gold.mvp.ui.holder;
17 |
18 | import android.text.TextUtils;
19 | import android.view.View;
20 | import android.widget.ImageView;
21 | import android.widget.TextView;
22 |
23 | import com.jess.arms.base.BaseHolder;
24 | import com.jess.arms.di.component.AppComponent;
25 | import com.jess.arms.http.imageloader.ImageLoader;
26 | import com.jess.arms.utils.ArmsUtils;
27 |
28 | import butterknife.BindView;
29 | import io.reactivex.Observable;
30 | import me.jessyan.armscomponent.commonsdk.imgaEngine.config.CommonImageConfigImpl;
31 | import me.jessyan.armscomponent.gold.R;
32 | import me.jessyan.armscomponent.gold.R2;
33 | import me.jessyan.armscomponent.gold.mvp.model.entity.GoldListBean;
34 |
35 | /**
36 | * ================================================
37 | * 展示 {@link BaseHolder} 的用法
38 | *
39 | * Created by JessYan on 9/4/16 12:56
40 | * Contact me
41 | * Follow me
42 | * ================================================
43 | */
44 | public class GoldHomeItemHolder extends BaseHolder {
45 |
46 | @BindView(R2.id.iv_avatar)
47 | ImageView mAvatar;
48 | @BindView(R2.id.tv_name)
49 | TextView mName;
50 | private AppComponent mAppComponent;
51 | private ImageLoader mImageLoader;//用于加载图片的管理类,默认使用 Glide,使用策略模式,可替换框架
52 |
53 | public GoldHomeItemHolder(View itemView) {
54 | super(itemView);
55 | //可以在任何可以拿到 Context 的地方,拿到 AppComponent,从而得到用 Dagger 管理的单例对象
56 | mAppComponent = ArmsUtils.obtainAppComponentFromContext(itemView.getContext());
57 | mImageLoader = mAppComponent.imageLoader();
58 | }
59 |
60 | @Override
61 | public void setData(GoldListBean data, int position) {
62 | Observable.just(data.getTitle())
63 | .subscribe(s -> mName.setText(s));
64 |
65 | if (data.getScreenshot() != null && !TextUtils.isEmpty(data.getScreenshot().getUrl())) {
66 | //itemView 的 Context 就是 Activity, Glide 会自动处理并和该 Activity 的生命周期绑定
67 | mImageLoader.loadImage(itemView.getContext(),
68 | CommonImageConfigImpl
69 | .builder()
70 | .url(data.getScreenshot().getUrl())
71 | .imageView(mAvatar)
72 | .build());
73 | } else {
74 | mAvatar.setImageResource(R.mipmap.gold_ic_logo);
75 | }
76 | }
77 |
78 | @Override
79 | protected void onRelease() {
80 | mImageLoader.clear(mAppComponent.application(), CommonImageConfigImpl.builder()
81 | .imageViews(mAvatar)
82 | .build());
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/res/layout/gold_activity_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/res/layout/gold_activity_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
17 |
18 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/module/module_gold/src/main/res/layout/gold_recycle_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
21 |
22 |
28 |
29 |
30 |
39 |
40 |
--------------------------------------------------------------------------------
/module/module_gold/src/test/java/me/jessyan/armscomponent/app/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package me.jessyan.armscomponent.zhihu;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 |
16 | }
--------------------------------------------------------------------------------
/module/module_zhihu/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module/module_zhihu/build.gradle:
--------------------------------------------------------------------------------
1 | apply from:"../../common_component_build.gradle"
2 |
3 | android {
4 | resourcePrefix "zhihu_" //给 Module 内的资源名增加前缀, 避免资源名冲突
5 | }
6 |
7 | dependencies {
8 | implementation fileTree(include: ['*.jar'], dir: 'libs')
9 | implementation project(":component:CommonRes")//因为 CommonRes 依赖了 CommonSDK, 所以如果业务模块需要公共 UI 组件就依赖 CommonRes, 如果不需要就只依赖 CommonSDK
10 | implementation project(":component:CommonService")
11 | implementation project(":component:CommonResource")
12 | }
13 |
--------------------------------------------------------------------------------
/module/module_zhihu/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/jess/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # 混淆规则在 arms moudule下的proguard-rules.pro中,混淆前先参阅https://github.com/JessYanCoding/MVPArms/wiki#1.5
--------------------------------------------------------------------------------
/module/module_zhihu/src/androidTest/java/me/jessyan/armscomponent/app/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package me.jessyan.armscomponent.zhihu;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
11 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/app/AppLifecyclesImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.app;
17 |
18 | import android.app.Application;
19 | import android.content.Context;
20 | import android.support.annotation.NonNull;
21 |
22 | import com.jess.arms.base.delegate.AppLifecycles;
23 |
24 | import me.jessyan.retrofiturlmanager.RetrofitUrlManager;
25 |
26 | import static me.jessyan.armscomponent.zhihu.mvp.model.api.Api.ZHIHU_DOMAIN;
27 | import static me.jessyan.armscomponent.zhihu.mvp.model.api.Api.ZHIHU_DOMAIN_NAME;
28 |
29 | /**
30 | * ================================================
31 | * 展示 {@link AppLifecycles} 的用法
32 | *
33 | * Created by JessYan on 04/09/2017 17:12
34 | * Contact me
35 | * Follow me
36 | * ================================================
37 | */
38 | public class AppLifecyclesImpl implements AppLifecycles {
39 |
40 | @Override
41 | public void attachBaseContext(@NonNull Context base) {
42 |
43 | }
44 |
45 | @Override
46 | public void onCreate(@NonNull Application application) {
47 | //使用 RetrofitUrlManager 切换 BaseUrl
48 | RetrofitUrlManager.getInstance().putDomain(ZHIHU_DOMAIN_NAME, ZHIHU_DOMAIN);
49 | }
50 |
51 | @Override
52 | public void onTerminate(@NonNull Application application) {
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/app/GlobalConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.app;
17 |
18 | import android.app.Application;
19 | import android.content.Context;
20 | import android.support.v4.app.FragmentManager;
21 |
22 | import com.jess.arms.base.delegate.AppLifecycles;
23 | import com.jess.arms.di.module.GlobalConfigModule;
24 | import com.jess.arms.integration.ConfigModule;
25 |
26 | import java.util.List;
27 |
28 | /**
29 | * ================================================
30 | * 组件的全局配置信息在此配置, 需要将此实现类声明到 AndroidManifest 中
31 | * CommonSDK 中已有 {@link me.jessyan.armscomponent.commonsdk.core.GlobalConfiguration} 配置有所有组件都可公用的配置信息
32 | * 这里用来配置一些组件自身私有的配置信息
33 | *
34 | * @see com.jess.arms.base.delegate.AppDelegate
35 | * @see com.jess.arms.integration.ManifestParser
36 | * @see ConfigModule wiki 官方文档
37 | * Created by JessYan on 12/04/2017 17:25
38 | * Contact me
39 | * Follow me
40 | * ================================================
41 | */
42 | public final class GlobalConfiguration implements ConfigModule {
43 |
44 | @Override
45 | public void applyOptions(Context context, GlobalConfigModule.Builder builder) {
46 |
47 | }
48 |
49 | @Override
50 | public void injectAppLifecycle(Context context, List lifecycles) {
51 | // AppLifecycles 的所有方法都会在基类 Application 的对应的生命周期中被调用,所以在对应的方法中可以扩展一些自己需要的逻辑
52 | // 可以根据不同的逻辑添加多个实现类
53 | lifecycles.add(new AppLifecyclesImpl());
54 | }
55 |
56 | @Override
57 | public void injectActivityLifecycle(Context context, List lifecycles) {
58 |
59 | }
60 |
61 | @Override
62 | public void injectFragmentLifecycle(Context context, List lifecycles) {
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/app/ZhihuConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.app;
17 |
18 | /**
19 | * ================================================
20 | * Created by JessYan on 25/04/2018 16:48
21 | * Contact me
22 | * Follow me
23 | * ================================================
24 | */
25 | public interface ZhihuConstants {
26 | String DETAIL_ID = "detail_id";
27 | String DETAIL_TITLE = "detail_title";
28 | String ENCODING = "UTF-8";
29 | }
30 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/component/service/ZhihuInfoServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.component.service;
17 |
18 | import android.content.Context;
19 |
20 | import com.alibaba.android.arouter.facade.annotation.Route;
21 | import com.jess.arms.utils.ArmsUtils;
22 |
23 | import me.jessyan.armscomponent.commonsdk.core.RouterHub;
24 | import me.jessyan.armscomponent.commonservice.zhihu.bean.ZhihuInfo;
25 | import me.jessyan.armscomponent.commonservice.zhihu.service.ZhihuInfoService;
26 | import me.jessyan.armscomponent.zhihu.R;
27 |
28 | /**
29 | * ================================================
30 | * 向外提供服务的接口实现类, 在此类中实现一些具有特定功能的方法提供给外部, 即可让一个组件与其他组件或宿主进行交互
31 | *
32 | * @see CommonService wiki 官方文档
33 | * Created by JessYan on 2018/4/27 14:27
34 | * Contact me
35 | * Follow me
36 | * ================================================
37 | */
38 | @Route(path = RouterHub.ZHIHU_SERVICE_ZHIHUINFOSERVICE, name = "知乎信息服务")
39 | public class ZhihuInfoServiceImpl implements ZhihuInfoService {
40 | private Context mContext;
41 |
42 | @Override
43 | public ZhihuInfo getInfo() {
44 | return new ZhihuInfo(ArmsUtils.getString(mContext, R.string.public_name_zhihu));
45 | }
46 |
47 | @Override
48 | public void init(Context context) {
49 | mContext = context;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/di/component/DetailComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.di.component;
17 |
18 | import com.jess.arms.di.component.AppComponent;
19 | import com.jess.arms.di.scope.ActivityScope;
20 |
21 | import dagger.BindsInstance;
22 | import dagger.Component;
23 | import me.jessyan.armscomponent.zhihu.di.module.DetailModule;
24 | import me.jessyan.armscomponent.zhihu.mvp.contract.DetailContract;
25 | import me.jessyan.armscomponent.zhihu.mvp.ui.activity.DetailActivity;
26 |
27 | /**
28 | * ================================================
29 | * 展示 Component 的用法
30 | *
31 | * @see Component wiki 官方文档
32 | * Created by JessYan on 25/04/2018 11:17
33 | * Contact me
34 | * Follow me
35 | * ================================================
36 | */
37 | @ActivityScope
38 | @Component(modules = DetailModule.class, dependencies = AppComponent.class)
39 | public interface DetailComponent {
40 | void inject(DetailActivity activity);
41 | @Component.Builder
42 | interface Builder {
43 | @BindsInstance
44 | DetailComponent.Builder view(DetailContract.View view);
45 | DetailComponent.Builder appComponent(AppComponent appComponent);
46 | DetailComponent build();
47 | }
48 | }
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/di/component/ZhihuHomeComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.di.component;
17 |
18 | import com.jess.arms.di.component.AppComponent;
19 | import com.jess.arms.di.scope.ActivityScope;
20 |
21 | import dagger.BindsInstance;
22 | import dagger.Component;
23 | import me.jessyan.armscomponent.zhihu.di.module.ZhihuHomeModule;
24 | import me.jessyan.armscomponent.zhihu.mvp.contract.ZhihuHomeContract;
25 | import me.jessyan.armscomponent.zhihu.mvp.ui.activity.ZhihuHomeActivity;
26 |
27 | /**
28 | * ================================================
29 | * 展示 Component 的用法
30 | *
31 | * @see Component wiki 官方文档
32 | * Created by JessYan on 09/04/2016 11:17
33 | * Contact me
34 | * Follow me
35 | * ================================================
36 | */
37 | @ActivityScope
38 | @Component(modules = ZhihuHomeModule.class, dependencies = AppComponent.class)
39 | public interface ZhihuHomeComponent {
40 | void inject(ZhihuHomeActivity activity);
41 | @Component.Builder
42 | interface Builder {
43 | @BindsInstance
44 | ZhihuHomeComponent.Builder view(ZhihuHomeContract.View view);
45 | ZhihuHomeComponent.Builder appComponent(AppComponent appComponent);
46 | ZhihuHomeComponent build();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/di/module/DetailModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.di.module;
17 |
18 | import android.app.Dialog;
19 |
20 | import com.jess.arms.di.scope.ActivityScope;
21 |
22 | import dagger.Binds;
23 | import dagger.Module;
24 | import dagger.Provides;
25 | import me.jessyan.armscomponent.commonres.dialog.ProgresDialog;
26 | import me.jessyan.armscomponent.zhihu.mvp.contract.DetailContract;
27 | import me.jessyan.armscomponent.zhihu.mvp.model.ZhihuModel;
28 |
29 | /**
30 | * ================================================
31 | * 展示 Module 的用法
32 | *
33 | * @see Module wiki 官方文档
34 | * Created by JessYan on 25/04/2016 11:10
35 | * Contact me
36 | * Follow me
37 | * ================================================
38 | */
39 | @Module
40 | public abstract class DetailModule {
41 | @Binds
42 | abstract DetailContract.Model bindZhihuModel(ZhihuModel model);
43 |
44 | @ActivityScope
45 | @Provides
46 | static Dialog provideDialog(DetailContract.View view){
47 | return new ProgresDialog(view.getActivity());
48 | }
49 | }
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/mvp/contract/DetailContract.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.mvp.contract;
17 |
18 | import android.app.Activity;
19 |
20 | import com.jess.arms.mvp.IModel;
21 | import com.jess.arms.mvp.IView;
22 |
23 | import io.reactivex.Observable;
24 | import me.jessyan.armscomponent.zhihu.mvp.model.entity.ZhihuDetailBean;
25 |
26 | /**
27 | * ================================================
28 | * 展示 Contract 的用法
29 | *
30 | * @see Contract wiki 官方文档
31 | * Created by JessYan on 25/04/2016 10:47
32 | * Contact me
33 | * Follow me
34 | * ================================================
35 | */
36 | public interface DetailContract {
37 | //对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
38 | interface View extends IView {
39 | void shonContent(ZhihuDetailBean bean);
40 | Activity getActivity();
41 | }
42 |
43 | //Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
44 | interface Model extends IModel {
45 | Observable getDetailInfo(int id);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/mvp/contract/ZhihuHomeContract.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.mvp.contract;
17 |
18 | import android.app.Activity;
19 |
20 | import com.jess.arms.mvp.IModel;
21 | import com.jess.arms.mvp.IView;
22 |
23 | import io.reactivex.Observable;
24 | import me.jessyan.armscomponent.zhihu.mvp.model.entity.DailyListBean;
25 |
26 | /**
27 | * ================================================
28 | * 展示 Contract 的用法
29 | *
30 | * @see Contract wiki 官方文档
31 | * Created by JessYan on 09/04/2016 10:47
32 | * Contact me
33 | * Follow me
34 | * ================================================
35 | */
36 | public interface ZhihuHomeContract {
37 | //对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
38 | interface View extends IView {
39 | Activity getActivity();
40 | }
41 | //Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,如是否使用缓存
42 | interface Model extends IModel{
43 | Observable getDailyList();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/mvp/model/ZhihuModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.mvp.model;
17 |
18 | import com.jess.arms.di.scope.ActivityScope;
19 | import com.jess.arms.integration.IRepositoryManager;
20 | import com.jess.arms.mvp.BaseModel;
21 |
22 | import javax.inject.Inject;
23 |
24 | import io.reactivex.Observable;
25 | import me.jessyan.armscomponent.zhihu.mvp.contract.DetailContract;
26 | import me.jessyan.armscomponent.zhihu.mvp.contract.ZhihuHomeContract;
27 | import me.jessyan.armscomponent.zhihu.mvp.model.api.service.ZhihuService;
28 | import me.jessyan.armscomponent.zhihu.mvp.model.entity.DailyListBean;
29 | import me.jessyan.armscomponent.zhihu.mvp.model.entity.ZhihuDetailBean;
30 |
31 | /**
32 | * ================================================
33 | * 展示 Model 的用法
34 | *
35 | * @see Model wiki 官方文档
36 | * Created by JessYan on 09/04/2016 10:56
37 | * Contact me
38 | * Follow me
39 | * ================================================
40 | */
41 | @ActivityScope
42 | public class ZhihuModel extends BaseModel implements ZhihuHomeContract.Model, DetailContract.Model {
43 |
44 | @Inject
45 | public ZhihuModel(IRepositoryManager repositoryManager) {
46 | super(repositoryManager);
47 | }
48 |
49 | @Override
50 | public Observable getDailyList(){
51 | return mRepositoryManager.obtainRetrofitService(ZhihuService.class)
52 | .getDailyList();
53 | }
54 |
55 | @Override
56 | public Observable getDetailInfo(int id) {
57 | return mRepositoryManager.obtainRetrofitService(ZhihuService.class)
58 | .getDetailInfo(id);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/mvp/model/api/Api.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.mvp.model.api;
17 |
18 | /**
19 | * ================================================
20 | * 存放一些与 API 有关的东西,如请求地址,请求码等
21 | *
22 | * Created by JessYan on 08/05/2016 11:25
23 | * Contact me
24 | * Follow me
25 | * ================================================
26 | */
27 | public interface Api {
28 | String ZHIHU_DOMAIN_NAME = "zhihu";
29 | String ZHIHU_DOMAIN = "http://news-at.zhihu.com";
30 | }
31 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/mvp/model/api/service/ZhihuService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.mvp.model.api.service;
17 |
18 | import io.reactivex.Observable;
19 | import me.jessyan.armscomponent.zhihu.mvp.model.entity.DailyListBean;
20 | import me.jessyan.armscomponent.zhihu.mvp.model.entity.ZhihuDetailBean;
21 | import retrofit2.Retrofit;
22 | import retrofit2.http.GET;
23 | import retrofit2.http.Headers;
24 | import retrofit2.http.Path;
25 |
26 | import static me.jessyan.armscomponent.zhihu.mvp.model.api.Api.ZHIHU_DOMAIN_NAME;
27 | import static me.jessyan.retrofiturlmanager.RetrofitUrlManager.DOMAIN_NAME_HEADER;
28 |
29 | /**
30 | * ================================================
31 | * 展示 {@link Retrofit#create(Class)} 中需要传入的 ApiService 的使用方式
32 | * 存放关于 zhihu 的一些 API
33 | *
34 | * Created by JessYan on 08/05/2016 12:05
35 | * Contact me
36 | * Follow me
37 | * ================================================
38 | */
39 | public interface ZhihuService {
40 | /**
41 | * 最新日报
42 | */
43 | @Headers({DOMAIN_NAME_HEADER + ZHIHU_DOMAIN_NAME})
44 | @GET("/api/4/news/latest")
45 | Observable getDailyList();
46 |
47 | /**
48 | * 日报详情
49 | */
50 | @Headers({DOMAIN_NAME_HEADER + ZHIHU_DOMAIN_NAME})
51 | @GET("/api/4/news/{id}")
52 | Observable getDetailInfo(@Path("id") int id);
53 | }
54 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/mvp/ui/adapter/ZhihuHomeAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.mvp.ui.adapter;
17 |
18 | import android.view.View;
19 |
20 | import com.jess.arms.base.BaseHolder;
21 | import com.jess.arms.base.DefaultAdapter;
22 |
23 | import java.util.List;
24 |
25 | import me.jessyan.armscomponent.zhihu.R;
26 | import me.jessyan.armscomponent.zhihu.mvp.model.entity.DailyListBean;
27 | import me.jessyan.armscomponent.zhihu.mvp.ui.holder.ZhihuHomeItemHolder;
28 |
29 | /**
30 | * ================================================
31 | * 展示 {@link DefaultAdapter} 的用法
32 | *
33 | * Created by JessYan on 09/04/2016 12:57
34 | * Contact me
35 | * Follow me
36 | * ================================================
37 | */
38 | public class ZhihuHomeAdapter extends DefaultAdapter{
39 | public ZhihuHomeAdapter(List infos) {
40 | super(infos);
41 | }
42 |
43 | @Override
44 | public BaseHolder getHolder(View v, int viewType) {
45 | return new ZhihuHomeItemHolder(v);
46 | }
47 |
48 | @Override
49 | public int getLayoutId(int viewType) {
50 | return R.layout.zhihu_recycle_list;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/module/module_zhihu/src/main/java/me/jessyan/armscomponent/zhihu/mvp/ui/holder/ZhihuHomeItemHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package me.jessyan.armscomponent.zhihu.mvp.ui.holder;
17 |
18 | import android.view.View;
19 | import android.widget.ImageView;
20 | import android.widget.TextView;
21 |
22 | import com.jess.arms.base.BaseHolder;
23 | import com.jess.arms.di.component.AppComponent;
24 | import com.jess.arms.http.imageloader.ImageLoader;
25 | import com.jess.arms.utils.ArmsUtils;
26 |
27 | import butterknife.BindView;
28 | import io.reactivex.Observable;
29 | import me.jessyan.armscomponent.commonsdk.imgaEngine.config.CommonImageConfigImpl;
30 | import me.jessyan.armscomponent.zhihu.R2;
31 | import me.jessyan.armscomponent.zhihu.mvp.model.entity.DailyListBean;
32 |
33 | /**
34 | * ================================================
35 | * 展示 {@link BaseHolder} 的用法
36 | *