Skip to content
This repository was archived by the owner on Mar 4, 2022. It is now read-only.

Commit dccf1f8

Browse files
author
itning
committed
class check
1 parent 2dee3ab commit dccf1f8

File tree

4 files changed

+157
-3
lines changed

4 files changed

+157
-3
lines changed

app/src/main/java/top/itning/smpandroid/client/ClassClient.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package top.itning.smpandroid.client;
22

33
import io.reactivex.Observable;
4+
import retrofit2.http.Field;
5+
import retrofit2.http.FormUrlEncoded;
46
import retrofit2.http.GET;
7+
import retrofit2.http.POST;
58
import retrofit2.http.Path;
69
import retrofit2.http.Query;
710
import top.itning.smpandroid.client.http.Page;
@@ -33,4 +36,25 @@ public interface ClassClient {
3336
*/
3437
@GET("/class/checks/{studentClassId}")
3538
Observable<RestModel<Page<StudentClassCheck>>> getAllChecks(@Path("studentClassId") String studentClassId, @Query("page") Integer page, @Query("size") Integer size);
39+
40+
/**
41+
* 检查是否可以签到
42+
*
43+
* @param studentClassId 学生班级ID
44+
* @return 可以签到返回<code>true</code>
45+
*/
46+
@GET("/class/can_check/{studentClassId}")
47+
Observable<RestModel<Boolean>> canCheck(@Path("studentClassId") String studentClassId);
48+
49+
/**
50+
* 学生课堂签到
51+
*
52+
* @param longitude 经度
53+
* @param latitude 纬度
54+
* @param studentClassId 课堂ID
55+
* @return 学生课堂签到
56+
*/
57+
@FormUrlEncoded
58+
@POST("/class/check")
59+
Observable<RestModel<StudentClassCheck>> check(@Field("longitude") double longitude, @Field("latitude") double latitude, @Field("studentClassId") String studentClassId);
3660
}

app/src/main/java/top/itning/smpandroid/entity/StudentClassCheck.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public class StudentClassCheck implements Serializable {
2929
* 签到时间
3030
*/
3131
private Date checkTime;
32+
/**
33+
* 经度
34+
*/
35+
private double longitude;
36+
/**
37+
* 纬度
38+
*/
39+
private double latitude;
40+
/**
41+
* 本次签到所对应的元数据
42+
*/
43+
private StudentClassCheckMetaData studentClassCheckMetaData;
3244
/**
3345
* 创建时间
3446
*/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package top.itning.smpandroid.entity;
2+
3+
import java.io.Serializable;
4+
import java.util.Date;
5+
6+
import lombok.Data;
7+
8+
/**
9+
* @author itning
10+
*/
11+
@Data
12+
public class StudentClassCheckMetaData implements Serializable {
13+
/**
14+
* 元数据ID
15+
*/
16+
private String id;
17+
/**
18+
* 签到开始时间
19+
*/
20+
private Date startTime;
21+
/**
22+
* 签到结束时间
23+
*/
24+
private Date endTime;
25+
/**
26+
* 经度
27+
*/
28+
private double longitude;
29+
/**
30+
* 纬度
31+
*/
32+
private double latitude;
33+
/**
34+
* 签到者距离教师经纬度最大距离
35+
*/
36+
private float m;
37+
/**
38+
* 元数据所对应的班级
39+
*/
40+
private StudentClass studentClass;
41+
/**
42+
* 创建时间
43+
*/
44+
private Date gmtCreate;
45+
/**
46+
* 更新时间
47+
*/
48+
private Date gmtModified;
49+
}

app/src/main/java/top/itning/smpandroid/ui/activity/ClassCheckActivity.java

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.animation.ObjectAnimator;
44
import android.animation.ValueAnimator;
5+
import android.app.ProgressDialog;
56
import android.os.Bundle;
67
import android.util.Log;
78
import android.view.Menu;
@@ -75,7 +76,14 @@ public class ClassCheckActivity extends AppCompatActivity {
7576
private ObjectAnimator alphaAnimator2;
7677
private List<StudentClassCheck> studentClassCheckList;
7778
private Page<StudentClassCheck> studentClassCheckPage;
79+
@Nullable
7880
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;
7987

8088
@Override
8189
protected void onCreate(Bundle savedInstanceState) {
@@ -85,7 +93,6 @@ protected void onCreate(Bundle savedInstanceState) {
8593
studentClassUserFromIntent = (StudentClassUser) getIntent().getSerializableExtra("data");
8694
initView();
8795
initLocation();
88-
Log.d(TAG, studentClassUserFromIntent == null ? "null" : studentClassUserFromIntent.toString());
8996
}
9097

9198
private void initLocation() {
@@ -96,6 +103,8 @@ private void initLocation() {
96103
if (aMapLocation != null) {
97104
if (aMapLocation.getErrorCode() == 0) {
98105
//可在其中解析amapLocation获取相应内容。
106+
longitude = aMapLocation.getLongitude();
107+
latitude = aMapLocation.getLatitude();
99108
if (addressTextView != null) {
100109
if (!"".equals(aMapLocation.getDescription())) {
101110
addressTextView.setText(aMapLocation.getDescription());
@@ -132,7 +141,7 @@ private void initLocation() {
132141
//设置是否返回地址信息(默认返回地址信息)
133142
locationOption.setNeedAddress(true);
134143
//设置是否允许模拟位置,默认为true,允许模拟位置
135-
locationOption.setMockEnable(false);
144+
locationOption.setMockEnable(true);
136145
//给定位客户端对象设置定位参数
137146
locationClient.setLocationOption(locationOption);
138147
//启动定位
@@ -286,6 +295,12 @@ public void onBackPressed() {
286295
if (initRecyclerViewDataDisposable != null && !initRecyclerViewDataDisposable.isDisposed()) {
287296
initRecyclerViewDataDisposable.dispose();
288297
}
298+
if (canCheckDisposable != null && !canCheckDisposable.isDisposed()) {
299+
canCheckDisposable.dispose();
300+
}
301+
if (checkDisposable != null && !checkDisposable.isDisposed()) {
302+
checkDisposable.dispose();
303+
}
289304
super.onBackPressed();
290305
}
291306

@@ -306,6 +321,60 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
306321
}
307322

308323
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+
}));
310379
}
311380
}

0 commit comments

Comments
 (0)