@@ -80,6 +80,7 @@ public class MainActivity extends AppCompatActivity implements StudentClassUserR
80
80
private Disposable recyclerViewDataDisposable ;
81
81
private List <StudentClassUser > groupList ;
82
82
private Page <StudentClassUser > studentGroupPage ;
83
+ private Disposable joinDisposable ;
83
84
84
85
85
86
@ Override
@@ -211,8 +212,13 @@ public void onFabClick(View view) {
211
212
if (textInputLayout != null ) {
212
213
EditText editText = textInputLayout .getEditText ();
213
214
if (editText != null ) {
215
+ if (editText .getText ().length () == 0 || "" .contentEquals (editText .getText ())) {
216
+ Snackbar .make (coordinatorLayout , "请输入班号" , Snackbar .LENGTH_LONG ).show ();
217
+ return ;
218
+ }
214
219
Editable editable = editText .getText ();
215
220
Log .d (TAG , editable .toString ());
221
+ doJoinClass (editable .toString ());
216
222
}
217
223
}
218
224
})
@@ -228,9 +234,26 @@ public void onFabClick(View view) {
228
234
}
229
235
}
230
236
237
+ private void doJoinClass (String classNum ) {
238
+ joinDisposable = HttpHelper .get (ClassClient .class )
239
+ .joinClass (classNum )
240
+ .subscribeOn (Schedulers .computation ())
241
+ .observeOn (AndroidSchedulers .mainThread ())
242
+ .subscribe (pageRestModel -> {
243
+ groupList .add (0 , pageRestModel .getData ());
244
+ if (rv .getAdapter () != null ) {
245
+ rv .getAdapter ().notifyDataSetChanged ();
246
+ }
247
+ }, HttpHelper .ErrorInvoke .get (this )
248
+ .orElseCode (t -> Snackbar .make (coordinatorLayout , t .getT2 () == null ? t .getT1 ().code () + "" : t .getT2 ().getMsg (), Snackbar .LENGTH_LONG ).show ())
249
+ .orElseException (t -> {
250
+ Log .w (TAG , "网络请求错误" , t );
251
+ Snackbar .make (coordinatorLayout , "网络请求错误" , Snackbar .LENGTH_LONG ).show ();
252
+ }));
253
+ }
254
+
231
255
@ Override
232
256
public void onItemClick (View view , StudentClassUser object ) {
233
- Log .d (TAG , object .toString ());
234
257
Intent intent = new Intent (this , ClassCheckActivity .class );
235
258
intent .putExtra ("data" , object );
236
259
startActivity (intent );
@@ -276,6 +299,9 @@ public void onBackPressed() {
276
299
if (recyclerViewDataDisposable != null && !recyclerViewDataDisposable .isDisposed ()) {
277
300
recyclerViewDataDisposable .dispose ();
278
301
}
302
+ if (joinDisposable != null && !joinDisposable .isDisposed ()) {
303
+ joinDisposable .dispose ();
304
+ }
279
305
super .onBackPressed ();
280
306
}
281
307
}
0 commit comments