2
2
3
3
import android .animation .ObjectAnimator ;
4
4
import android .animation .ValueAnimator ;
5
+ import android .app .ProgressDialog ;
5
6
import android .os .Bundle ;
6
7
import android .util .Log ;
7
8
import android .view .Menu ;
@@ -75,7 +76,14 @@ public class ClassCheckActivity extends AppCompatActivity {
75
76
private ObjectAnimator alphaAnimator2 ;
76
77
private List <StudentClassCheck > studentClassCheckList ;
77
78
private Page <StudentClassCheck > studentClassCheckPage ;
79
+ @ Nullable
78
80
private Disposable initRecyclerViewDataDisposable ;
81
+ @ Nullable
82
+ private Disposable canCheckDisposable ;
83
+ @ Nullable
84
+ private Disposable checkDisposable ;
85
+ private double longitude = 0 ;
86
+ private double latitude = 0 ;
79
87
80
88
@ Override
81
89
protected void onCreate (Bundle savedInstanceState ) {
@@ -85,7 +93,6 @@ protected void onCreate(Bundle savedInstanceState) {
85
93
studentClassUserFromIntent = (StudentClassUser ) getIntent ().getSerializableExtra ("data" );
86
94
initView ();
87
95
initLocation ();
88
- Log .d (TAG , studentClassUserFromIntent == null ? "null" : studentClassUserFromIntent .toString ());
89
96
}
90
97
91
98
private void initLocation () {
@@ -96,6 +103,8 @@ private void initLocation() {
96
103
if (aMapLocation != null ) {
97
104
if (aMapLocation .getErrorCode () == 0 ) {
98
105
//可在其中解析amapLocation获取相应内容。
106
+ longitude = aMapLocation .getLongitude ();
107
+ latitude = aMapLocation .getLatitude ();
99
108
if (addressTextView != null ) {
100
109
if (!"" .equals (aMapLocation .getDescription ())) {
101
110
addressTextView .setText (aMapLocation .getDescription ());
@@ -132,7 +141,7 @@ private void initLocation() {
132
141
//设置是否返回地址信息(默认返回地址信息)
133
142
locationOption .setNeedAddress (true );
134
143
//设置是否允许模拟位置,默认为true,允许模拟位置
135
- locationOption .setMockEnable (false );
144
+ locationOption .setMockEnable (true );
136
145
//给定位客户端对象设置定位参数
137
146
locationClient .setLocationOption (locationOption );
138
147
//启动定位
@@ -286,6 +295,12 @@ public void onBackPressed() {
286
295
if (initRecyclerViewDataDisposable != null && !initRecyclerViewDataDisposable .isDisposed ()) {
287
296
initRecyclerViewDataDisposable .dispose ();
288
297
}
298
+ if (canCheckDisposable != null && !canCheckDisposable .isDisposed ()) {
299
+ canCheckDisposable .dispose ();
300
+ }
301
+ if (checkDisposable != null && !checkDisposable .isDisposed ()) {
302
+ checkDisposable .dispose ();
303
+ }
289
304
super .onBackPressed ();
290
305
}
291
306
@@ -306,6 +321,60 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
306
321
}
307
322
308
323
public void onShadowClick (View view ) {
309
- Snackbar .make (coordinatorLayout , "老师没有开启签到" , Snackbar .LENGTH_LONG ).show ();
324
+ if (studentClassUserFromIntent == null ) {
325
+ Snackbar .make (coordinatorLayout , "无法签到,获取班级信息失败" , Snackbar .LENGTH_LONG ).show ();
326
+ return ;
327
+ }
328
+ String studentClassId = studentClassUserFromIntent .getStudentClass ().getId ();
329
+ canCheckDisposable = HttpHelper .get (ClassClient .class )
330
+ .canCheck (studentClassId )
331
+ .subscribeOn (Schedulers .computation ())
332
+ .observeOn (AndroidSchedulers .mainThread ())
333
+ .subscribe (booleanRestModel -> {
334
+ if (booleanRestModel .getData ()) {
335
+ doClassCheck ();
336
+ } else {
337
+ Snackbar .make (coordinatorLayout , "教师未开启签到" , Snackbar .LENGTH_LONG ).show ();
338
+ }
339
+ }, HttpHelper .ErrorInvoke .get (this )
340
+ .orElseException (t -> {
341
+ Log .w (TAG , "网络请求错误" , t );
342
+ Snackbar .make (coordinatorLayout , "网络请求错误" , Snackbar .LENGTH_LONG ).show ();
343
+ }));
344
+ }
345
+
346
+ @ SuppressWarnings ("deprecation" )
347
+ private void doClassCheck () {
348
+ if (studentClassUserFromIntent == null ) {
349
+ Snackbar .make (coordinatorLayout , "无法签到,获取班级信息失败" , Snackbar .LENGTH_LONG ).show ();
350
+ return ;
351
+ }
352
+ ProgressDialog progressDialog = new ProgressDialog (this );
353
+ progressDialog .setMessage ("正在签到" );
354
+ progressDialog .setProgressStyle (ProgressDialog .STYLE_SPINNER );
355
+ progressDialog .setCancelable (false );
356
+ progressDialog .show ();
357
+ checkDisposable = HttpHelper .get (ClassClient .class )
358
+ .check (longitude , latitude , studentClassUserFromIntent .getStudentClass ().getId ())
359
+ .subscribeOn (Schedulers .computation ())
360
+ .observeOn (AndroidSchedulers .mainThread ())
361
+ .subscribe (studentClassCheckRestModel -> {
362
+ studentClassCheckList .add (0 , studentClassCheckRestModel .getData ());
363
+ if (rv .getAdapter () != null ) {
364
+ rv .getAdapter ().notifyDataSetChanged ();
365
+ }
366
+ setLastCheckTimeTextView (0 , studentClassCheckRestModel .getData ());
367
+ progressDialog .dismiss ();
368
+ Snackbar .make (coordinatorLayout , "签到成功" , Snackbar .LENGTH_LONG ).show ();
369
+ }, HttpHelper .ErrorInvoke .get (this )
370
+ .before (t -> progressDialog .dismiss ())
371
+ .orElseCode (t -> {
372
+ String msg = t .getT2 () != null ? t .getT2 ().getMsg () : t .getT1 ().code () + "" ;
373
+ Snackbar .make (coordinatorLayout , msg , Snackbar .LENGTH_LONG ).show ();
374
+ })
375
+ .orElseException (t -> {
376
+ Log .w (TAG , "网络请求错误" , t );
377
+ Snackbar .make (coordinatorLayout , "网络请求错误" , Snackbar .LENGTH_LONG ).show ();
378
+ }));
310
379
}
311
380
}
0 commit comments