diff --git a/COURCE/.gitignore b/COURCE/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/COURCE/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/COURCE/.idea/.gitignore b/COURCE/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/COURCE/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/COURCE/.idea/compiler.xml b/COURCE/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/COURCE/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/COURCE/.idea/gradle.xml b/COURCE/.idea/gradle.xml new file mode 100644 index 0000000..526b4c2 --- /dev/null +++ b/COURCE/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/COURCE/.idea/misc.xml b/COURCE/.idea/misc.xml new file mode 100644 index 0000000..5ea60e3 --- /dev/null +++ b/COURCE/.idea/misc.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/COURCE/app/.gitignore b/COURCE/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/COURCE/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/COURCE/app/build.gradle b/COURCE/app/build.gradle new file mode 100644 index 0000000..f4b18da --- /dev/null +++ b/COURCE/app/build.gradle @@ -0,0 +1,41 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdk 32 + + defaultConfig { + applicationId "com.example.cource" + minSdk 27 + targetSdk 32 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'com.google.code.gson:gson:2.9.0' + implementation 'com.growingio.android:okhttp3:3.3.6' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} \ No newline at end of file diff --git a/COURCE/app/proguard-rules.pro b/COURCE/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/COURCE/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/COURCE/app/src/androidTest/java/com/example/cource/ExampleInstrumentedTest.java b/COURCE/app/src/androidTest/java/com/example/cource/ExampleInstrumentedTest.java new file mode 100644 index 0000000..6cd9db0 --- /dev/null +++ b/COURCE/app/src/androidTest/java/com/example/cource/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.cource; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.cource", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/COURCE/app/src/main/AndroidManifest.xml b/COURCE/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..16894c1 --- /dev/null +++ b/COURCE/app/src/main/AndroidManifest.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/BaseRespone.java b/COURCE/app/src/main/java/com/example/cource/BaseRespone.java new file mode 100644 index 0000000..53a2738 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/BaseRespone.java @@ -0,0 +1,37 @@ +package com.example.cource; + +public class BaseRespone { + private int code; + private String msg; + + + public final static int RESPONE_SUCCESS = 0; + private T data; + public BaseRespone() { + + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/Constans.java b/COURCE/app/src/main/java/com/example/cource/Constans.java new file mode 100644 index 0000000..a5e6de1 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/Constans.java @@ -0,0 +1,44 @@ +package com.example.cource; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public final class Constans { + private Constans(){ + + } + + + public static String Accept="application/json, text/plain, */*"; + public static String Content_Type="application/json"; + public static String ReqUrl ="http://47.107.52.7:88/member/sign/"; + public static String appId = "7a313d4c78764cb89dde6c031efdc480"; + public static String appSecret="32939480977be35ff4daf88e1b8c209ce0c12"; + public static String all_course = "course/all"; + public static String detail = "course/detail"; + public static String student= "course/student"; + public static String imagePath = "https://guet-lab.oss-cn-guangzhou.aliyuncs.com/api/2022/06/14/Screenshot_2021-10-16_21_47_43.png"; + public static String studentdrop= "course/student/drop"; + + public static String studentselect= "course/student/select"; + + public static String studentsign = "course/student/sign"; + + + public static String studentsignList = "course/student/signList"; + public static String teacher = "course/teacher"; + public static String teacherfinished = "course/teacher/finished"; + public static String teacherinitiate = "course/teacher/initiate"; + public static String teacherpage = "course/teacher/page"; + public static String teacherunfinish = "course/teacher/finished"; + public static String imageload= "image/load"; + public static String userlogin= "user/login"; + public static String userrigister= "user/register"; + public static String userupdate= "user/update"; + +} diff --git a/COURCE/app/src/main/java/com/example/cource/CourseActivity.java b/COURCE/app/src/main/java/com/example/cource/CourseActivity.java new file mode 100644 index 0000000..1a3bd87 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/CourseActivity.java @@ -0,0 +1,284 @@ +package com.example.cource; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + +import android.content.Intent; +import android.os.Bundle; +import android.os.NetworkOnMainThreadException; +import android.util.Log; +import android.view.View; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class CourseActivity extends AppCompatActivity { + + private List signRecords; + private List signRecords1; + private TextView sign,action,head; + private ImageView signment; + private SwipeRefreshLayout swipe_course; + + private int status=0; + private String signId="0"; + private SignAdapterStudent adapter1; + private SignAdapter adapter; + private ListView lv_sign; + private String courseName; + private int courseId,roleId; + private long userId; + private final Callback callback=new okhttp3.Callback(){ + + @Override + public void onFailure(Call call, IOException e) { + Log.e("TAG","Failed to connect server!"); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if(response.isSuccessful()){ + final String body1 = response.body().string(); + Log.println(Log.INFO,"OK",body1); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken>>>(){}.getType(); + BaseRespone>> newUserResponse = gson.fromJson(body1,jsonType); + Log.println(Log.INFO,"records","what3?"); + if (newUserResponse.getData()!=null) + { + if (!adapter1.isEmpty()) { + adapter1.clear(); + }Log.println(Log.INFO,"records","what2?"); + ResponseData> u = newUserResponse.getData(); + if (!u.getRecords().isEmpty()) { + List s = u.getRecords(); + for (SignInfo_student s1:s){ + adapter1.add(s1); + } + adapter1.notifyDataSetChanged(); + Log.println(Log.INFO,"records","what1?"); + } + }Log.println(Log.INFO,"records","what?"); + + } + }); + }else { + String msg = response.message(); + int code = response.code(); + Log.println(Log.ERROR,"error",String.valueOf(code)+" "+msg); + } + } + + }; + private final Callback callback1 = new Callback() { + @Override + public void onFailure(Call call, IOException e) { + Log.e("TAG","Failed to connect server!"); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if(response.isSuccessful()){ + String body2 = response.body().string(); + Log.println(Log.INFO,"OK",body2); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken>(){}.getType(); + BaseRespone newUserResponse = gson.fromJson(body2,jsonType); + signInfo u= newUserResponse.getData(); + //Log.println(Log.INFO,"OK",Long.toString(u.getCourseId())); + if (!adapter.isEmpty()) + { + adapter.clear(); + + }else { + adapter.add(u); + adapter.notifyDataSetChanged(); + Log.println(Log.INFO,"test","nosign"); + } + } + }); + } + } + }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_course); + Intent intent = getIntent(); + + lv_sign =findViewById(R.id.sign_lv); + signment =findViewById(R.id.introduction); + + swipe_course = findViewById(R.id.swipe_course); + courseId = intent.getIntExtra("courseId",0); + userId = intent.getLongExtra("UserId",0); + + roleId = intent.getIntExtra("roleId",0); + courseName=intent.getStringExtra("courseName"); + + head =findViewById(R.id.TvCalendar); + head.setText(courseName); + sign = findViewById(R.id.sign); + action = findViewById(R.id.action); + sign.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + action.setTextColor(0xFFE0DBDB); + sign.setTextColor(0xFF000000); + + status=0; + if (roleId==1){ + getSign(); + }else { + getSignStudent(status); + } + } + }); + action.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + status=1; + sign.setTextColor(0xFFE0DBDB); + action.setTextColor(0xFF000000); + if (roleId==0){ + getSignStudent(status); + } + } + }); + + signment.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + if (roleId==1){ + Intent intent1 = new Intent(CourseActivity.this, Sign_CreateActivity.class); + intent1.putExtra("courseName", courseName); + intent1.putExtra("courseId", courseId); + intent1.putExtra("userId", userId); + startActivity(intent1); + }else if (roleId ==0){ + Intent intent1 = new Intent(CourseActivity.this, Sign_inActivity.class); + intent1.putExtra("userId", userId); + intent1.putExtra("userSignId", signId); + startActivity(intent1); + } + } + }); + Log.println(Log.INFO," Course id:",Integer.toString(courseId)); + Log.println(Log.INFO,"user id:",Long.toString(userId)); + + if (roleId==0){ + initData(); + }else { + initSign(); + } + + swipe_course.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + if (roleId==0){ + getSignStudent(status); + }else { + getSign(); + } + swipe_course.setRefreshing(false); + } + }); + } + + void getSignStudent(int i){ + new Thread(new Runnable() { + @Override + public void run() { + + String urlparam; + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + if (i==0){ + urlparam = "?courseId="+courseId+"&status=0"+"&userId="+userId; + }else { + urlparam = "?courseId=" + courseId + "&status=1" + "&userId=" + userId; + } + Request request1 = new Request.Builder().url(Constans.ReqUrl+Constans.studentsignList+urlparam) + .headers(Headers.of(map1)) + .get() + .build(); + + try { + OkHttpClient client = new OkHttpClient(); + client.newCall(request1).enqueue(callback); + }catch (NetworkOnMainThreadException e){ + e.printStackTrace(); + Log.println(Log.ERROR,"error","error"); + } + } + }).start(); + } + void initData(){ + signRecords1 = new ArrayList<>(); + adapter1 = new SignAdapterStudent(CourseActivity.this,R.layout.course_item,signRecords1); + lv_sign.setAdapter(adapter1); + getSignStudent(0); + } + void initSign(){ + signRecords = new ArrayList<>(); + adapter = new SignAdapter(CourseActivity.this,R.layout.course_item,signRecords); + lv_sign.setAdapter(adapter); + getSign(); + } + void getSign(){ + //获取签到列表 + new Thread(new Runnable() { + @Override + public void run() { + + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + String urlparam = "?courseId="+courseId+"&userId="+userId; + + Request request1 = new Request.Builder().url(Constans.ReqUrl+Constans.teacherpage+urlparam) + .headers(Headers.of(map1)) + .get() + .build(); + + try { + OkHttpClient client = new OkHttpClient(); + client.newCall(request1).enqueue(callback1); + }catch (NetworkOnMainThreadException e){ + e.printStackTrace(); + Log.println(Log.ERROR,"error","error"); + } + } + }).start(); + } +} \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/CourseInfo.java b/COURCE/app/src/main/java/com/example/cource/CourseInfo.java new file mode 100644 index 0000000..cd4056d --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/CourseInfo.java @@ -0,0 +1,94 @@ +package com.example.cource; + +public class CourseInfo { + private int courseId; + private String coursePhoto; + private String collegeName; + private String courseName; + private long endTime; + private String introduce; + private String realName; + private long startTime; + private long userID; + private String userName; + + public String getCollegeName() { + return collegeName; + } + + public void setCollegeName(String collegeName) { + this.collegeName = collegeName; + } + + public String getCourseName() { + return courseName; + } + + public void setCourseName(String courseName) { + this.courseName = courseName; + } + + public String getCoursePhoto() { + return coursePhoto; + } + + public void setCoursePhoto(String coursePhoto) { + this.coursePhoto = coursePhoto; + } + + public long getEndTime() { + return endTime; + } + + public void setEndTime(long endTime) { + this.endTime = endTime; + } + + public String getIntroduce() { + return introduce; + } + + public void setIntroduce(String intrudoce) { + this.introduce = intrudoce; + } + + public String getRealName() { + return realName; + } + + public void setRealName(String realName) { + this.realName = realName; + } + + public long getStartTime() { + return startTime; + } + + public void setStartTime(long startTime) { + this.startTime = startTime; + } + + public long getUserID() { + return userID; + } + + public void setUserID(long userID) { + this.userID = userID; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public int getCourseId() { + return courseId; + } + + public void setCourseId(int courseId) { + this.courseId = courseId; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/CourseResponse.java b/COURCE/app/src/main/java/com/example/cource/CourseResponse.java new file mode 100644 index 0000000..92d4e21 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/CourseResponse.java @@ -0,0 +1,68 @@ +package com.example.cource; + +public class CourseResponse { + private int code; + private String msg; + + + private final static int RESPONE_SUCCESS = 0; + private T data; + private int total; + private int current; + private int size; + + public CourseResponse() { + + } + public static int getResponeSuccess() { + return RESPONE_SUCCESS; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public int getCurrent() { + return current; + } + + public void setCurrent(int current) { + this.current = current; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/Course_create_Activity.java b/COURCE/app/src/main/java/com/example/cource/Course_create_Activity.java new file mode 100644 index 0000000..17224f8 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/Course_create_Activity.java @@ -0,0 +1,136 @@ +package com.example.cource; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.os.NetworkOnMainThreadException; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.HashMap; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class Course_create_Activity extends AppCompatActivity { + + private Long userid; + private String userName,realName,collegeName; + private EditText StartTime,EndTime,CourseName,Introduction; + private Button create_course; + private Callback callback = new Callback() { + @Override + public void onFailure(Call call, IOException e) { + Log.e("TAG","Failed to connect server!"); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if (response.isSuccessful()){ + final String body = response.body().string(); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken>(){}.getType(); + BaseRespone stringBaseRespone =gson.fromJson(body,jsonType); + int code = stringBaseRespone.getCode(); + String msg = stringBaseRespone.getMsg(); + Log.println(Log.INFO,"code",Integer.toString(code)+msg); + if (code ==200){ + Toast.makeText(getApplicationContext(),"添加成功",Toast.LENGTH_SHORT).show(); + }else Toast.makeText(getApplicationContext(),stringBaseRespone.getMsg(),Toast.LENGTH_SHORT).show(); + } + }); + + } + + } + }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_course_create); + Intent intent = getIntent(); + userid=intent.getLongExtra("userId",0); + collegeName = intent.getStringExtra("collegeName"); + userName = intent.getStringExtra("userName"); + realName = intent.getStringExtra("realName"); + Log.println(Log.INFO,"id_course_create_activity",Long.toString(userid)); + + StartTime = findViewById(R.id.courseStartTime_create); + EndTime = findViewById(R.id.courseEnd_create); + CourseName = findViewById(R.id.courseName_create); + Introduction = findViewById(R.id.courseIntroduction_create); + create_course = findViewById(R.id.Bt_course_create); + + create_course.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(realName ==null||collegeName==null){ + Toast.makeText(getApplicationContext(),"请完善个人信息",Toast.LENGTH_SHORT).show(); + }else { + courseCreate(); + } + } + }); + } + void courseCreate(){ + + new Thread(new Runnable() { + @Override + public void run() { + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + JSONObject jsonObject = new JSONObject(); + Log.println(Log.ERROR,"jsontest","this is"); + try { + jsonObject.put("collegeName",collegeName); + jsonObject.put("courseName",CourseName.getText().toString()); + jsonObject.put("coursePhoto",Constans.imagePath); + jsonObject.put("realName",realName); + jsonObject.put("endTime",EndTime.getText().toString()); + jsonObject.put("introduce",Introduction.getText().toString()); + jsonObject.put("startTime",StartTime.getText().toString()); + jsonObject.put("userId",userid); + jsonObject.put("userName",userName); + } catch (JSONException e) { + e.printStackTrace(); + } + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"),String.valueOf(jsonObject)); + Request request = new Request.Builder().url(Constans.ReqUrl+Constans.teacher) + .headers(Headers.of(map1)) + .post(requestBody) + .build(); + try { + OkHttpClient client = new OkHttpClient(); + client.newCall(request).enqueue(callback); + }catch (NetworkOnMainThreadException ex){ + ex.printStackTrace(); + } + } + }).start(); + } +} \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/ErrorInfo.java b/COURCE/app/src/main/java/com/example/cource/ErrorInfo.java new file mode 100644 index 0000000..a8dee01 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/ErrorInfo.java @@ -0,0 +1,49 @@ +package com.example.cource; + +public class ErrorInfo { + private String timestamp; + private String error; + private String message; + private String path; + private int status; + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getError() { + return error; + } + + public void setError(String error) { + this.error = error; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/ErrorRespone.java b/COURCE/app/src/main/java/com/example/cource/ErrorRespone.java new file mode 100644 index 0000000..667af91 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/ErrorRespone.java @@ -0,0 +1,8 @@ +package com.example.cource; + +public class ErrorRespone { + private T data; + public ErrorRespone() { + + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/LoginActivity.java b/COURCE/app/src/main/java/com/example/cource/LoginActivity.java new file mode 100644 index 0000000..c1b0979 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/LoginActivity.java @@ -0,0 +1,197 @@ +package com.example.cource; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.os.NetworkOnMainThreadException; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.HashMap; + +import okhttp3.Call; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class LoginActivity extends AppCompatActivity{ + + private Button login; + private EditText user,passwd; + private String username,password; + private TextView register; + private CheckBox PwdRem; + + private okhttp3.Callback callback =new okhttp3.Callback(){ + @Override + public void onFailure(Call call, IOException e) { + Log.e("TAG","Failed to connect server!"); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if(response.isSuccessful()){ + final String body = response.body().string(); + int code = response.code(); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken>(){}.getType(); + BaseRespone newUserResponse = gson.fromJson(body,jsonType); + Userinfo u =(Userinfo) newUserResponse.getData(); + long code1 = u.getId(); + String userName = u.getUserName(); + String realName = u.getRealName(); + String collegeName = u.getCollegeName(); + String roleId = u.getRoleId(); + Log.println(Log.INFO,"OK",body); + Log.println(Log.INFO,"cide",Long.toString(code1)); + switch (code){ + case 500: + Toast.makeText(getApplicationContext(),"未找到该用户",Toast.LENGTH_SHORT).show(); + break; + case 200:Intent intent =new Intent(LoginActivity.this,MainActivity.class); + intent.putExtra("id",code1); + intent.putExtra("role",Integer.valueOf(roleId)); + intent.putExtra("collegeName",collegeName); + intent.putExtra("userName",userName); + intent.putExtra("realName",realName); + intent.putExtra("email",u.getEmail()); + intent.putExtra("idNumber",u.getIdNumber()); + intent.putExtra("inTime",u.getInSchoolTime()); + intent.putExtra("phone",u.getPhone()); + intent.putExtra("gender",u.isGender()); + startActivity(intent); + break; + default: Toast.makeText(getApplicationContext(),newUserResponse.getMsg(),Toast.LENGTH_SHORT).show(); + break; + } + } + }); + }else { + int code = response.code(); + Log.println(Log.ERROR,"error",String.valueOf(code)); + } + } + }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + login = findViewById(R.id.login_button); + user = findViewById(R.id.username); + passwd = findViewById(R.id.passwd); + register = findViewById(R.id.register); + PwdRem = findViewById(R.id.RememberPwd); + login.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Rember(); + Login(); + } + }); + register.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + register(); + } + }); + String spFileName = getResources().getString(R.string.shared_preferences_file_name); + String accountKey = getResources().getString(R.string.login_account_name); + String passwordKey = getResources().getString(R.string.login_password); + String rememberPasswordKey = getResources().getString(R.string.login_remember_password); + + SharedPreferences spFile = getSharedPreferences(spFileName, Context.MODE_PRIVATE); + String password = spFile.getString(passwordKey,null); + String account = spFile.getString(accountKey,null); + Boolean rememberPassword = spFile.getBoolean(rememberPasswordKey,false); + + if (account!=null&&!TextUtils.isEmpty(account)){ + user.setText(account); + } + + if (password!=null&&!TextUtils.isEmpty(password)){ + passwd.setText(password); + } + PwdRem.setChecked(rememberPassword); + + } + + void Rember(){ + String spFileName = getResources().getString(R.string.shared_preferences_file_name); + String accountKey = getResources().getString(R.string.login_account_name); + String passwordKey = getResources().getString(R.string.login_password); + String rememberPasswordKey = getResources().getString(R.string.login_remember_password); + + SharedPreferences spFile = getSharedPreferences(spFileName, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = spFile.edit(); + + if (PwdRem.isChecked()){ + String password = passwd.getText().toString(); + String account = user.getText().toString(); + editor.putString(accountKey,account); + editor.putString(passwordKey,password); + editor.putBoolean(rememberPasswordKey,true); + editor.apply(); + }else{ + editor.remove(accountKey); + editor.remove(passwordKey); + editor.remove(rememberPasswordKey); + editor.apply(); + } + + } + void Login(){ + username = user.getText().toString(); + password = passwd.getText().toString(); + new Thread(new Runnable() { + @Override + public void run() { + UserRequest requestobj = new UserRequest(); + requestobj.setPassword(password); + requestobj.setUsername(username); + String urlParam = requestobj.toString(); + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + Log.println(Log.INFO,"param",urlParam); + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), urlParam); + Request request = new Request.Builder().url(Constans.ReqUrl+Constans.userlogin+urlParam) + .addHeader("appId",Constans.appId) + .addHeader("appSecret",Constans.appSecret).post(requestBody).build(); + try { + OkHttpClient client = new OkHttpClient(); + client.newCall(request).enqueue(callback); + + }catch (NetworkOnMainThreadException ex){ + ex.printStackTrace(); + } + } + }).start(); + } + void register(){ + Intent intent = new Intent(LoginActivity.this,RegisterActivity.class); + startActivity(intent); + } + +} \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/MainActivity.java b/COURCE/app/src/main/java/com/example/cource/MainActivity.java new file mode 100644 index 0000000..8a01aa2 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/MainActivity.java @@ -0,0 +1,367 @@ +package com.example.cource; + +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + +import android.content.Intent; +import android.os.Bundle; +import android.os.NetworkOnMainThreadException; +import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.PopupMenu; +import android.widget.Switch; +import android.widget.TextView; +import android.widget.Toast; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class MainActivity extends AppCompatActivity { + + private String urlParam,collegeName,userName,realName,phone,email,inTime; + private boolean gender; + private long code,idNumber; + private int roleId; + private ListView recordList; + private List records; + private RecordAdapter adapter; + private TextView all,teaching,studying; + private SwipeRefreshLayout swipe; + + private int mode=0; + private ImageView head_image; + private Toolbar mytoolbar; + private Callback callback=new okhttp3.Callback(){ + + @Override + public void onFailure(Call call, IOException e) { + Log.e("TAG","Failed to connect server!"); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if(response.isSuccessful()){ + final String body = response.body().string(); + Log.println(Log.INFO,"OK",body); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken>>>(){}.getType(); + BaseRespone>> newUserResponse = gson.fromJson(body,jsonType); + ResponseData> u= newUserResponse.getData(); + if (!u.getRecords().isEmpty()) { + adapter.clear(); + for (record r : u.getRecords()) { + adapter.add(r); + } + + adapter.notifyDataSetChanged(); + } + else { + Toast.makeText(getApplicationContext(),"您还没用创建课程",Toast.LENGTH_SHORT).show(); + } + int c = newUserResponse.getCode(); + if (u!=null){ + Log.println(Log.INFO,"code",Integer.toString(c)); + int id = u.getCurrent(); + Log.println(Log.INFO,"current",Integer.toString(id)); + Log.println(Log.INFO,"records",records.get(0).getCoursePhoto()); + + } + } + }); + }else { + /*final String errorbody = response.body().string(); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken(){}.getType(); + ErrorInfo newUserResponse = gson.fromJson(errorbody,jsonType); + String message =newUserResponse.getMessage(); + Log.println(Log.ERROR,"error",message); + } + });*/ + String msg = response.message(); + int code = response.code(); + Log.println(Log.ERROR,"error",String.valueOf(code)+" "+msg); + } + } + + }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Intent intent = getIntent(); + collegeName = intent.getStringExtra("collegeName"); + realName = intent.getStringExtra("realName"); + userName = intent.getStringExtra("userName"); + roleId = intent.getIntExtra("role",2); + code = intent.getLongExtra("id",0); + phone = intent.getStringExtra("phone"); + email = intent.getStringExtra("email"); + inTime = intent.getStringExtra("inTime"); + gender = intent.getBooleanExtra("gender",true); + idNumber = intent.getLongExtra("idNumber",0); + Log.println(Log.INFO,"intent",Long.toString(code)+" "+Integer.toString(roleId)); + + all = findViewById(R.id.all); + teaching = findViewById(R.id.teaching); + studying = findViewById(R.id.study); + + head_image = findViewById(R.id.head_image); + mytoolbar = findViewById(R.id.myToolbar); + setSupportActionBar(mytoolbar); + + swipe = findViewById(R.id.swipe); + + initView(); + initCourse(); + + all.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mode=0; + all.setTextColor(0xFF000000); + teaching.setTextColor(0xFFBBBCBF); + studying.setTextColor(0xFFBBBCBF); + search(0); + } + }); + + teaching.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + if (roleId==1){ + mode=1; + teaching.setTextColor(0xFF000000); + all.setTextColor(0xFFBBBCBF); + studying.setTextColor(0xFFBBBCBF); + search(1); + } + } + }); + studying.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(roleId==0) { + mode=2; + all.setTextColor(0xFFBBBCBF); + teaching.setTextColor(0xFFBBBCBF); + studying.setTextColor(0xFF000000); + search(2); + } + } + }); + + head_image.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + achieve(3); + } + }); + + swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + + switch (mode){ + case 1:search(1); + break; + case 2:search(2); + break; + default:search(0); + break; + } + swipe.setRefreshing(false); + Toast.makeText(getApplicationContext(),"刷新完成",Toast.LENGTH_SHORT).show(); + } + }); + + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.pop_menus_action,menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + switch (item.getItemId()){ + case R.id.participate: + if (roleId==0){ + achieve(1); + }else Toast.makeText(MainActivity.this,"您不是学生",Toast.LENGTH_SHORT).show(); + return true; + case R.id.create: + if (roleId==1) { + achieve(2); + }else Toast.makeText(MainActivity.this,"您不是教师",Toast.LENGTH_SHORT).show(); + return true; + case R.id.drop: + if (roleId==0){ + achieve(0); + }else Toast.makeText(MainActivity.this,"您不是学生",Toast.LENGTH_SHORT).show(); + default: + return super.onOptionsItemSelected(item); + + } + } + + void achieve(int id){ + Intent intent; + switch (id){ + case 0:intent = new Intent(MainActivity.this,QuitCourse_Activity.class); + intent.putExtra("userId",code); + startActivity(intent); + break; + case 1: + intent = new Intent(MainActivity.this,Participate_in_Activity.class); + intent.putExtra("userId",code); + startActivity(intent); + break; + case 2: + intent = new Intent(MainActivity.this,Course_create_Activity.class); + intent.putExtra("userId",code); + intent.putExtra("realName",realName); + intent.putExtra("collegeName",collegeName); + intent.putExtra("userName",userName); + startActivity(intent); + break; + case 3: + intent = new Intent(MainActivity.this,Modifyactivity.class); + intent.putExtra("userId",code); + intent.putExtra("realName",realName); + intent.putExtra("collegeName",collegeName); + intent.putExtra("userName",userName); + intent.putExtra("phone",phone); + intent.putExtra("email",email); + intent.putExtra("inTime",inTime); + intent.putExtra("idNumber",idNumber); + intent.putExtra("gender",gender); + startActivity(intent); + break; + default: break; + } + } + void initView(){ + recordList = findViewById(R.id.lv_course); + + recordList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Intent intent = new Intent(MainActivity.this,CourseActivity.class); + record r = adapter.getItem(position); + intent.putExtra("courseName",r.getCourseName()); + intent.putExtra("courseId",r.getCourseId()); + intent.putExtra("UserId",code); + intent.putExtra("roleId",roleId); + startActivity(intent); + } + }); + } + void initCourse(){ + records = new ArrayList<>(); + adapter = new RecordAdapter(MainActivity.this,R.layout.course_item,records); + recordList.setAdapter(adapter); + + refresh(); + //Log.println(Log.INFO,"records",records.get(0).toString()); + + + } + void refresh(){ + new Thread(new Runnable() { + @Override + public void run() { + + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + + + Request request1 = new Request.Builder().url(Constans.ReqUrl+Constans.all_course).headers(Headers.of(map1)) + .get() + .build(); + + try { + OkHttpClient client = new OkHttpClient(); + client.newCall(request1).enqueue(callback); + }catch (NetworkOnMainThreadException e){ + e.printStackTrace(); + Log.println(Log.ERROR,"error","error"); + } + } + }).start(); + } + void search(int c){ + switch (c){ + case 1:urlParam = Constans.teacherunfinish+"?userId="+Long.toString(code); + break; + + case 2:urlParam = Constans.student+"?userId="+Long.toString(code); + break; + default:urlParam=Constans.all_course; break; + } + new Thread(new Runnable() { + @Override + public void run() { + + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + + Request request1 = new Request.Builder().url(Constans.ReqUrl+urlParam).headers(Headers.of(map1)) + .get() + .build(); + + try { + OkHttpClient client = new OkHttpClient(); + client.newCall(request1).enqueue(callback); + }catch (NetworkOnMainThreadException e){ + e.printStackTrace(); + Log.println(Log.ERROR,"error","error"); + } + } + }).start(); + } +} \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/Modifyactivity.java b/COURCE/app/src/main/java/com/example/cource/Modifyactivity.java new file mode 100644 index 0000000..743b490 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/Modifyactivity.java @@ -0,0 +1,164 @@ +package com.example.cource; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.os.NetworkOnMainThreadException; +import android.util.Log; +import android.view.View; +import android.view.Window; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.HashMap; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class Modifyactivity extends AppCompatActivity { + + private TextView collegeName,email,gender,idNumber,inTime,phone,realName,userName; + + private Long userId; + private Button modify_button; + private Callback callback = new Callback() { + @Override + public void onFailure(Call call, IOException e) { + Log.e("TAG","Failed to connect server!"); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if (response.isSuccessful()){ + final String body = response.body().string(); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken>(){}.getType(); + BaseRespone stringBaseRespone =gson.fromJson(body,jsonType); + int code = stringBaseRespone.getCode(); + String msg = stringBaseRespone.getMsg(); + Log.println(Log.INFO,"code",Integer.toString(code)+msg); + if (code ==200){ + Toast.makeText(getApplicationContext(),"修改成功",Toast.LENGTH_SHORT).show(); + }else Toast.makeText(getApplicationContext(),stringBaseRespone.getMsg(),Toast.LENGTH_SHORT).show(); + } + }); + + } + + } + + }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_modifyactivity); + Intent intent = getIntent(); + userId=intent.getLongExtra("userId",0); + collegeName = findViewById(R.id.ed_college_Name_modify); + email = findViewById(R.id.ed_email_modify); + gender = findViewById(R.id.ed_gender_modify); + idNumber = findViewById(R.id.ed_idNumber_modify); + inTime = findViewById(R.id.ed_inSchoolTime_modify); + phone = findViewById(R.id.ed_phone_modify); + realName = findViewById(R.id.ed_realName_modify); + userName = findViewById(R.id.ed_userName_modify); + + collegeName.setText(intent.getStringExtra("collegeName")); + realName.setText(intent.getStringExtra("realName")); + userName.setText(intent.getStringExtra("userName")); + if (intent.getLongExtra("idNumber",0)!=0){ + String s = Long.toString(intent.getLongExtra("idNumber",0)); + idNumber.setText(s); + } + inTime.setText(intent.getStringExtra("inTime")); + phone.setText(intent.getStringExtra("phone")); + email.setText(intent.getStringExtra("email")); + if (intent.getBooleanExtra("gender",true)){ + gender.setText("男"); + }else gender.setText("女"); + modify_button =findViewById(R.id.button_modify); + modify_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + modify(); + } + }); + } + + void modify(){ + new Thread(new Runnable() { + @Override + public void run() { + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + JSONObject jsonObject = new JSONObject(); + Log.println(Log.ERROR,"jsontest","this is"); + try { + if (collegeName.getText()!=null) { + jsonObject.put("collegeName", collegeName.getText().toString()); + } + if (email.getText()!=null) { + jsonObject.put("email", email.getText().toString()); + } + if (gender.getText().toString().equals("男")){ + jsonObject.put("gender","true"); + }else { + jsonObject.put("gender","false"); + } + if (realName.getText().toString()!=null) { + jsonObject.put("realName", realName.getText().toString()); + } + if (inTime.getText().toString()!=null) { + jsonObject.put("inSchoolTime", inTime.getText().toString()); + } + if (phone.getText().toString()!=null){ + jsonObject.put("phone", phone.getText().toString()); + } + if (userName.getText().toString()!=null){ + jsonObject.put("userName", userName.getText().toString()); + } + jsonObject.put("id",userId); + if (idNumber.getText().toString()!=null) { + jsonObject.put("idNumber", idNumber.getText().toString()); + } + } catch (JSONException e) { + e.printStackTrace(); + } + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"),String.valueOf(jsonObject)); + Request request = new Request.Builder().url(Constans.ReqUrl+Constans.userupdate) + .headers(Headers.of(map1)) + .post(requestBody) + .build(); + try { + OkHttpClient client = new OkHttpClient(); + client.newCall(request).enqueue(callback); + }catch (NetworkOnMainThreadException ex){ + ex.printStackTrace(); + } + } + }).start(); + } +} \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/Participate_in_Activity.java b/COURCE/app/src/main/java/com/example/cource/Participate_in_Activity.java new file mode 100644 index 0000000..b34fc66 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/Participate_in_Activity.java @@ -0,0 +1,107 @@ +package com.example.cource; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.os.NetworkOnMainThreadException; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.HashMap; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class Participate_in_Activity extends AppCompatActivity { + + private Long userId; + private EditText Edit; + private Button Bt_participate; + private Callback callback = new Callback() { + @Override + public void onFailure(Call call, IOException e) { + Log.e("TAG","Failed to connect server!"); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if (response.isSuccessful()){ + final String body = response.body().string(); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken>(){}.getType(); + BaseRespone newUserResponse = gson.fromJson(body,jsonType); + int code = newUserResponse.getCode(); + Log.println(Log.INFO,"cide",Integer.toString(code)); + if (code ==200){ + + Toast.makeText(getApplicationContext(),"加入成功",Toast.LENGTH_SHORT).show(); + }else Toast.makeText(getApplicationContext(),newUserResponse.getMsg(),Toast.LENGTH_SHORT).show(); + } + }); + + }else Log.println(Log.INFO,"cide",Integer.toString(response.code())+response.message()); + + + } + }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_participate_in); + Intent intent =getIntent(); + userId = intent.getLongExtra("userId",0); + + Edit =findViewById(R.id.Edit_courseid); + Bt_participate = findViewById(R.id.Bt_participate_in); + Bt_participate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + participate_in(); + } + }); + } + void participate_in(){ + + new Thread(new Runnable() { + @Override + public void run() { + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + String urlParam ="?"+"courseId="+Edit.getText().toString()+"&userId="+userId; + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), urlParam); + Request request = new Request.Builder().url(Constans.ReqUrl+Constans.studentselect+urlParam) + .headers(Headers.of(map1)) + .post(requestBody).build(); + try { + OkHttpClient client = new OkHttpClient() ; + client.newCall(request).enqueue(callback); + }catch (NetworkOnMainThreadException ex){ + ex.printStackTrace(); + } + } + }).start(); + } + +} \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/PersonalInfomation.java b/COURCE/app/src/main/java/com/example/cource/PersonalInfomation.java new file mode 100644 index 0000000..5deeaed --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/PersonalInfomation.java @@ -0,0 +1,64 @@ +package com.example.cource; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link PersonalInfomation#newInstance} factory method to + * create an instance of this fragment. + */ +public class PersonalInfomation extends Fragment { + + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + + // TODO: Rename and change types of parameters + private String mParam1; + private String mParam2; + + public PersonalInfomation() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment PersonalInfomation. + */ + // TODO: Rename and change types and number of parameters + public static PersonalInfomation newInstance(String param1, String param2) { + PersonalInfomation fragment = new PersonalInfomation(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_personal_infomation, container, false); + } +} \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/QuitCourse_Activity.java b/COURCE/app/src/main/java/com/example/cource/QuitCourse_Activity.java new file mode 100644 index 0000000..a9d24a3 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/QuitCourse_Activity.java @@ -0,0 +1,105 @@ +package com.example.cource; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.os.NetworkOnMainThreadException; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.HashMap; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class QuitCourse_Activity extends AppCompatActivity { + private Long userId; + private EditText Edit; + private Button Bt_quit; + private Callback callback = new Callback() { + @Override + public void onFailure(Call call, IOException e) { + Log.e("TAG","Failed to connect server!"); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if (response.isSuccessful()){ + final String body = response.body().string(); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken>(){}.getType(); + BaseRespone newUserResponse = gson.fromJson(body,jsonType); + int code = newUserResponse.getCode(); + Log.println(Log.INFO,"cide",Integer.toString(code)+newUserResponse.getMsg()); + if (code ==200){ + + Toast.makeText(getApplicationContext(),"退课成功",Toast.LENGTH_SHORT).show(); + }else Toast.makeText(getApplicationContext(),newUserResponse.getMsg(),Toast.LENGTH_SHORT).show(); + } + }); + + }else Log.println(Log.INFO,"cide",Integer.toString(response.code())+response.message()); + + + } + }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_quit_course); + Intent intent =getIntent(); + userId = intent.getLongExtra("userId",0); + + Edit =findViewById(R.id.Edit_courseid_quit); + Bt_quit = findViewById(R.id.Bt_quit_out); + Bt_quit.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + quit(); + } + }); + } + void quit(){ + + new Thread(new Runnable() { + @Override + public void run() { + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + String urlParam ="?"+"courseId="+Edit.getText().toString()+"&userId="+userId; + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), urlParam); + Request request = new Request.Builder().url(Constans.ReqUrl+Constans.studentdrop+urlParam) + .headers(Headers.of(map1)) + .delete(requestBody).build(); + try { + OkHttpClient client = new OkHttpClient() ; + client.newCall(request).enqueue(callback); + }catch (NetworkOnMainThreadException ex){ + ex.printStackTrace(); + } + } + }).start(); + } +} \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/RecordAdapter.java b/COURCE/app/src/main/java/com/example/cource/RecordAdapter.java new file mode 100644 index 0000000..3a9eebe --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/RecordAdapter.java @@ -0,0 +1,58 @@ +package com.example.cource; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.List; + +public class RecordAdapter extends ArrayAdapter { + private List records; + private Context mContext; + private int resourseId; + + public RecordAdapter(Context context,int resourseId,List recordList){ + + super(context,resourseId,recordList); + this.mContext = context; + this.records=recordList; + this.resourseId = resourseId; + } + + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + record r = getItem(position); + View view; + + final ViewHolder vh; + if(convertView==null){ + view = LayoutInflater.from(getContext()).inflate(resourseId,parent,false); + vh= new ViewHolder(); + vh.college = view.findViewById(R.id.college); + vh.name = view.findViewById(R.id.name_course); + vh.course_id = view.findViewById(R.id.id_course); + view.setTag(vh); + }else{ + view = convertView; + vh = (ViewHolder) view.getTag(); + } + + vh.course_id.setText(Integer.toString(r.getCourseId())); + vh.college.setText(r.getCollegeName()); + vh.name.setText(r.getCourseName()); + + return view; + } + class ViewHolder{ + TextView name; + TextView course_id; + TextView college; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/RegisterActivity.java b/COURCE/app/src/main/java/com/example/cource/RegisterActivity.java new file mode 100644 index 0000000..4df8806 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/RegisterActivity.java @@ -0,0 +1,138 @@ +package com.example.cource; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.os.NetworkOnMainThreadException; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; + +import org.json.JSONException; +import org.json.JSONObject; +import org.json.JSONStringer; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.HashMap; + +import okhttp3.Call; +import okhttp3.FormBody; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import okhttp3.internal.http2.Header; +import okio.BufferedSink; + +public class RegisterActivity extends AppCompatActivity { + + private EditText user,passwd,role; + private Button register; + private okhttp3.Callback callback =new okhttp3.Callback(){ + @Override + public void onFailure(Call call, IOException e) { + Log.e("TAG","Failed to connect server!"); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if(response.isSuccessful()){ + final String body = response.body().string(); + Log.println(Log.INFO,"OK",body); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken>(){}.getType(); + BaseRespone newUserResponse = gson.fromJson(body,jsonType); + Userinfo u =newUserResponse.getData(); + int c = newUserResponse.getCode(); + if (u==null){ + Log.println(Log.INFO,"code",Integer.toString(c)); + if (c==200){ + Toast.makeText(getApplicationContext(),"注册成功",Toast.LENGTH_SHORT).show(); + }else Toast.makeText(getApplicationContext(),newUserResponse.getMsg(),Toast.LENGTH_SHORT).show(); + + } + + } + }); + }else { + String msg = response.message(); + int code = response.code(); + Log.println(Log.ERROR,"error",String.valueOf(code)+" "+msg); + } + } + }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_register); + user = findViewById(R.id.user_register); + passwd = findViewById(R.id.Pwd_register); + role = findViewById(R.id.Role_register); + register = findViewById(R.id.button_register); + + register.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + RegisterIn(); + } + }); + } + void RegisterIn(){ + String username = String.valueOf(user.getText()); + String password = String.valueOf(passwd.getText()); + String rol = String.valueOf(role.getText()); + Log.println(Log.INFO,"username",String.valueOf(username)); + + new Thread(new Runnable() { + @Override + public void run() { + + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + JSONObject jsonObject = new JSONObject(); + Log.println(Log.ERROR,"jsontest","this is"); + try { + jsonObject.put("password",password); + jsonObject.put("roleId",Integer.valueOf(rol)); + jsonObject.put("userName",username); + } catch (JSONException e) { + e.printStackTrace(); + } + String json = "password"+password+","+"roleId"+rol+","+"userName"+username; + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), String.valueOf(jsonObject)); + Request request1 = new Request.Builder().url(Constans.ReqUrl+Constans.userrigister).headers(Headers.of(map1)) + .post(requestBody) + .build(); + + try { + OkHttpClient client = new OkHttpClient(); + client.newCall(request1).enqueue(callback); + }catch (NetworkOnMainThreadException e){ + e.printStackTrace(); + Log.println(Log.ERROR,"error","error"); + } + } + }).start(); + + + + } +} \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/ResponseData.java b/COURCE/app/src/main/java/com/example/cource/ResponseData.java new file mode 100644 index 0000000..e89182a --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/ResponseData.java @@ -0,0 +1,40 @@ +package com.example.cource; + +public class ResponseData { + private T records; + private int total; + private int size; + private int current; + + public T getRecords() { + return records; + } + + public void setRecords(T records) { + this.records = records; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public int getCurrent() { + return current; + } + + public void setCurrent(int current) { + this.current = current; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/SignAdapter.java b/COURCE/app/src/main/java/com/example/cource/SignAdapter.java new file mode 100644 index 0000000..bb3ffe2 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/SignAdapter.java @@ -0,0 +1,57 @@ +package com.example.cource; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.List; + +public class SignAdapter extends ArrayAdapter { + private List records; + private Context mContext; + private int resourseId; + public SignAdapter(Context context,int resourseId,List recordList){ + + super(context,resourseId,recordList); + this.mContext = context; + this.records=recordList; + this.resourseId = resourseId; + } + + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + signInfo r = getItem(position); + View view; + + final ViewHolder vh; + if(convertView==null){ + view = LayoutInflater.from(getContext()).inflate(resourseId,parent,false); + vh= new ViewHolder(); + vh.name = view.findViewById(R.id.college); + vh.course_id = view.findViewById(R.id.name_course); + vh.courseNum = view.findViewById(R.id.id_course); + view.setTag(vh); + }else{ + view = convertView; + vh = (ViewHolder) view.getTag(); + } + + vh.course_id.setText("课程ID:"+Long.toString(r.getCourseId())); + vh.courseNum.setText(Integer.toString(r.getCourseNum())); + vh.name.setText(r.getCourseName()); + + return view; + } + class ViewHolder{ + TextView name; + TextView course_id; + TextView courseNum; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/SignAdapterStudent.java b/COURCE/app/src/main/java/com/example/cource/SignAdapterStudent.java new file mode 100644 index 0000000..5278e51 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/SignAdapterStudent.java @@ -0,0 +1,57 @@ +package com.example.cource; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.List; + +public class SignAdapterStudent extends ArrayAdapter { + private List records; + private Context mContext; + private int resourseId; + public SignAdapterStudent(Context context,int resourseId,List recordList){ + + super(context,resourseId,recordList); + this.mContext = context; + this.records=recordList; + this.resourseId = resourseId; + } + + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + SignInfo_student r = getItem(position); + View view; + + final ViewHolder vh; + if(convertView==null){ + view = LayoutInflater.from(getContext()).inflate(resourseId,parent,false); + vh= new ViewHolder(); + vh.name = view.findViewById(R.id.name_course); + vh.college = view.findViewById(R.id.college); + vh.course_id = view.findViewById(R.id.id_course); + view.setTag(vh); + }else{ + view = convertView; + vh = (ViewHolder) view.getTag(); + } + + vh.course_id.setText(r.getCourseAddr()); + vh.college.setText("用户签到id:"+r.getUserSignId()); + vh.name.setText(r.getCourseName()); + + return view; + } + class ViewHolder{ + TextView name; + TextView course_id; + TextView college; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/SignInfo_student.java b/COURCE/app/src/main/java/com/example/cource/SignInfo_student.java new file mode 100644 index 0000000..1548cef --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/SignInfo_student.java @@ -0,0 +1,41 @@ +package com.example.cource; + +public class SignInfo_student { + + private String courseName; + private String courseAddr; + private String createTime; + private String userSignId; + + public String getCourseName() { + return courseName; + } + + public void setCourseName(String courseName) { + this.courseName = courseName; + } + + public String getCourseAddr() { + return courseAddr; + } + + public void setCourseAddr(String courseAddr) { + this.courseAddr = courseAddr; + } + + public String getCreateTime() { + return createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + + public String getUserSignId() { + return userSignId; + } + + public void setUserSignId(String userSignId) { + this.userSignId = userSignId; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/Sign_CreateActivity.java b/COURCE/app/src/main/java/com/example/cource/Sign_CreateActivity.java new file mode 100644 index 0000000..c74033b --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/Sign_CreateActivity.java @@ -0,0 +1,137 @@ +package com.example.cource; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.os.NetworkOnMainThreadException; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.text.SimpleDateFormat; +import java.util.HashMap; +import java.util.Locale; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class Sign_CreateActivity extends AppCompatActivity { + + private Long startTime,terminalTime; + private Button add_button; + private EditText beginT,endT,Addr,sign; + private String courseAddr,courseName; + private int signCode,courseId,total; + private Long beginTime,endTime,userId; + private Callback callback = new Callback() { + @Override + public void onFailure(Call call, IOException e) { + Log.e("TAG","Failed to connect server!"); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if(response.isSuccessful()){ + final String body = response.body().string(); + Log.println(Log.INFO,"OK",body); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken>(){}.getType(); + BaseRespone newUserResponse = gson.fromJson(body,jsonType); + String u= newUserResponse.getData(); + int c = newUserResponse.getCode(); + if (c==200){ + Log.println(Log.INFO,"code",Integer.toString(c)); + Toast.makeText(getApplicationContext(),"发起成功",Toast.LENGTH_SHORT).show(); + }else Toast.makeText(getApplicationContext(),"发起签到失败",Toast.LENGTH_SHORT).show(); + } + }); + } + } + }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_sign_create); + Intent intent = getIntent(); + courseName = intent.getStringExtra("courseName"); + courseId=intent.getIntExtra("courseId",0); + userId=intent.getLongExtra("userId",0); + beginT=findViewById(R.id.beginTime); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒", Locale.getDefault()); + startTime = System.currentTimeMillis(); + terminalTime = startTime+300000; + beginT.setText(simpleDateFormat.format(startTime)); + endT=findViewById(R.id.ed_endtime); + endT.setText(simpleDateFormat.format(terminalTime)); + Addr = findViewById(R.id.courseAddr); + sign = findViewById(R.id.signcode); + add_button = findViewById(R.id.add_button); + Log.println(Log.INFO,"userId",Long.toString(userId)); + Log.println(Log.INFO,"courseId",Long.toString(courseId)); + + add_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + add_sign(); + } + }); + } + void add_sign(){ + new Thread(new Runnable() { + @Override + public void run() { + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + JSONObject jsonObject = new JSONObject(); + Log.println(Log.ERROR,"jsontest","this is"); + try { + jsonObject.put("courseName",courseName); + jsonObject.put("userId",userId); + jsonObject.put("courseId",courseId); + jsonObject.put("courseAddr",Addr.getText().toString()); + jsonObject.put("beginTime",startTime); + jsonObject.put("endTime",terminalTime); + jsonObject.put("signCode",sign.getText().toString()); + jsonObject.put("total",99); + } catch (JSONException e) { + e.printStackTrace(); + } + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"),String.valueOf(jsonObject)); + Request request = new Request.Builder().url(Constans.ReqUrl+Constans.teacherinitiate) + .headers(Headers.of(map1)) + .post(requestBody) + .build(); + try { + OkHttpClient client = new OkHttpClient(); + client.newCall(request).enqueue(callback); + }catch (NetworkOnMainThreadException ex){ + ex.printStackTrace(); + } + } + }).start(); + } +} \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/Sign_inActivity.java b/COURCE/app/src/main/java/com/example/cource/Sign_inActivity.java new file mode 100644 index 0000000..afc272c --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/Sign_inActivity.java @@ -0,0 +1,126 @@ +package com.example.cource; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.os.NetworkOnMainThreadException; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.List; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class Sign_inActivity extends AppCompatActivity { + + private Long userId; + private String signCode; + private EditText ed_sign,userSignId; + private Button bt_sign; + private final Callback callback=new okhttp3.Callback() { + + @Override + public void onFailure(Call call, IOException e) { + Log.e("TAG", "Failed to connect server!"); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if (response.isSuccessful()) { + final String body = response.body().string(); + Log.println(Log.INFO, "OK", body); + runOnUiThread(new Runnable() { + @Override + public void run() { + Gson gson = new Gson(); + Type jsonType = new TypeToken>() {}.getType(); + BaseRespone newUserResponse = gson.fromJson(body, jsonType); + int code = newUserResponse.getCode(); + if (code==200){ + Toast.makeText(getApplicationContext(),"签到成功",Toast.LENGTH_SHORT).show(); + }else { + Toast.makeText(getApplicationContext(),"签到失败",Toast.LENGTH_SHORT).show(); + } + } + }); + } else { + String msg = response.message(); + int code = response.code(); + Log.println(Log.ERROR, "error", String.valueOf(code) + " " + msg); + } + } + }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_sign_in); + Intent intent = getIntent(); + userId = intent.getLongExtra("userId",0); + userSignId = findViewById(R.id.userSignId); + ed_sign = findViewById(R.id.Edit_Signcode); + bt_sign =findViewById(R.id.Bt_sign_in); + bt_sign.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + sign_in(); + } + }); + } + void sign_in(){ + new Thread(new Runnable() { + @Override + public void run() { + + HashMap map1 = new HashMap(); + map1.put("Accept",Constans.Accept); + map1.put("Content-Type",Constans.Content_Type); + map1.put("appId",Constans.appId); + map1.put("appSecret",Constans.appSecret); + + JSONObject jsonObject = new JSONObject(); + try { + jsonObject.put("signCode",ed_sign.getText().toString()); + jsonObject.put("userId",userId); + jsonObject.put("userSignId",userSignId.getText().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + + RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"),String.valueOf(jsonObject)); + Request request1 = new Request.Builder().url(Constans.ReqUrl+Constans.studentsign) + .headers(Headers.of(map1)) + .post(requestBody) + .build(); + + try { + OkHttpClient client = new OkHttpClient(); + client.newCall(request1).enqueue(callback); + }catch (NetworkOnMainThreadException e){ + e.printStackTrace(); + Log.println(Log.ERROR,"error","error"); + } + } + }).start(); + } +} \ No newline at end of file diff --git a/COURCE/app/src/main/java/com/example/cource/UserRequest.java b/COURCE/app/src/main/java/com/example/cource/UserRequest.java new file mode 100644 index 0000000..1ddc927 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/UserRequest.java @@ -0,0 +1,43 @@ +package com.example.cource; + +public class UserRequest { + private String username; + private String password; + private int roleId; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public String toString() { + String retvalue; + retvalue = "?"+"password="+password+"&username="+username; + return retvalue; + } + + public String toRegisterString(){ + String retvalue; + retvalue = "?"+"password="+password+"&username="+username+"&roleId="+roleId; + return retvalue; + } + public int getRoleId() { + return roleId; + } + + public void setRoleId(int roleId) { + this.roleId = roleId; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/Userinfo.java b/COURCE/app/src/main/java/com/example/cource/Userinfo.java new file mode 100644 index 0000000..dd70145 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/Userinfo.java @@ -0,0 +1,133 @@ +package com.example.cource; + + + +public class Userinfo { + private long id; + private String appKey; + private String userName; + private String roleId; + private String realName; + private long idNumber; + private String collegeName; + private boolean gender=true; + private String phone; + private String email; + private String avatar; + private String inSchoolTime; + private String createTime; + private String lastUpdateTime; + + public String getCollegeName() { + return collegeName; + } + + public void setCollegeName(String collegeName) { + this.collegeName = collegeName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public boolean isGender() { + return gender; + } + + public void setGender(boolean gender) { + this.gender = gender; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getIdNumber() { + return idNumber; + } + + public void setIdNumber(long idNumber) { + this.idNumber = idNumber; + } + + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getRealName() { + return realName; + } + + public void setRealName(String realName) { + this.realName = realName; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getRoleId() { + return roleId; + } + + public void setRoleId(String roleId) { + this.roleId = roleId; + } + + public String getAppKey() { + return appKey; + } + + public void setAppKey(String appKey) { + this.appKey = appKey; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public void setInSchoolTime(String inSchoolTime) { + this.inSchoolTime = inSchoolTime; + } + + public String getCreateTime() { + return createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + + public String getLastUpdateTime() { + return lastUpdateTime; + } + + public void setLastUpdateTime(String lastUpdateTime) { + this.lastUpdateTime = lastUpdateTime; + } + + public String getAvatar() { + return avatar; + } + + public String getInSchoolTime() { + return inSchoolTime; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/record.java b/COURCE/app/src/main/java/com/example/cource/record.java new file mode 100644 index 0000000..32b3d19 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/record.java @@ -0,0 +1,40 @@ +package com.example.cource; + +public class record { + private int courseId; + private String courseName; + private String coursePhoto; + private String collegeName; + + public int getCourseId() { + return courseId; + } + + public void setCourseId(int courseId) { + this.courseId = courseId; + } + + public String getCourseName() { + return courseName; + } + + public void setCourseName(String courseName) { + this.courseName = courseName; + } + + public String getCoursePhoto() { + return coursePhoto; + } + + public void setCoursePhoto(String coursePhoto) { + this.coursePhoto = coursePhoto; + } + + public String getCollegeName() { + return collegeName; + } + + public void setCollegeName(String collegeName) { + this.collegeName = collegeName; + } +} diff --git a/COURCE/app/src/main/java/com/example/cource/signInfo.java b/COURCE/app/src/main/java/com/example/cource/signInfo.java new file mode 100644 index 0000000..bb65129 --- /dev/null +++ b/COURCE/app/src/main/java/com/example/cource/signInfo.java @@ -0,0 +1,33 @@ +package com.example.cource; + +public class signInfo { + private String courseName; + private Long courseId; + private int courseNum; + + public String getCourseName() { + return courseName; + } + + public void setCourseName(String courseName) { + this.courseName = courseName; + } + + public Long getCourseId() { + return courseId; + } + + public void setCourseId(Long courseId) { + this.courseId = courseId; + } + + public int getCourseNum() { + return courseNum; + } + + public void setCourseNum(int courseNum) { + this.courseNum = courseNum; + } + + +} diff --git a/COURCE/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/COURCE/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/COURCE/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/COURCE/app/src/main/res/drawable/add.png b/COURCE/app/src/main/res/drawable/add.png new file mode 100644 index 0000000..314f402 Binary files /dev/null and b/COURCE/app/src/main/res/drawable/add.png differ diff --git a/COURCE/app/src/main/res/drawable/group.png b/COURCE/app/src/main/res/drawable/group.png new file mode 100644 index 0000000..94643bd Binary files /dev/null and b/COURCE/app/src/main/res/drawable/group.png differ diff --git a/COURCE/app/src/main/res/drawable/group1.png b/COURCE/app/src/main/res/drawable/group1.png new file mode 100644 index 0000000..a3e0715 Binary files /dev/null and b/COURCE/app/src/main/res/drawable/group1.png differ diff --git a/COURCE/app/src/main/res/drawable/ic_baseline_add_circle_outline_24.xml b/COURCE/app/src/main/res/drawable/ic_baseline_add_circle_outline_24.xml new file mode 100644 index 0000000..ece998d --- /dev/null +++ b/COURCE/app/src/main/res/drawable/ic_baseline_add_circle_outline_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/COURCE/app/src/main/res/drawable/ic_baseline_lock_24.xml b/COURCE/app/src/main/res/drawable/ic_baseline_lock_24.xml new file mode 100644 index 0000000..ff65e27 --- /dev/null +++ b/COURCE/app/src/main/res/drawable/ic_baseline_lock_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/COURCE/app/src/main/res/drawable/ic_baseline_lock_open_24.xml b/COURCE/app/src/main/res/drawable/ic_baseline_lock_open_24.xml new file mode 100644 index 0000000..0e8905c --- /dev/null +++ b/COURCE/app/src/main/res/drawable/ic_baseline_lock_open_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/COURCE/app/src/main/res/drawable/ic_baseline_person_24.xml b/COURCE/app/src/main/res/drawable/ic_baseline_person_24.xml new file mode 100644 index 0000000..ccfe46a --- /dev/null +++ b/COURCE/app/src/main/res/drawable/ic_baseline_person_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/COURCE/app/src/main/res/drawable/ic_launcher_background.xml b/COURCE/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/COURCE/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/COURCE/app/src/main/res/drawable/introduction.png b/COURCE/app/src/main/res/drawable/introduction.png new file mode 100644 index 0000000..595bc63 Binary files /dev/null and b/COURCE/app/src/main/res/drawable/introduction.png differ diff --git a/COURCE/app/src/main/res/drawable/member.png b/COURCE/app/src/main/res/drawable/member.png new file mode 100644 index 0000000..a28e1fa Binary files /dev/null and b/COURCE/app/src/main/res/drawable/member.png differ diff --git a/COURCE/app/src/main/res/drawable/member2.png b/COURCE/app/src/main/res/drawable/member2.png new file mode 100644 index 0000000..e03ece2 Binary files /dev/null and b/COURCE/app/src/main/res/drawable/member2.png differ diff --git a/COURCE/app/src/main/res/drawable/personal.png b/COURCE/app/src/main/res/drawable/personal.png new file mode 100644 index 0000000..9491158 Binary files /dev/null and b/COURCE/app/src/main/res/drawable/personal.png differ diff --git a/COURCE/app/src/main/res/drawable/teacher.png b/COURCE/app/src/main/res/drawable/teacher.png new file mode 100644 index 0000000..bf9275e Binary files /dev/null and b/COURCE/app/src/main/res/drawable/teacher.png differ diff --git a/COURCE/app/src/main/res/layout/activity_course.xml b/COURCE/app/src/main/res/layout/activity_course.xml new file mode 100644 index 0000000..a9d9b60 --- /dev/null +++ b/COURCE/app/src/main/res/layout/activity_course.xml @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/COURCE/app/src/main/res/layout/activity_course_create.xml b/COURCE/app/src/main/res/layout/activity_course_create.xml new file mode 100644 index 0000000..a905871 --- /dev/null +++ b/COURCE/app/src/main/res/layout/activity_course_create.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + +