Compare View
Commits (2)
Showing
3 changed files
Show diff stats
app/build.gradle
1 | apply plugin: 'com.android.application' | 1 | apply plugin: 'com.android.application' |
2 | 2 | ||
3 | 3 | ||
4 | def androidId = rootProject.ext.androidId | 4 | def androidId = rootProject.ext.androidId |
5 | def support = rootProject.ext.dependencies | 5 | def support = rootProject.ext.dependencies |
6 | def url = rootProject.ext.url | 6 | def url = rootProject.ext.url |
7 | 7 | ||
8 | 8 | ||
9 | android { | 9 | android { |
10 | signingConfigs { | 10 | signingConfigs { |
11 | 11 | ||
12 | config { | 12 | config { |
13 | keyAlias 'alias' | 13 | keyAlias 'alias' |
14 | keyPassword '123456' | 14 | keyPassword '123456' |
15 | storeFile file('key.jks') | 15 | storeFile file('key.jks') |
16 | storePassword '123456' | 16 | storePassword '123456' |
17 | } | 17 | } |
18 | debug { | 18 | debug { |
19 | } | 19 | } |
20 | } | 20 | } |
21 | compileSdk 32 | 21 | compileSdk 32 |
22 | 22 | ||
23 | defaultConfig { | 23 | defaultConfig { |
24 | applicationId "com.hjx.parent" | 24 | applicationId "com.hjx.parent" |
25 | minSdk 26 | 25 | minSdk 26 |
26 | targetSdk 32 | 26 | targetSdk 32 |
27 | versionCode 1010 | 27 | versionCode 1011 |
28 | versionName "1.0.10" | 28 | versionName "1.0.11" |
29 | 29 | ||
30 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | 30 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
31 | } | 31 | } |
32 | 32 | ||
33 | android.applicationVariants.all { | 33 | android.applicationVariants.all { |
34 | variant -> | 34 | variant -> |
35 | variant.outputs.all { | 35 | variant.outputs.all { |
36 | //在这里修改apk文件名 | 36 | //在这里修改apk文件名 |
37 | outputFileName = "parent-${variant.name}-v${variant.versionName}.apk" | 37 | outputFileName = "parent-${variant.name}-v${variant.versionName}.apk" |
38 | } | 38 | } |
39 | } | 39 | } |
40 | buildTypes { | 40 | buildTypes { |
41 | debug { | 41 | debug { |
42 | debuggable true | 42 | debuggable true |
43 | minifyEnabled false | 43 | minifyEnabled false |
44 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 44 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
45 | signingConfig signingConfigs.config | 45 | signingConfig signingConfigs.config |
46 | } | 46 | } |
47 | release { | 47 | release { |
48 | debuggable true | 48 | debuggable true |
49 | minifyEnabled false | 49 | minifyEnabled false |
50 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 50 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
51 | signingConfig signingConfigs.config | 51 | signingConfig signingConfigs.config |
52 | } | 52 | } |
53 | } | 53 | } |
54 | lintOptions { | 54 | lintOptions { |
55 | checkReleaseBuilds false | 55 | checkReleaseBuilds false |
56 | abortOnError false | 56 | abortOnError false |
57 | } | 57 | } |
58 | buildFeatures { | 58 | buildFeatures { |
59 | viewBinding true | 59 | viewBinding true |
60 | dataBinding true | 60 | dataBinding 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 | ||
82 | // rx | 82 | // rx |
83 | implementation("com.trello.rxlifecycle2:rxlifecycle:2.2.2") | 83 | implementation("com.trello.rxlifecycle2:rxlifecycle:2.2.2") |
84 | implementation("com.trello.rxlifecycle2:rxlifecycle-android:2.2.2") | 84 | implementation("com.trello.rxlifecycle2:rxlifecycle-android:2.2.2") |
85 | 85 | ||
86 | implementation("com.github.PhilJay:MPAndroidChart:v3.1.0") | 86 | implementation("com.github.PhilJay:MPAndroidChart:v3.1.0") |
87 | implementation("com.contrarywind:Android-PickerView:4.1.9") | 87 | implementation("com.contrarywind:Android-PickerView:4.1.9") |
88 | 88 | ||
89 | implementation 'com.google.android:flexbox:1.0.0' | 89 | implementation 'com.google.android:flexbox:1.0.0' |
90 | 90 | ||
91 | // 沉浸式状态栏和他的Kotlin拓展 | 91 | // 沉浸式状态栏和他的Kotlin拓展 |
92 | implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2' | 92 | implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2' |
93 | implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2' | 93 | implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2' |
94 | 94 | ||
95 | // 图片查看 | 95 | // 图片查看 |
96 | implementation 'com.github.chrisbanes:PhotoView:2.0.0' | 96 | implementation 'com.github.chrisbanes:PhotoView:2.0.0' |
97 | 97 | ||
98 | implementation 'com.jakewharton:butterknife:10.2.3' | 98 | implementation 'com.jakewharton:butterknife:10.2.3' |
99 | annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3' | 99 | annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3' |
100 | } | 100 | } |
app/src/main/java/com/hjx/parent/dialog/AddHomeworkDialog.java
1 | package com.hjx.parent.dialog; | 1 | package com.hjx.parent.dialog; |
2 | 2 | ||
3 | import android.annotation.SuppressLint; | 3 | import android.annotation.SuppressLint; |
4 | import android.content.Context; | 4 | import android.content.Context; |
5 | import android.util.Pair; | 5 | import android.util.Pair; |
6 | import android.view.View; | 6 | import android.view.View; |
7 | import android.view.WindowManager; | 7 | import android.view.WindowManager; |
8 | import android.widget.AdapterView; | 8 | import android.widget.AdapterView; |
9 | import android.widget.ArrayAdapter; | 9 | import android.widget.ArrayAdapter; |
10 | import android.widget.Toast; | 10 | import android.widget.Toast; |
11 | 11 | ||
12 | import androidx.annotation.NonNull; | 12 | import androidx.annotation.NonNull; |
13 | 13 | ||
14 | import com.bigkoo.pickerview.builder.TimePickerBuilder; | 14 | import com.bigkoo.pickerview.builder.TimePickerBuilder; |
15 | import com.google.gson.Gson; | 15 | import com.google.gson.Gson; |
16 | import com.hjx.parent.R; | 16 | import com.hjx.parent.R; |
17 | import com.hjx.parent.bean.StudentBean; | 17 | import com.hjx.parent.bean.StudentBean; |
18 | import com.hjx.parent.databinding.DialogAddHomeworkBinding; | 18 | import com.hjx.parent.databinding.DialogAddHomeworkBinding; |
19 | import com.hjx.parent.function.Function0; | 19 | import com.hjx.parent.function.Function0; |
20 | import com.hjx.parent.function.Function1; | 20 | import com.hjx.parent.function.Function1; |
21 | import com.hjx.parent.rx.BaseRxActivity; | 21 | import com.hjx.parent.rx.BaseRxActivity; |
22 | import com.prws.common.bean.GradeAndSubject; | 22 | import com.prws.common.bean.GradeAndSubject; |
23 | import com.prws.common.bean.ResponseResult; | 23 | import com.prws.common.bean.ResponseResult; |
24 | import com.prws.common.bean.Student; | 24 | import com.prws.common.bean.Student; |
25 | import com.prws.common.bean.Subject; | 25 | import com.prws.common.bean.Subject; |
26 | import com.prws.common.bean.baidu.BaiduInput; | 26 | import com.prws.common.bean.baidu.BaiduInput; |
27 | import com.prws.common.net.NetWorks; | 27 | import com.prws.common.net.NetWorks; |
28 | import com.prws.common.utils.SharedPreferencesUtil; | 28 | import com.prws.common.utils.SharedPreferencesUtil; |
29 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; | 29 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; |
30 | 30 | ||
31 | import java.io.File; | 31 | import java.io.File; |
32 | import java.text.SimpleDateFormat; | 32 | import java.text.SimpleDateFormat; |
33 | import java.util.ArrayList; | 33 | import java.util.ArrayList; |
34 | import java.util.Date; | 34 | import java.util.Date; |
35 | import java.util.HashMap; | 35 | import java.util.HashMap; |
36 | import java.util.List; | 36 | import java.util.List; |
37 | import java.util.Locale; | 37 | import java.util.Locale; |
38 | import java.util.Map; | 38 | import java.util.Map; |
39 | 39 | ||
40 | import io.reactivex.Observable; | 40 | import io.reactivex.Observable; |
41 | import io.reactivex.android.schedulers.AndroidSchedulers; | 41 | import io.reactivex.android.schedulers.AndroidSchedulers; |
42 | import io.reactivex.schedulers.Schedulers; | 42 | import io.reactivex.schedulers.Schedulers; |
43 | 43 | ||
44 | public class AddHomeworkDialog extends BaseDialog<DialogAddHomeworkBinding>{ | 44 | public class AddHomeworkDialog extends BaseDialog<DialogAddHomeworkBinding>{ |
45 | private final BaseRxActivity<?> activity; | 45 | private final BaseRxActivity<?> activity; |
46 | 46 | ||
47 | private Function1<Student> callback; | 47 | private Function1<Student> callback; |
48 | 48 | ||
49 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA); | 49 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA); |
50 | List<Student> studentList; | 50 | List<Student> studentList; |
51 | List<GradeAndSubject> gradeAndSubjectList; | 51 | List<GradeAndSubject> gradeAndSubjectList; |
52 | 52 | ||
53 | List<String> images; | 53 | List<String> images; |
54 | 54 | ||
55 | Student student; | 55 | Student student; |
56 | String grade; | 56 | String grade; |
57 | String term; | 57 | String term; |
58 | String subject; | 58 | String subject; |
59 | Date uploadTime = new Date(); | 59 | Date uploadTime = new Date(); |
60 | 60 | ||
61 | public AddHomeworkDialog(BaseRxActivity<?> context) { | 61 | public AddHomeworkDialog(BaseRxActivity<?> context) { |
62 | super((Context) context); | 62 | super((Context) context); |
63 | activity = context; | 63 | activity = context; |
64 | } | 64 | } |
65 | 65 | ||
66 | public void show(List<String> paths, Function1<Student> callback) { | 66 | public void show(List<String> paths, Function1<Student> callback) { |
67 | images = paths; | 67 | images = paths; |
68 | this.callback = callback; | 68 | this.callback = callback; |
69 | super.show(); | 69 | super.show(); |
70 | } | 70 | } |
71 | 71 | ||
72 | @SuppressLint("SetTextI18n") | 72 | @SuppressLint("SetTextI18n") |
73 | @Override | 73 | @Override |
74 | public void initView() { | 74 | public void initView() { |
75 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); | 75 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); |
76 | binding.btnClose.setOnClickListener(v -> dismiss()); | 76 | binding.btnClose.setOnClickListener(v -> dismiss()); |
77 | binding.spStudent.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 77 | binding.spStudent.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
78 | @Override | 78 | @Override |
79 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 79 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
80 | student = studentList.get(position); | 80 | student = studentList.get(position); |
81 | if (gradeAndSubjectList == null) return; | 81 | if (gradeAndSubjectList == null) return; |
82 | int p = 0; | 82 | int p = 0; |
83 | for (GradeAndSubject it: gradeAndSubjectList) { | 83 | for (GradeAndSubject it: gradeAndSubjectList) { |
84 | if (it.getGrade().getGrade().equals(student.grade)) { | 84 | if (it.getGrade().getGrade().equals(student.grade)) { |
85 | p = gradeAndSubjectList.indexOf(it); | 85 | p = gradeAndSubjectList.indexOf(it); |
86 | break; | 86 | break; |
87 | } | 87 | } |
88 | } | 88 | } |
89 | binding.spGrade.setSelection(p); | 89 | binding.spGrade.setSelection(p); |
90 | } | 90 | } |
91 | 91 | ||
92 | @Override | 92 | @Override |
93 | public void onNothingSelected(AdapterView<?> parent) { | 93 | public void onNothingSelected(AdapterView<?> parent) { |
94 | } | 94 | } |
95 | }); | 95 | }); |
96 | binding.spTerm.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 96 | binding.spTerm.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
97 | @Override | 97 | @Override |
98 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 98 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
99 | term = getContext().getResources().getStringArray(R.array.grade_array)[position]; | 99 | term = getContext().getResources().getStringArray(R.array.grade_array)[position]; |
100 | } | 100 | } |
101 | @Override | 101 | @Override |
102 | public void onNothingSelected(AdapterView<?> parent) { | 102 | public void onNothingSelected(AdapterView<?> parent) { |
103 | } | 103 | } |
104 | }); | 104 | }); |
105 | binding.spGrade.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 105 | binding.spGrade.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
106 | @Override | 106 | @Override |
107 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 107 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
108 | grade = gradeAndSubjectList.get(position).getGrade().getGrade(); | 108 | grade = gradeAndSubjectList.get(position).getGrade().getGrade(); |
109 | refreshSubjects(position); | 109 | refreshSubjects(position); |
110 | } | 110 | } |
111 | 111 | ||
112 | @Override | 112 | @Override |
113 | public void onNothingSelected(AdapterView<?> parent) { | 113 | public void onNothingSelected(AdapterView<?> parent) { |
114 | } | 114 | } |
115 | }); | 115 | }); |
116 | 116 | ||
117 | binding.tvDate.setText(dateFormat.format(uploadTime)); | 117 | binding.tvDate.setText(dateFormat.format(uploadTime)); |
118 | binding.tvDate.setOnClickListener(v -> { | 118 | binding.tvDate.setOnClickListener(v -> { |
119 | new TimePickerBuilder(getContext(), (date, v1) -> { | 119 | new TimePickerBuilder(getContext(), (date, v1) -> { |
120 | uploadTime = date; | 120 | uploadTime = date; |
121 | binding.tvDate.setText(dateFormat.format(uploadTime)); | 121 | binding.tvDate.setText(dateFormat.format(uploadTime)); |
122 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); | 122 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); |
123 | }).setType(new boolean[]{true, true, true, false, false, false}).isDialog(true).build().show(); | 123 | }).setType(new boolean[]{true, true, true, false, false, false}).isDialog(true).build().show(); |
124 | }); | 124 | }); |
125 | 125 | ||
126 | binding.btnConfirm.setOnClickListener(v -> { | 126 | binding.btnConfirm.setOnClickListener(v -> { |
127 | String name = binding.etName.getText().toString().trim(); | 127 | String name = binding.etName.getText().toString().trim(); |
128 | if (name.isEmpty()) { | 128 | if (name.isEmpty()) { |
129 | Toast.makeText(getContext(), "请输入作业名称", Toast.LENGTH_SHORT).show(); | 129 | Toast.makeText(getContext(), "请输入作业名称", Toast.LENGTH_SHORT).show(); |
130 | return; | 130 | return; |
131 | } | 131 | } |
132 | uploadImage(name); | 132 | uploadImage(name); |
133 | }); | 133 | }); |
134 | 134 | ||
135 | getGrade(); | 135 | getGrade(); |
136 | } | 136 | } |
137 | 137 | ||
138 | private String getCurrentStuId() { | 138 | private String getCurrentStuId() { |
139 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 139 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
140 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); | 140 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); |
141 | return studentBean.getStuId(); | 141 | return studentBean.getStuId(); |
142 | } | 142 | } |
143 | 143 | ||
144 | @SuppressLint("CheckResult") | 144 | @SuppressLint("CheckResult") |
145 | private void getStudents() { | 145 | private void getStudents() { |
146 | NetWorks.listStudent() | 146 | NetWorks.listStudent() |
147 | .subscribeOn(Schedulers.io()) | 147 | .subscribeOn(Schedulers.io()) |
148 | .observeOn(AndroidSchedulers.mainThread()) | 148 | .observeOn(AndroidSchedulers.mainThread()) |
149 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | 149 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) |
150 | .map(ResponseResult::getData) | 150 | .map(ResponseResult::getData) |
151 | .subscribe((data, th) -> { | 151 | .subscribe((data, th) -> { |
152 | if (th != null) th.printStackTrace(); | 152 | if (th != null) th.printStackTrace(); |
153 | if (data != null && data.size() > 0) { | 153 | if (data != null && data.size() > 0) { |
154 | studentList = data; | 154 | studentList = data; |
155 | int position = 0; | 155 | int position = 0; |
156 | String stuId = getCurrentStuId(); | 156 | String stuId = getCurrentStuId(); |
157 | for (int i = 0; i < data.size(); i++) { | 157 | for (int i = 0; i < data.size(); i++) { |
158 | if (data.get(i).stuId.equals(stuId)) { | 158 | if (data.get(i).stuId.equals(stuId)) { |
159 | position = i; | 159 | position = i; |
160 | break; | 160 | break; |
161 | } | 161 | } |
162 | } | 162 | } |
163 | binding.spStudent.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, data)); | 163 | binding.spStudent.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, data)); |
164 | binding.spStudent.setSelection(position); | 164 | binding.spStudent.setSelection(position); |
165 | } | 165 | } |
166 | }); | 166 | }); |
167 | } | 167 | } |
168 | 168 | ||
169 | @SuppressLint("CheckResult") | 169 | @SuppressLint("CheckResult") |
170 | private void getGrade() { | 170 | private void getGrade() { |
171 | NetWorks.service_url.listGradeAndSubject(NetWorks.getHeader()) | 171 | NetWorks.service_url.listGradeAndSubject(NetWorks.getHeader()) |
172 | .subscribeOn(Schedulers.io()) | 172 | .subscribeOn(Schedulers.io()) |
173 | .observeOn(AndroidSchedulers.mainThread()) | 173 | .observeOn(AndroidSchedulers.mainThread()) |
174 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | 174 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) |
175 | .map(ResponseResult::getData) | 175 | .map(ResponseResult::getData) |
176 | .firstOrError() | 176 | .firstOrError() |
177 | .subscribe((data, th) -> { | 177 | .subscribe((data, th) -> { |
178 | if (th != null) th.printStackTrace(); | 178 | if (th != null) th.printStackTrace(); |
179 | if (data != null && data.size() > 0) { | 179 | if (data != null && data.size() > 0) { |
180 | gradeAndSubjectList = data; | 180 | gradeAndSubjectList = data; |
181 | List<String> grades = new ArrayList<>(); | 181 | List<String> grades = new ArrayList<>(); |
182 | for (GradeAndSubject it: data) { | 182 | for (GradeAndSubject it: data) { |
183 | grades.add(it.getGrade().getGrade()); | 183 | grades.add(it.getGrade().getGrade()); |
184 | } | 184 | } |
185 | binding.spGrade.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, grades)); | 185 | binding.spGrade.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, grades)); |
186 | } | 186 | } |
187 | getStudents(); | 187 | getStudents(); |
188 | }); | 188 | }); |
189 | } | 189 | } |
190 | 190 | ||
191 | private void refreshSubjects(int gradePosition) { | 191 | private void refreshSubjects(int gradePosition) { |
192 | if (gradeAndSubjectList == null) return; | 192 | if (gradeAndSubjectList == null) return; |
193 | List<Subject> subjectList = gradeAndSubjectList.get(gradePosition).getSubjects(); | 193 | List<Subject> subjectList = gradeAndSubjectList.get(gradePosition).getSubjects(); |
194 | List<String> subjects = new ArrayList<>(); | 194 | List<String> subjects = new ArrayList<>(); |
195 | for (Subject s: subjectList) { | 195 | for (Subject s: subjectList) { |
196 | subjects.add(s.getSubject()); | 196 | subjects.add(s.getSubject()); |
197 | } | 197 | } |
198 | binding.spSubject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 198 | binding.spSubject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
199 | @SuppressLint("SetTextI18n") | 199 | @SuppressLint("SetTextI18n") |
200 | @Override | 200 | @Override |
201 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 201 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
202 | subject = subjects.get(position); | 202 | subject = subjects.get(position); |
203 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); | 203 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); |
204 | } | 204 | } |
205 | @Override | 205 | @Override |
206 | public void onNothingSelected(AdapterView<?> parent) { | 206 | public void onNothingSelected(AdapterView<?> parent) { |
207 | } | 207 | } |
208 | }); | 208 | }); |
209 | binding.spSubject.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, subjects)); | 209 | binding.spSubject.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, subjects)); |
210 | } | 210 | } |
211 | 211 | ||
212 | @SuppressLint("CheckResult") | 212 | @SuppressLint("CheckResult") |
213 | public void uploadImage(String name) { | 213 | public void uploadImage(String name) { |
214 | activity.showLoadingDialog("上传作业中..."); | 214 | activity.showLoadingDialog("上传作业中..."); |
215 | Observable.fromIterable(images) | 215 | Observable.fromIterable(images) |
216 | .map(path -> { | 216 | .map(path -> { |
217 | int index = images.indexOf(path); | 217 | int index = images.indexOf(path); |
218 | return new Pair<>(index, path); | 218 | return new Pair<>(index, path); |
219 | }) | 219 | }) |
220 | .subscribeOn(Schedulers.io()) | 220 | .subscribeOn(Schedulers.io()) |
221 | .flatMap(pair -> { | 221 | .flatMap(pair -> { |
222 | int index = pair.first; | 222 | int index = pair.first; |
223 | String path = pair.second; | 223 | String path = pair.second; |
224 | File file = new File(path); | 224 | File file = new File(path); |
225 | return Observable.just(file) | ||
226 | .map(var -> { | 225 | return Observable.just(file) |
227 | String id = file.getName().substring(0, file.getName().lastIndexOf(".")); | 226 | .map(var -> { |
227 | String id = file.getName().substring(0, file.getName().lastIndexOf(".")); | ||
228 | BaiduInput baiduInput = NetWorks.inputImage(path, id).blockingGet(); | 228 | BaiduInput baiduInput = NetWorks.inputImage(path, id).blockingGet(); |
229 | if (baiduInput.getError_code() != null && baiduInput.getBrief() == null) { | 229 | if (baiduInput.getError_code() != null && baiduInput.getBrief() == null) { |
230 | throw new RuntimeException("图片入库失败"); | 230 | throw new RuntimeException("图片入库失败"); |
231 | } | ||
232 | if (baiduInput.getBrief() != null) { | ||
233 | id = baiduInput.briefId(); | ||
231 | } | 234 | } else { |
232 | if (baiduInput.getBrief() != null) { | 235 | NetWorks.uploadImage(path, id).blockingGet(); |
233 | id = baiduInput.briefId(); | 236 | } |
234 | } else { | 237 | |
235 | NetWorks.uploadImage(path, id).blockingGet(); | ||
236 | } | ||
237 | 238 | Map<String, Object> map = new HashMap<>(); | |
238 | Map<String, Object> map = new HashMap<>(); | 239 | map.put("brief", id); |
239 | map.put("brief", id); | 240 | map.put("sort", index); |
240 | map.put("sort", index); | 241 | return map; |
241 | return map; | 242 | }); |
242 | }); | 243 | }, 2) |
243 | }, 2) | 244 | .toList() |
244 | .toList() | 245 | .map(list -> { |
245 | .map(list -> { | 246 | List<String> stuIds = new ArrayList<>(); |
246 | List<String> stuIds = new ArrayList<>(); | 247 | stuIds.add(student.stuId); |
247 | stuIds.add(student.stuId); | 248 | String userId = NetWorks.getUserId(); |
248 | String userId = NetWorks.getUserId(); | 249 | |
249 | 250 | Map<String, Object> map = new HashMap<>(); | |
250 | Map<String, Object> map = new HashMap<>(); | 251 | map.put("name", name); |
251 | map.put("name", name); | 252 | map.put("grade", grade); |
252 | map.put("grade", grade); | 253 | map.put("term", term); |
253 | map.put("term", term); | 254 | map.put("subject", subject); |
254 | map.put("subject", subject); | 255 | map.put("userId", userId); |
255 | map.put("userId", userId); | 256 | map.put("stuIds", stuIds); |
256 | map.put("stuIds", stuIds); | 257 | map.put("briefList", list); |
257 | map.put("briefList", list); | 258 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); |
258 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); | 259 | map.put("uploadTime", format.format(uploadTime)); |
259 | map.put("uploadTime", format.format(uploadTime)); | 260 | return map; |
260 | return map; | 261 | }) |
261 | }) | 262 | .flatMap(body -> { |
262 | .flatMap(body -> { | 263 | return NetWorks.service_url.uploadHomework(NetWorks.getHeader(), body); |
263 | return NetWorks.service_url.uploadHomework(NetWorks.getHeader(), body); | 264 | }) |
264 | }) | 265 | .observeOn(AndroidSchedulers.mainThread()) |
265 | .observeOn(AndroidSchedulers.mainThread()) | 266 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) |
266 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | 267 | .subscribe((response, th) -> { |
267 | .subscribe((response, th) -> { | 268 | if (th != null) th.printStackTrace(); |
268 | if (th != null) th.printStackTrace(); | 269 | if (response != null && response.getSuccess()) { |
269 | if (response != null && response.getSuccess()) { | 270 | activity.cancelLoadingDialog(); |
270 | activity.cancelLoadingDialog(); | 271 | dismiss(); |
271 | dismiss(); | 272 | if (callback != null) callback.invoke(student); |
272 | if (callback != null) callback.invoke(student); | 273 | } else { |
273 | } else { | 274 | activity.loadFail("上传作业失败"); |
274 | activity.loadFail("上传作业失败"); | 275 | } |
275 | } | 276 | }) |
276 | }) | 277 | ; |
277 | ; | 278 | } |
278 | } | 279 | |
279 | 280 | @NonNull | |
280 | @NonNull | 281 | @Override |
281 | @Override | 282 | public DialogAddHomeworkBinding getBinding() { |
282 | public DialogAddHomeworkBinding getBinding() { | 283 | return DialogAddHomeworkBinding.inflate(getLayoutInflater()); |
libs/common/src/main/java/com/prws/common/bean/baidu/BaiduInput.java
1 | package com.prws.common.bean.baidu; | 1 | package com.prws.common.bean.baidu; |
2 | 2 | ||
3 | import com.google.gson.Gson; | ||
4 | |||
3 | import com.google.gson.Gson; | 5 | public class BaiduInput { |
4 | 6 | String brief; | |
5 | public class BaiduInput { | 7 | String error_code; |
6 | String brief; | 8 | String cont_sign; |
7 | String error_code; | 9 | String log_id; |
8 | String cont_sign; | 10 | |
9 | String log_id; | 11 | public void setBrief(String brief) { |
10 | 12 | this.brief = brief; | |
11 | public void setBrief(String brief) { | 13 | } |
12 | this.brief = brief; | 14 | |
13 | } | 15 | public void setError_code(String error_code) { |
14 | 16 | this.error_code = error_code; | |
15 | public void setError_code(String error_code) { | 17 | } |
16 | this.error_code = error_code; | 18 | |
17 | } | 19 | public void setCont_sign(String cont_sign) { |
18 | 20 | this.cont_sign = cont_sign; | |
19 | public void setCont_sign(String cont_sign) { | 21 | } |
20 | this.cont_sign = cont_sign; | 22 | |
21 | } | 23 | public void setLog_id(String log_id) { |
22 | 24 | this.log_id = log_id; | |
23 | public void setLog_id(String log_id) { | 25 | } |
24 | this.log_id = log_id; | 26 | |
25 | } | 27 | public String getBrief() { |
26 | 28 | return brief; | |
27 | public String getBrief() { | 29 | } |
28 | return brief; | 30 | |
31 | public String briefId() { | ||
32 | Brief briefBean = new Gson().fromJson(brief, Brief.class); | ||
33 | return briefBean.id; | ||
34 | } | ||
35 | |||
29 | } | 36 | public String getError_code() { |
30 | 37 | return error_code; | |
31 | public String briefId() { | 38 | } |
32 | Brief briefBean = new Gson().fromJson(brief, Brief.class); | 39 | |
33 | return briefBean.id; | 40 | public String getCont_sign() { |
34 | } | 41 | return cont_sign; |
35 | 42 | } | |
36 | public String getError_code() { | 43 | |
37 | return error_code; | 44 | public String getLog_id() { |
38 | } | 45 | return log_id; |
39 | 46 | } | |
40 | public String getCont_sign() { | 47 | |
41 | return cont_sign; | 48 | public static class Brief { |
42 | } | 49 | String name; |
43 | 50 | String id; | |
44 | public String getLog_id() { | 51 | |
45 | return log_id; | 52 | public void setName(String name) { |
46 | } | 53 | this.name = name; |
47 | 54 | } | |
48 | public static class Brief { | 55 | |
49 | String name; | 56 | public String getName() { |
50 | String id; | 57 | return name; |
51 | 58 | } | |
52 | public void setName(String name) { | 59 | |
53 | this.name = name; | 60 | public String getId() { |
54 | } | 61 | return id; |
55 | 62 | } | |
56 | public String getName() { | 63 | } |
57 | return name; | 64 | } |
58 | } | 65 |