Commit 5cc69290e43f97c58abf159b04023441c9357804
1 parent
f1ce56b9bb
Exists in
master
登录到指定学生
Showing
3 changed files
with
41 additions
and
33 deletions
Show diff stats
app/build.gradle
1 | apply plugin: 'com.android.application' | 1 | apply plugin: 'com.android.application' |
2 | apply from: '../config.gradle' | 2 | apply from: '../config.gradle' |
3 | 3 | ||
4 | 4 | ||
5 | def androidId = rootProject.ext.androidId | 5 | def androidId = rootProject.ext.androidId |
6 | def support = rootProject.ext.dependencies | 6 | def support = rootProject.ext.dependencies |
7 | def url = rootProject.ext.url | 7 | def url = rootProject.ext.url |
8 | 8 | ||
9 | 9 | ||
10 | android { | 10 | android { |
11 | signingConfigs { | 11 | signingConfigs { |
12 | 12 | ||
13 | config { | 13 | config { |
14 | keyAlias 'alias' | 14 | keyAlias 'alias' |
15 | keyPassword '123456' | 15 | keyPassword '123456' |
16 | storeFile file('key.jks') | 16 | storeFile file('key.jks') |
17 | storePassword '123456' | 17 | storePassword '123456' |
18 | } | 18 | } |
19 | debug { | 19 | debug { |
20 | } | 20 | } |
21 | } | 21 | } |
22 | compileSdk 32 | 22 | compileSdk 32 |
23 | 23 | ||
24 | defaultConfig { | 24 | defaultConfig { |
25 | applicationId "com.hjx.parent" | 25 | applicationId "com.hjx.parent" |
26 | minSdk 24 | 26 | minSdk 24 |
27 | targetSdk 32 | 27 | targetSdk 32 |
28 | versionCode 1004 | 28 | versionCode 1005 |
29 | versionName "1.0.0.4" | 29 | versionName "1.0.0.5" |
30 | 30 | ||
31 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | 31 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
32 | } | 32 | } |
33 | 33 | ||
34 | android.applicationVariants.all { | 34 | android.applicationVariants.all { |
35 | variant -> | 35 | variant -> |
36 | variant.outputs.all { | 36 | variant.outputs.all { |
37 | //在这里修改apk文件名 | 37 | //在这里修改apk文件名 |
38 | outputFileName = "parent-${variant.name}-v${variant.versionName}.apk" | 38 | outputFileName = "parent-${variant.name}-v${variant.versionName}.apk" |
39 | } | 39 | } |
40 | } | 40 | } |
41 | buildTypes { | 41 | buildTypes { |
42 | debug { | 42 | debug { |
43 | debuggable true | 43 | debuggable true |
44 | minifyEnabled false | 44 | minifyEnabled false |
45 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 45 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
46 | signingConfig signingConfigs.config | 46 | signingConfig signingConfigs.config |
47 | } | 47 | } |
48 | release { | 48 | release { |
49 | debuggable true | 49 | debuggable true |
50 | minifyEnabled false | 50 | minifyEnabled false |
51 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 51 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
52 | signingConfig signingConfigs.config | 52 | signingConfig signingConfigs.config |
53 | } | 53 | } |
54 | } | 54 | } |
55 | lintOptions { | 55 | lintOptions { |
56 | checkReleaseBuilds false | 56 | checkReleaseBuilds false |
57 | abortOnError false | 57 | abortOnError false |
58 | } | 58 | } |
59 | buildFeatures { | 59 | buildFeatures { |
60 | viewBinding true | 60 | viewBinding true |
61 | } | 61 | } |
62 | compileOptions { | 62 | compileOptions { |
63 | sourceCompatibility JavaVersion.VERSION_1_8 | 63 | sourceCompatibility JavaVersion.VERSION_1_8 |
64 | targetCompatibility JavaVersion.VERSION_1_8 | 64 | targetCompatibility JavaVersion.VERSION_1_8 |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | dependencies { | 68 | dependencies { |
69 | support.each { k, v -> implementation v } | 69 | support.each { k, v -> implementation v } |
70 | api project(path: ':libs:common') | 70 | api project(path: ':libs:common') |
71 | implementation 'androidx.appcompat:appcompat:1.5.1' | 71 | implementation 'androidx.appcompat:appcompat:1.5.1' |
72 | implementation 'com.google.android.material:material:1.6.1' | 72 | implementation 'com.google.android.material:material:1.6.1' |
73 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | 73 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' |
74 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50' | 74 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50' |
75 | implementation 'com.github.ForgetAll:LoadingDialog:1.1.2' | 75 | implementation 'com.github.ForgetAll:LoadingDialog:1.1.2' |
76 | implementation 'com.github.DL-ZhangTeng:ImagePicker:1.5.0' | 76 | implementation 'com.github.DL-ZhangTeng:ImagePicker:1.5.0' |
77 | //使用的三方 | 77 | //使用的三方 |
78 | implementation 'com.yalantis:ucrop:2.2.0' | 78 | implementation 'com.yalantis:ucrop:2.2.0' |
79 | implementation 'com.github.DL-ZhangTeng:RequestPermission:1.3.0' | 79 | implementation 'com.github.DL-ZhangTeng:RequestPermission:1.3.0' |
80 | implementation 'com.github.DL-ZhangTeng:Utils:2.2.0' | 80 | implementation 'com.github.DL-ZhangTeng:Utils:2.2.0' |
81 | } | 81 | } |
app/src/main/java/com/hjx/parent/QRActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.graphics.Bitmap; | 3 | import android.graphics.Bitmap; |
4 | import android.widget.Toast; | 4 | import android.widget.Toast; |
5 | 5 | ||
6 | import com.google.gson.Gson; | 6 | import com.google.gson.Gson; |
7 | import com.hjx.parent.bean.RegisterBean; | 7 | import com.hjx.parent.bean.RegisterBean; |
8 | import com.hjx.parent.bean.StudentBean; | ||
8 | import com.prws.common.base.BaseActivity; | 9 | import com.prws.common.base.BaseActivity; |
9 | import com.prws.common.base.BasePresenter; | 10 | import com.prws.common.base.BasePresenter; |
10 | import com.prws.common.net.NetWorks; | 11 | import com.prws.common.net.NetWorks; |
11 | import com.prws.common.utils.LogUtil; | 12 | import com.prws.common.utils.LogUtil; |
12 | import com.prws.common.utils.SharedPreferencesUtil; | 13 | import com.prws.common.utils.SharedPreferencesUtil; |
13 | import com.uuzuche.lib_zxing.activity.CaptureFragment; | 14 | import com.uuzuche.lib_zxing.activity.CaptureFragment; |
14 | import com.uuzuche.lib_zxing.activity.CodeUtils; | 15 | import com.uuzuche.lib_zxing.activity.CodeUtils; |
15 | 16 | ||
16 | import org.json.JSONObject; | 17 | import org.json.JSONObject; |
17 | 18 | ||
18 | import java.io.IOException; | 19 | import java.io.IOException; |
19 | 20 | ||
20 | import io.reactivex.Observer; | 21 | import io.reactivex.Observer; |
21 | import io.reactivex.disposables.Disposable; | 22 | import io.reactivex.disposables.Disposable; |
22 | import okhttp3.ResponseBody; | 23 | import okhttp3.ResponseBody; |
23 | 24 | ||
24 | public class QRActivity extends BaseActivity { | 25 | public class QRActivity extends BaseActivity { |
25 | @Override | 26 | @Override |
26 | protected int layoutResId() { | 27 | protected int layoutResId() { |
27 | return R.layout.activity_qr; | 28 | return R.layout.activity_qr; |
28 | } | 29 | } |
29 | 30 | ||
30 | @Override | 31 | @Override |
31 | public Object getContract() { | 32 | public Object getContract() { |
32 | return null; | 33 | return null; |
33 | } | 34 | } |
34 | 35 | ||
35 | @Override | 36 | @Override |
36 | public BasePresenter getPresenter() { | 37 | public BasePresenter getPresenter() { |
37 | return null; | 38 | return null; |
38 | } | 39 | } |
39 | 40 | ||
40 | @Override | 41 | @Override |
41 | protected void initView() { | 42 | protected void initView() { |
42 | 43 | ||
43 | findViewById(R.id.iv_back).setOnClickListener(view -> startActivity(MainActivity.class)); | 44 | findViewById(R.id.iv_back).setOnClickListener(view -> startActivity(MainActivity.class)); |
44 | 45 | ||
45 | CaptureFragment captureFragment = new CaptureFragment(); | 46 | CaptureFragment captureFragment = new CaptureFragment(); |
46 | 47 | ||
47 | captureFragment.setAnalyzeCallback(new CodeUtils.AnalyzeCallback() { | 48 | captureFragment.setAnalyzeCallback(new CodeUtils.AnalyzeCallback() { |
48 | @Override | 49 | @Override |
49 | public void onAnalyzeSuccess(Bitmap mBitmap, String result) { | 50 | public void onAnalyzeSuccess(Bitmap mBitmap, String result) { |
50 | LogUtil.e(TAG, "result----:" + result); | 51 | LogUtil.e(TAG, "result----:" + result); |
51 | 52 | ||
52 | loginAnd(result); | 53 | loginAnd(result); |
53 | 54 | ||
54 | } | 55 | } |
55 | 56 | ||
56 | @Override | 57 | @Override |
57 | public void onAnalyzeFailed() { | 58 | public void onAnalyzeFailed() { |
58 | 59 | ||
59 | } | 60 | } |
60 | }); | 61 | }); |
61 | 62 | ||
62 | 63 | ||
63 | getSupportFragmentManager().beginTransaction().replace(R.id.rl_content, captureFragment).commit(); | 64 | getSupportFragmentManager().beginTransaction().replace(R.id.rl_content, captureFragment).commit(); |
64 | 65 | ||
65 | 66 | ||
66 | } | 67 | } |
67 | 68 | ||
68 | public void loginAnd(String str) { | 69 | public void loginAnd(String str) { |
69 | NetWorks.scanAndLogin(str, new Observer<ResponseBody>() { | 70 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
70 | @Override | 71 | try { |
71 | public void onSubscribe(Disposable d) { | 72 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); |
72 | 73 | ||
73 | } | 74 | NetWorks.scanAndLogin(str, studentBean.getStuId(), new Observer<ResponseBody>() { |
75 | @Override | ||
76 | public void onSubscribe(Disposable d) { | ||
74 | 77 | ||
75 | @Override | 78 | } |
76 | public void onNext(ResponseBody responseBody) { | 79 | |
77 | try { | 80 | @Override |
78 | 81 | public void onNext(ResponseBody responseBody) { | |
79 | String str = responseBody.string().toString(); | 82 | try { |
80 | LogUtil.e(TAG, "----" + str); | 83 | |
81 | JSONObject jo = new JSONObject(str); | 84 | String str = responseBody.string().toString(); |
82 | boolean isSucceed = jo.getBoolean("success"); | 85 | LogUtil.e(TAG, "----" + str); |
83 | if (isSucceed) { | 86 | JSONObject jo = new JSONObject(str); |
87 | boolean isSucceed = jo.getBoolean("success"); | ||
88 | if (isSucceed) { | ||
89 | startActivity(MainActivity.class); | ||
90 | finish(); | ||
91 | } else { | ||
92 | Toast.makeText(QRActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); | ||
93 | } | ||
94 | } catch (Exception e) { | ||
95 | e.printStackTrace(); | ||
96 | Toast.makeText(QRActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); | ||
84 | startActivity(MainActivity.class); | 97 | startActivity(MainActivity.class); |
85 | finish(); | ||
86 | } else { | ||
87 | Toast.makeText(QRActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); | ||
88 | } | 98 | } |
89 | } catch (Exception e) { | ||
90 | e.printStackTrace(); | ||
91 | Toast.makeText(QRActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); | ||
92 | startActivity(MainActivity.class); | ||
93 | } | 99 | } |
94 | } | ||
95 | 100 | ||
96 | @Override | 101 | @Override |
97 | public void onError(Throwable e) { | 102 | public void onError(Throwable e) { |
98 | 103 | ||
99 | } | 104 | } |
100 | 105 | ||
101 | @Override | 106 | @Override |
102 | public void onComplete() { | 107 | public void onComplete() { |
103 | 108 | ||
104 | } | 109 | } |
105 | }); | 110 | }); |
111 | } catch (Exception e) { | ||
112 | |||
113 | } | ||
106 | } | 114 | } |
107 | 115 | ||
108 | @Override | 116 | @Override |
109 | protected void initListener() { | 117 | protected void initListener() { |
110 | 118 | ||
111 | } | 119 | } |
112 | 120 | ||
113 | @Override | 121 | @Override |
114 | protected void initData() { | 122 | protected void initData() { |
115 | 123 |
libs/common/src/main/java/com/prws/common/net/NetWorks.java
1 | package com.prws.common.net; | 1 | package com.prws.common.net; |
2 | 2 | ||
3 | 3 | ||
4 | import com.google.gson.Gson; | 4 | import com.google.gson.Gson; |
5 | import com.google.gson.JsonObject; | 5 | import com.google.gson.JsonObject; |
6 | import com.prws.common.BuildConfig; | 6 | import com.prws.common.BuildConfig; |
7 | import com.prws.common.bean.BaseEntity; | 7 | import com.prws.common.bean.BaseEntity; |
8 | import com.prws.common.bean.CutPicBean; | 8 | import com.prws.common.bean.CutPicBean; |
9 | import com.prws.common.bean.GradeAndSubject; | 9 | import com.prws.common.bean.GradeAndSubject; |
10 | import com.prws.common.bean.PageInfo; | 10 | import com.prws.common.bean.PageInfo; |
11 | import com.prws.common.bean.ResponseResult; | 11 | import com.prws.common.bean.ResponseResult; |
12 | import com.prws.common.bean.ScheduleBean; | 12 | import com.prws.common.bean.ScheduleBean; |
13 | import com.prws.common.bean.Teacher; | 13 | import com.prws.common.bean.Teacher; |
14 | import com.prws.common.bean.TopicBean; | 14 | import com.prws.common.bean.TopicBean; |
15 | import com.prws.common.bean.UpdateBean; | 15 | import com.prws.common.bean.UpdateBean; |
16 | import com.prws.common.utils.SharedPreferencesUtil; | 16 | import com.prws.common.utils.SharedPreferencesUtil; |
17 | 17 | ||
18 | import java.io.File; | 18 | import java.io.File; |
19 | import java.util.HashMap; | 19 | import java.util.HashMap; |
20 | import java.util.List; | 20 | import java.util.List; |
21 | import java.util.Map; | 21 | import java.util.Map; |
22 | 22 | ||
23 | import io.reactivex.Observable; | 23 | import io.reactivex.Observable; |
24 | import io.reactivex.Observer; | 24 | import io.reactivex.Observer; |
25 | import io.reactivex.android.schedulers.AndroidSchedulers; | 25 | import io.reactivex.android.schedulers.AndroidSchedulers; |
26 | import io.reactivex.schedulers.Schedulers; | 26 | import io.reactivex.schedulers.Schedulers; |
27 | import okhttp3.MediaType; | 27 | import okhttp3.MediaType; |
28 | import okhttp3.MultipartBody; | 28 | import okhttp3.MultipartBody; |
29 | import okhttp3.RequestBody; | 29 | import okhttp3.RequestBody; |
30 | import okhttp3.ResponseBody; | 30 | import okhttp3.ResponseBody; |
31 | import retrofit2.Call; | 31 | import retrofit2.Call; |
32 | import retrofit2.Callback; | 32 | import retrofit2.Callback; |
33 | import retrofit2.http.Body; | 33 | import retrofit2.http.Body; |
34 | import retrofit2.http.DELETE; | 34 | import retrofit2.http.DELETE; |
35 | import retrofit2.http.FieldMap; | 35 | import retrofit2.http.FieldMap; |
36 | import retrofit2.http.FormUrlEncoded; | 36 | import retrofit2.http.FormUrlEncoded; |
37 | import retrofit2.http.GET; | 37 | import retrofit2.http.GET; |
38 | import retrofit2.http.Header; | 38 | import retrofit2.http.Header; |
39 | import retrofit2.http.HeaderMap; | 39 | import retrofit2.http.HeaderMap; |
40 | import retrofit2.http.Headers; | 40 | import retrofit2.http.Headers; |
41 | import retrofit2.http.Multipart; | 41 | import retrofit2.http.Multipart; |
42 | import retrofit2.http.POST; | 42 | import retrofit2.http.POST; |
43 | import retrofit2.http.PUT; | 43 | import retrofit2.http.PUT; |
44 | import retrofit2.http.Part; | 44 | import retrofit2.http.Part; |
45 | import retrofit2.http.PartMap; | 45 | import retrofit2.http.PartMap; |
46 | import retrofit2.http.Path; | 46 | import retrofit2.http.Path; |
47 | import retrofit2.http.Query; | 47 | import retrofit2.http.Query; |
48 | import retrofit2.http.QueryMap; | 48 | import retrofit2.http.QueryMap; |
49 | import retrofit2.http.Streaming; | 49 | import retrofit2.http.Streaming; |
50 | import retrofit2.http.Url; | 50 | import retrofit2.http.Url; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * 类名称:NetWorks | 53 | * 类名称:NetWorks |
54 | * 创建人: | 54 | * 创建人: |
55 | * <p> | 55 | * <p> |
56 | * 类描述:网络请求的操作类 | 56 | * 类描述:网络请求的操作类 |
57 | */ | 57 | */ |
58 | public class NetWorks extends RetrofitUtils { | 58 | public class NetWorks extends RetrofitUtils { |
59 | //服务器路径 | 59 | //服务器路径 |
60 | public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); | 60 | public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); |
61 | 61 | ||
62 | //设缓存有效期为1天 | 62 | //设缓存有效期为1天 |
63 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; | 63 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; |
64 | //查询缓存的Cache-Control设置,使用缓存 | 64 | //查询缓存的Cache-Control设置,使用缓存 |
65 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; | 65 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; |
66 | //查询网络的Cache-Control设置。不使用缓存 | 66 | //查询网络的Cache-Control设置。不使用缓存 |
67 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; | 67 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; |
68 | 68 | ||
69 | 69 | ||
70 | private interface NetService { | 70 | private interface NetService { |
71 | 71 | ||
72 | 72 | ||
73 | @GET("/api/v1/user/logout") | 73 | @GET("/api/v1/user/logout") |
74 | Observable<ResponseBody> logout(); | 74 | Observable<ResponseBody> logout(); |
75 | 75 | ||
76 | @Multipart | 76 | @Multipart |
77 | @POST("/api/v1/user/upLoadAvatar") | 77 | @POST("/api/v1/user/upLoadAvatar") |
78 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); | 78 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); |
79 | 79 | ||
80 | 80 | ||
81 | @Headers("Content-Type: application/json") | 81 | @Headers("Content-Type: application/json") |
82 | @POST("/api/v1/user/editUser") | 82 | @POST("/api/v1/user/editUser") |
83 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); | 83 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); |
84 | 84 | ||
85 | @Headers("Content-Type: application/json") | 85 | @Headers("Content-Type: application/json") |
86 | @POST("/api/v1/user/changePassword") | 86 | @POST("/api/v1/user/changePassword") |
87 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); | 87 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); |
88 | 88 | ||
89 | 89 | ||
90 | @GET("/api/v1/user/searchById") | 90 | @GET("/api/v1/user/searchById") |
91 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); | 91 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); |
92 | 92 | ||
93 | 93 | ||
94 | @Headers("Content-Type: application/json") | 94 | @Headers("Content-Type: application/json") |
95 | @POST("/api/v1/auth/login") | 95 | @POST("/api/v1/auth/login") |
96 | Observable<ResponseBody> login(@Body RequestBody body); | 96 | Observable<ResponseBody> login(@Body RequestBody body); |
97 | 97 | ||
98 | @GET("/api/v1/resource/listGradeAndSubject") | 98 | @GET("/api/v1/resource/listGradeAndSubject") |
99 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); | 99 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); |
100 | 100 | ||
101 | 101 | ||
102 | @GET("/api/v1/manager/generalQrCode") | 102 | @GET("/api/v1/manager/generalQrCode") |
103 | Observable<ResponseBody> generalQrCode(); | 103 | Observable<ResponseBody> generalQrCode(); |
104 | 104 | ||
105 | @GET("/api/v1/parent/scanAndLogin?") | 105 | @GET("/api/v1/parent/scanAndLogin?") |
106 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code); | 106 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); |
107 | 107 | ||
108 | @GET("/api/v1/parent/getChildrenList") | 108 | @GET("/api/v1/parent/getChildrenList") |
109 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); | 109 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); |
110 | 110 | ||
111 | 111 | ||
112 | @Headers("Content-Type: application/json") | 112 | @Headers("Content-Type: application/json") |
113 | @POST("/api/v1/parent/registerParent") | 113 | @POST("/api/v1/parent/registerParent") |
114 | Observable<ResponseBody> registerParent(@Body RequestBody body); | 114 | Observable<ResponseBody> registerParent(@Body RequestBody body); |
115 | 115 | ||
116 | 116 | ||
117 | @GET("/api/v1/parent/listChildren") | 117 | @GET("/api/v1/parent/listChildren") |
118 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); | 118 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); |
119 | 119 | ||
120 | 120 | ||
121 | @Headers("Content-Type: application/json") | 121 | @Headers("Content-Type: application/json") |
122 | @POST("/api/v1/parent/registerStudent") | 122 | @POST("/api/v1/parent/registerStudent") |
123 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); | 123 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); |
124 | 124 | ||
125 | @Headers("Content-Type: application/json") | 125 | @Headers("Content-Type: application/json") |
126 | @POST("/api/v1/parent/bindTeacher") | 126 | @POST("/api/v1/parent/bindTeacher") |
127 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); | 127 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); |
128 | 128 | ||
129 | @Multipart | 129 | @Multipart |
130 | @POST("/api/v1/user/upLoadAvatar") | 130 | @POST("/api/v1/user/upLoadAvatar") |
131 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); | 131 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); |
132 | 132 | ||
133 | 133 | ||
134 | @Multipart | 134 | @Multipart |
135 | @POST("/api/v1/student/editStudentAvatar") | 135 | @POST("/api/v1/student/editStudentAvatar") |
136 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 136 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
137 | 137 | ||
138 | @Headers("Content-Type: application/json") | 138 | @Headers("Content-Type: application/json") |
139 | @POST("/api/v1/parent/editChild") | 139 | @POST("/api/v1/parent/editChild") |
140 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); | 140 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); |
141 | 141 | ||
142 | @GET("/api/v1/student/getStudyPlanForThisWeek") | 142 | @GET("/api/v1/student/getStudyPlanForThisWeek") |
143 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); | 143 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); |
144 | 144 | ||
145 | @GET("api/v1/parent/searchTeacher") | 145 | @GET("api/v1/parent/searchTeacher") |
146 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); | 146 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); |
147 | 147 | ||
148 | @POST("api/v1/question/listErrorBook") | 148 | @POST("api/v1/question/listErrorBook") |
149 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); | 149 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); |
150 | 150 | ||
151 | @POST | 151 | @POST |
152 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); | 152 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); |
153 | 153 | ||
154 | @POST | 154 | @POST |
155 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); | 155 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); |
156 | 156 | ||
157 | @POST | 157 | @POST |
158 | Observable<JsonObject> getBaiduToken(@Url String url); | 158 | Observable<JsonObject> getBaiduToken(@Url String url); |
159 | 159 | ||
160 | @Multipart | 160 | @Multipart |
161 | @POST("api/v1/pad/addErrorBook") | 161 | @POST("api/v1/pad/addErrorBook") |
162 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 162 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
163 | 163 | ||
164 | @POST("api/v1/pad/deleteStuErrorBook") | 164 | @POST("api/v1/pad/deleteStuErrorBook") |
165 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); | 165 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); |
166 | 166 | ||
167 | @PUT("api/v1/pad/updateStuErrorBookInfo") | 167 | @PUT("api/v1/pad/updateStuErrorBookInfo") |
168 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); | 168 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); |
169 | 169 | ||
170 | @POST("api/v1/question/editErrorBook") | 170 | @POST("api/v1/question/editErrorBook") |
171 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); | 171 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); |
172 | 172 | ||
173 | @GET("api/v1/resource/checkUpdate") | 173 | @GET("api/v1/resource/checkUpdate") |
174 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); | 174 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); |
175 | 175 | ||
176 | @GET("api/v1/teacher/getStudentList") | 176 | @GET("api/v1/teacher/getStudentList") |
177 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); | 177 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); |
178 | 178 | ||
179 | @GET("api/v1/answer/listRecordForTeacher") | 179 | @GET("api/v1/answer/listRecordForTeacher") |
180 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); | 180 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | public static String getHeader() { | 184 | public static String getHeader() { |
185 | return (String) SharedPreferencesUtil.getData("token", ""); | 185 | return (String) SharedPreferencesUtil.getData("token", ""); |
186 | } | 186 | } |
187 | 187 | ||
188 | public static String getBaiduToken() { | 188 | public static String getBaiduToken() { |
189 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); | 189 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); |
190 | } | 190 | } |
191 | 191 | ||
192 | 192 | ||
193 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { | 193 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { |
194 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); | 194 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); |
195 | } | 195 | } |
196 | 196 | ||
197 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { | 197 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { |
198 | File file = new File(path); | 198 | File file = new File(path); |
199 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 199 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
200 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 200 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
201 | Map<String, Object> map = new HashMap<>(); | 201 | Map<String, Object> map = new HashMap<>(); |
202 | map.put("condition", param); | 202 | map.put("condition", param); |
203 | setSubscribe(service_url.addError(part, map), observer); | 203 | setSubscribe(service_url.addError(part, map), observer); |
204 | } | 204 | } |
205 | 205 | ||
206 | 206 | ||
207 | public static void cut(String base64, Observer<CutPicBean> observer) { | 207 | public static void cut(String base64, Observer<CutPicBean> observer) { |
208 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 208 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
209 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); | 209 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); |
210 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); | 210 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); |
211 | } | 211 | } |
212 | 212 | ||
213 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { | 213 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { |
214 | setSubscribe(service_url.editError(getHeader(), map), observer); | 214 | setSubscribe(service_url.editError(getHeader(), map), observer); |
215 | } | 215 | } |
216 | 216 | ||
217 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { | 217 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { |
218 | setSubscribe(service_url.updateError(getHeader(), map), observer); | 218 | setSubscribe(service_url.updateError(getHeader(), map), observer); |
219 | } | 219 | } |
220 | 220 | ||
221 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { | 221 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { |
222 | setSubscribe(service_url.deleteError(getHeader(), map), observer); | 222 | setSubscribe(service_url.deleteError(getHeader(), map), observer); |
223 | } | 223 | } |
224 | 224 | ||
225 | public static void getBaiduToken(Observer<JsonObject> observer) { | 225 | public static void getBaiduToken(Observer<JsonObject> observer) { |
226 | setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer); | 226 | setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer); |
227 | } | 227 | } |
228 | 228 | ||
229 | public static void removeWriting(String base64, Observer<JsonObject> observer) { | 229 | public static void removeWriting(String base64, Observer<JsonObject> observer) { |
230 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 230 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
231 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); | 231 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); |
232 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); | 232 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); |
233 | } | 233 | } |
234 | 234 | ||
235 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { | 235 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { |
236 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); | 236 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); |
237 | } | 237 | } |
238 | 238 | ||
239 | public static void logout(Observer<ResponseBody> observer) { | 239 | public static void logout(Observer<ResponseBody> observer) { |
240 | setSubscribe(service_url.logout(), observer); | 240 | setSubscribe(service_url.logout(), observer); |
241 | } | 241 | } |
242 | 242 | ||
243 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { | 243 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { |
244 | setSubscribe(service_url.editStudent(getHeader(), body), observable); | 244 | setSubscribe(service_url.editStudent(getHeader(), body), observable); |
245 | } | 245 | } |
246 | 246 | ||
247 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { | 247 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { |
248 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); | 248 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); |
249 | } | 249 | } |
250 | 250 | ||
251 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { | 251 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { |
252 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 252 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
253 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 253 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
254 | Map<String, Object> map = new HashMap<>(); | 254 | Map<String, Object> map = new HashMap<>(); |
255 | map.put("stuId", stuId); | 255 | map.put("stuId", stuId); |
256 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); | 256 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); |
257 | } | 257 | } |
258 | 258 | ||
259 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { | 259 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { |
260 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 260 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
261 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 261 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
262 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); | 262 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); |
263 | } | 263 | } |
264 | 264 | ||
265 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { | 265 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { |
266 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); | 266 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); |
267 | } | 267 | } |
268 | 268 | ||
269 | 269 | ||
270 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { | 270 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { |
271 | setSubscribe(service_url.editUser(getHeader(), body), observer); | 271 | setSubscribe(service_url.editUser(getHeader(), body), observer); |
272 | } | 272 | } |
273 | 273 | ||
274 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { | 274 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { |
275 | setSubscribe(service_url.changePassword(getHeader(), body), observer); | 275 | setSubscribe(service_url.changePassword(getHeader(), body), observer); |
276 | } | 276 | } |
277 | 277 | ||
278 | 278 | ||
279 | public static void searchById(String userId, Observer<ResponseBody> observer) { | 279 | public static void searchById(String userId, Observer<ResponseBody> observer) { |
280 | setSubscribe(service_url.searchById(getHeader(), userId), observer); | 280 | setSubscribe(service_url.searchById(getHeader(), userId), observer); |
281 | } | 281 | } |
282 | 282 | ||
283 | 283 | ||
284 | public static void login(RequestBody body, Observer<ResponseBody> observer) { | 284 | public static void login(RequestBody body, Observer<ResponseBody> observer) { |
285 | setSubscribe(service_url.login(body), observer); | 285 | setSubscribe(service_url.login(body), observer); |
286 | } | 286 | } |
287 | 287 | ||
288 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { | 288 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { |
289 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); | 289 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); |
290 | } | 290 | } |
291 | 291 | ||
292 | 292 | ||
293 | public static void scanAndLogin(String code, Observer<ResponseBody> observer) { | 293 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { |
294 | setSubscribe(service_url.scanAndLogin(getHeader(), code), observer); | 294 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); |
295 | } | 295 | } |
296 | 296 | ||
297 | public static void getChildrenList(Observer<ResponseBody> observer) { | 297 | public static void getChildrenList(Observer<ResponseBody> observer) { |
298 | setSubscribe(service_url.getChildrenList(getHeader()), observer); | 298 | setSubscribe(service_url.getChildrenList(getHeader()), observer); |
299 | } | 299 | } |
300 | 300 | ||
301 | 301 | ||
302 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { | 302 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { |
303 | setSubscribe(service_url.registerParent(body), observer); | 303 | setSubscribe(service_url.registerParent(body), observer); |
304 | } | 304 | } |
305 | 305 | ||
306 | 306 | ||
307 | public static void listChildren(Observer<ResponseBody> observer) { | 307 | public static void listChildren(Observer<ResponseBody> observer) { |
308 | setSubscribe(service_url.listChildren(getHeader()), observer); | 308 | setSubscribe(service_url.listChildren(getHeader()), observer); |
309 | } | 309 | } |
310 | 310 | ||
311 | public static void listStudent(Observer<ResponseBody> observer) { | 311 | public static void listStudent(Observer<ResponseBody> observer) { |
312 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 312 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
313 | } | 313 | } |
314 | 314 | ||
315 | public static void listRecord(Observer<ResponseBody> observer) { | 315 | public static void listRecord(Observer<ResponseBody> observer) { |
316 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 316 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
317 | } | 317 | } |
318 | 318 | ||
319 | 319 | ||
320 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { | 320 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { |
321 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); | 321 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); |
322 | } | 322 | } |
323 | 323 | ||
324 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { | 324 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { |
325 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); | 325 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); |
326 | } | 326 | } |
327 | 327 | ||
328 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { | 328 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { |
329 | setSubscribe(service_url.getError(getHeader(), map), observer); | 329 | setSubscribe(service_url.getError(getHeader(), map), observer); |
330 | } | 330 | } |
331 | 331 | ||
332 | 332 | ||
333 | public static RequestBody getMapRequestBody(Map map) { | 333 | public static RequestBody getMapRequestBody(Map map) { |
334 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); | 334 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); |
335 | } | 335 | } |
336 | 336 | ||
337 | 337 | ||
338 | public static RequestBody getArrayRequestBody(List list) { | 338 | public static RequestBody getArrayRequestBody(List list) { |
339 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); | 339 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); |
340 | } | 340 | } |
341 | 341 | ||
342 | public static RequestBody getFileRequestBody(File file) { | 342 | public static RequestBody getFileRequestBody(File file) { |
343 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); | 343 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); |
344 | } | 344 | } |
345 | 345 | ||
346 | public static RequestBody getFileRequestBody(byte[] bytes) { | 346 | public static RequestBody getFileRequestBody(byte[] bytes) { |
347 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); | 347 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); |
348 | } | 348 | } |
349 | 349 | ||
350 | public static RequestBody getObjectRequestBody(Object obj) { | 350 | public static RequestBody getObjectRequestBody(Object obj) { |
351 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); | 351 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); |
352 | } | 352 | } |
353 | 353 | ||
354 | public static RequestBody getStringRequestBody(String str) { | 354 | public static RequestBody getStringRequestBody(String str) { |
355 | return RequestBody.create(MediaType.parse("text/plain"), str); | 355 | return RequestBody.create(MediaType.parse("text/plain"), str); |
356 | } | 356 | } |
357 | 357 | ||
358 | 358 | ||
359 | /** | 359 | /** |
360 | * 插入观察者 | 360 | * 插入观察者 |
361 | * | 361 | * |
362 | * @param observable | 362 | * @param observable |
363 | * @param observer | 363 | * @param observer |
364 | * @param <T> | 364 | * @param <T> |
365 | */ | 365 | */ |
366 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { | 366 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { |
367 | observable.subscribeOn(Schedulers.io())//子线程访问网络 | 367 | observable.subscribeOn(Schedulers.io())//子线程访问网络 |
368 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 | 368 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 |
369 | .subscribe(observer); | 369 | .subscribe(observer); |
370 | } | 370 | } |
371 | 371 | ||
372 | } | 372 | } |
373 | 373 |