Commit 937d37ac8b08ce38db5603ee0c11e407fdb9df98

Authored by shixianjie
1 parent 92afa3a05c
Exists in master

切换学生

app/src/main/java/com/hjx/parent/StuHomeworkActivity.java
... ... @@ -6,6 +6,7 @@ import android.os.Bundle;
6 6 import android.widget.LinearLayout;
7 7 import android.widget.PopupWindow;
8 8  
  9 +import androidx.annotation.Nullable;
9 10 import androidx.lifecycle.MutableLiveData;
10 11  
11 12 import com.google.gson.Gson;
... ... @@ -81,6 +82,27 @@ public class StuHomeworkActivity extends BaseRxActivity<ActivityStudentHomeworkB
81 82 intent.putExtra("student", state.student);
82 83 startActivity(intent);
83 84 };
  85 +
  86 + binding.btnChangeStudent.setOnClickListener(v -> {
  87 + Intent intent = new Intent(this, TeacherChooseActivity.class);
  88 + intent.putExtra("needBack", true);
  89 + startActivityForResult(intent, 0xA01);
  90 + });
  91 + }
  92 +
  93 + @SuppressLint("SetTextI18n")
  94 + @Override
  95 + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  96 + super.onActivityResult(requestCode, resultCode, data);
  97 + if (requestCode == 0xA01 && resultCode == RESULT_OK) {
  98 + String json = (String) SharedPreferencesUtil.getData("student", "");
  99 + try {
  100 + state.student = new Gson().fromJson(json, Student.class);
  101 + binding.tvTitle.setText(state.student.stuName + "的全部作业");
  102 + getHomework();
  103 + }
  104 + catch (Throwable t) { t.printStackTrace(); }
  105 + }
84 106 }
85 107  
86 108 @SuppressLint("CheckResult")
... ...
app/src/main/java/com/hjx/parent/TeacherChooseActivity.java
... ... @@ -185,6 +185,7 @@ public class TeacherChooseActivity extends BaseActivity {
185 185 SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean));
186 186 startActivity(intent);
187 187 }
  188 + setResult(RESULT_OK);
188 189 finish();
189 190 }
190 191 }
... ...
app/src/main/res/drawable/png_ic_change_student.png

2.88 KB

app/src/main/res/layout/activity_student_homework.xml
... ... @@ -24,6 +24,13 @@
24 24 android:layout_gravity="center"
25 25 android:layout_width="wrap_content"
26 26 android:layout_height="wrap_content"/>
  27 + <ImageView
  28 + android:id="@+id/btnChangeStudent"
  29 + android:src="@drawable/png_ic_change_student"
  30 + android:layout_gravity="end"
  31 + android:layout_marginEnd="24dp"
  32 + android:layout_width="20dp"
  33 + android:layout_height="20dp"/>
27 34 </androidx.appcompat.widget.Toolbar>
28 35 <LinearLayout
29 36 android:orientation="horizontal"
... ...