Commit 32434bc9c6e1d83dffc96b03d464b9a837b60d76
1 parent
0b06f873f3
Exists in
master
全屏查看图片
Showing
5 changed files
with
99 additions
and
0 deletions
Show diff stats
app/build.gradle
| 1 | apply plugin: 'com.android.application' | 1 | apply plugin: 'com.android.application' |
| 2 | apply from: '../config.gradle' | 2 | apply from: '../config.gradle' |
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | def androidId = rootProject.ext.androidId | 5 | def androidId = rootProject.ext.androidId |
| 6 | def support = rootProject.ext.dependencies | 6 | def support = rootProject.ext.dependencies |
| 7 | def url = rootProject.ext.url | 7 | def url = rootProject.ext.url |
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | android { | 10 | android { |
| 11 | signingConfigs { | 11 | signingConfigs { |
| 12 | 12 | ||
| 13 | config { | 13 | config { |
| 14 | keyAlias 'alias' | 14 | keyAlias 'alias' |
| 15 | keyPassword '123456' | 15 | keyPassword '123456' |
| 16 | storeFile file('key.jks') | 16 | storeFile file('key.jks') |
| 17 | storePassword '123456' | 17 | storePassword '123456' |
| 18 | } | 18 | } |
| 19 | debug { | 19 | debug { |
| 20 | } | 20 | } |
| 21 | } | 21 | } |
| 22 | compileSdk 32 | 22 | compileSdk 32 |
| 23 | 23 | ||
| 24 | defaultConfig { | 24 | defaultConfig { |
| 25 | applicationId "com.hjx.parent" | 25 | applicationId "com.hjx.parent" |
| 26 | minSdk 26 | 26 | minSdk 26 |
| 27 | targetSdk 32 | 27 | targetSdk 32 |
| 28 | versionCode 1005 | 28 | versionCode 1005 |
| 29 | versionName "1.0.0.5" | 29 | versionName "1.0.0.5" |
| 30 | 30 | ||
| 31 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | 31 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | android.applicationVariants.all { | 34 | android.applicationVariants.all { |
| 35 | variant -> | 35 | variant -> |
| 36 | variant.outputs.all { | 36 | variant.outputs.all { |
| 37 | //在这里修改apk文件名 | 37 | //在这里修改apk文件名 |
| 38 | outputFileName = "parent-${variant.name}-v${variant.versionName}.apk" | 38 | outputFileName = "parent-${variant.name}-v${variant.versionName}.apk" |
| 39 | } | 39 | } |
| 40 | } | 40 | } |
| 41 | buildTypes { | 41 | buildTypes { |
| 42 | debug { | 42 | debug { |
| 43 | debuggable true | 43 | debuggable true |
| 44 | minifyEnabled false | 44 | minifyEnabled false |
| 45 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 45 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 46 | signingConfig signingConfigs.config | 46 | signingConfig signingConfigs.config |
| 47 | } | 47 | } |
| 48 | release { | 48 | release { |
| 49 | debuggable true | 49 | debuggable true |
| 50 | minifyEnabled false | 50 | minifyEnabled false |
| 51 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 51 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 52 | signingConfig signingConfigs.config | 52 | signingConfig signingConfigs.config |
| 53 | } | 53 | } |
| 54 | } | 54 | } |
| 55 | lintOptions { | 55 | lintOptions { |
| 56 | checkReleaseBuilds false | 56 | checkReleaseBuilds false |
| 57 | abortOnError false | 57 | abortOnError false |
| 58 | } | 58 | } |
| 59 | buildFeatures { | 59 | buildFeatures { |
| 60 | viewBinding true | 60 | viewBinding true |
| 61 | dataBinding true | 61 | dataBinding true |
| 62 | } | 62 | } |
| 63 | compileOptions { | 63 | compileOptions { |
| 64 | sourceCompatibility JavaVersion.VERSION_1_8 | 64 | sourceCompatibility JavaVersion.VERSION_1_8 |
| 65 | targetCompatibility JavaVersion.VERSION_1_8 | 65 | targetCompatibility JavaVersion.VERSION_1_8 |
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | dependencies { | 69 | dependencies { |
| 70 | support.each { k, v -> implementation v } | 70 | support.each { k, v -> implementation v } |
| 71 | api project(path: ':libs:common') | 71 | api project(path: ':libs:common') |
| 72 | implementation 'androidx.appcompat:appcompat:1.5.1' | 72 | implementation 'androidx.appcompat:appcompat:1.5.1' |
| 73 | implementation 'com.google.android.material:material:1.6.1' | 73 | implementation 'com.google.android.material:material:1.6.1' |
| 74 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | 74 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' |
| 75 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50' | 75 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50' |
| 76 | implementation 'com.github.ForgetAll:LoadingDialog:1.1.2' | 76 | implementation 'com.github.ForgetAll:LoadingDialog:1.1.2' |
| 77 | implementation 'com.github.DL-ZhangTeng:ImagePicker:1.5.0' | 77 | implementation 'com.github.DL-ZhangTeng:ImagePicker:1.5.0' |
| 78 | //使用的三方 | 78 | //使用的三方 |
| 79 | implementation 'com.yalantis:ucrop:2.2.0' | 79 | implementation 'com.yalantis:ucrop:2.2.0' |
| 80 | implementation 'com.github.DL-ZhangTeng:RequestPermission:1.3.0' | 80 | implementation 'com.github.DL-ZhangTeng:RequestPermission:1.3.0' |
| 81 | implementation 'com.github.DL-ZhangTeng:Utils:2.2.0' | 81 | implementation 'com.github.DL-ZhangTeng:Utils:2.2.0' |
| 82 | 82 | ||
| 83 | // rx | 83 | // rx |
| 84 | implementation("com.trello.rxlifecycle2:rxlifecycle:2.2.2") | 84 | implementation("com.trello.rxlifecycle2:rxlifecycle:2.2.2") |
| 85 | implementation("com.trello.rxlifecycle2:rxlifecycle-android:2.2.2") | 85 | implementation("com.trello.rxlifecycle2:rxlifecycle-android:2.2.2") |
| 86 | 86 | ||
| 87 | implementation("com.github.PhilJay:MPAndroidChart:v3.1.0") | 87 | implementation("com.github.PhilJay:MPAndroidChart:v3.1.0") |
| 88 | implementation("com.contrarywind:Android-PickerView:4.1.9") | 88 | implementation("com.contrarywind:Android-PickerView:4.1.9") |
| 89 | 89 | ||
| 90 | implementation 'com.google.android:flexbox:1.0.0' | 90 | implementation 'com.google.android:flexbox:1.0.0' |
| 91 | 91 | ||
| 92 | // 沉浸式状态栏和他的Kotlin拓展 | 92 | // 沉浸式状态栏和他的Kotlin拓展 |
| 93 | implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2' | 93 | implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2' |
| 94 | implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2' | 94 | implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2' |
| 95 | 95 | ||
| 96 | // 图片查看 | ||
| 97 | implementation 'com.github.chrisbanes:PhotoView:2.0.0' | ||
| 96 | } | 98 | } |
app/src/main/java/com/hjx/parent/HomeworkShareActivity.java
| 1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
| 2 | 2 | ||
| 3 | import android.annotation.SuppressLint; | 3 | import android.annotation.SuppressLint; |
| 4 | import android.content.Intent; | 4 | import android.content.Intent; |
| 5 | import android.graphics.Bitmap; | 5 | import android.graphics.Bitmap; |
| 6 | import android.net.Uri; | 6 | import android.net.Uri; |
| 7 | import android.os.Bundle; | 7 | import android.os.Bundle; |
| 8 | import android.text.Html; | 8 | import android.text.Html; |
| 9 | import android.view.View; | 9 | import android.view.View; |
| 10 | import android.widget.ImageView; | 10 | import android.widget.ImageView; |
| 11 | import android.widget.LinearLayout; | 11 | import android.widget.LinearLayout; |
| 12 | import android.widget.TextView; | 12 | import android.widget.TextView; |
| 13 | 13 | ||
| 14 | import androidx.annotation.NonNull; | 14 | import androidx.annotation.NonNull; |
| 15 | 15 | ||
| 16 | import com.bumptech.glide.Glide; | 16 | import com.bumptech.glide.Glide; |
| 17 | import com.chad.library.adapter.base.BaseQuickAdapter; | 17 | import com.chad.library.adapter.base.BaseQuickAdapter; |
| 18 | import com.chad.library.adapter.base.BaseViewHolder; | 18 | import com.chad.library.adapter.base.BaseViewHolder; |
| 19 | import com.google.gson.Gson; | 19 | import com.google.gson.Gson; |
| 20 | import com.gyf.immersionbar.ImmersionBar; | 20 | import com.gyf.immersionbar.ImmersionBar; |
| 21 | import com.hjx.parent.databinding.ActivityHomeworkShareBinding; | 21 | import com.hjx.parent.databinding.ActivityHomeworkShareBinding; |
| 22 | import com.hjx.parent.dialog.PhotoViewDialog; | ||
| 22 | import com.hjx.parent.rx.BaseRxActivity; | 23 | import com.hjx.parent.rx.BaseRxActivity; |
| 23 | import com.prws.common.bean.ResponseResult; | 24 | import com.prws.common.bean.ResponseResult; |
| 24 | import com.prws.common.bean.Student; | 25 | import com.prws.common.bean.Student; |
| 25 | import com.prws.common.bean.homework.HomeWork; | 26 | import com.prws.common.bean.homework.HomeWork; |
| 26 | import com.prws.common.bean.homework.HomeworkDetail; | 27 | import com.prws.common.bean.homework.HomeworkDetail; |
| 27 | import com.prws.common.bean.homework.KeyValue; | 28 | import com.prws.common.bean.homework.KeyValue; |
| 28 | import com.prws.common.net.NetWorks; | 29 | import com.prws.common.net.NetWorks; |
| 29 | import com.prws.common.utils.BitmapUtils; | 30 | import com.prws.common.utils.BitmapUtils; |
| 30 | import com.prws.common.utils.CommonUtil; | 31 | import com.prws.common.utils.CommonUtil; |
| 31 | import com.prws.common.utils.ContentUtil; | 32 | import com.prws.common.utils.ContentUtil; |
| 32 | 33 | ||
| 33 | import java.text.DecimalFormat; | 34 | import java.text.DecimalFormat; |
| 34 | import java.text.SimpleDateFormat; | 35 | import java.text.SimpleDateFormat; |
| 35 | import java.util.ArrayList; | 36 | import java.util.ArrayList; |
| 36 | import java.util.HashSet; | 37 | import java.util.HashSet; |
| 37 | import java.util.List; | 38 | import java.util.List; |
| 38 | import java.util.Locale; | 39 | import java.util.Locale; |
| 39 | import java.util.Set; | 40 | import java.util.Set; |
| 40 | 41 | ||
| 41 | import io.reactivex.Single; | 42 | import io.reactivex.Single; |
| 42 | import io.reactivex.android.schedulers.AndroidSchedulers; | 43 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 43 | import io.reactivex.schedulers.Schedulers; | 44 | import io.reactivex.schedulers.Schedulers; |
| 44 | 45 | ||
| 45 | public class HomeworkShareActivity extends BaseRxActivity<ActivityHomeworkShareBinding> { | 46 | public class HomeworkShareActivity extends BaseRxActivity<ActivityHomeworkShareBinding> { |
| 46 | private String id; | 47 | private String id; |
| 47 | 48 | ||
| 48 | String indent = " "; | 49 | String indent = " "; |
| 49 | 50 | ||
| 50 | private String title; | 51 | private String title; |
| 51 | private Student student; | 52 | private Student student; |
| 52 | private ErrorAdapter mAdapter = new ErrorAdapter(); | 53 | private ErrorAdapter mAdapter = new ErrorAdapter(); |
| 53 | 54 | ||
| 54 | private Uri shareUri; | 55 | private Uri shareUri; |
| 55 | 56 | ||
| 56 | @SuppressLint("SetTextI18n") | 57 | @SuppressLint("SetTextI18n") |
| 57 | @Override | 58 | @Override |
| 58 | public void initView(Bundle savedInstanceState) { | 59 | public void initView(Bundle savedInstanceState) { |
| 59 | ImmersionBar.with(this).init(); | 60 | ImmersionBar.with(this).init(); |
| 60 | binding.btnBack.setOnClickListener(v -> onBackPressed()); | 61 | binding.btnBack.setOnClickListener(v -> onBackPressed()); |
| 61 | binding.rvWrong.setAdapter(mAdapter); | 62 | binding.rvWrong.setAdapter(mAdapter); |
| 62 | mAdapter.setEmptyView(R.layout.empty_statistical_no_error, binding.rvWrong); | 63 | mAdapter.setEmptyView(R.layout.empty_statistical_no_error, binding.rvWrong); |
| 63 | 64 | ||
| 64 | id = getIntent().getStringExtra("id"); | 65 | id = getIntent().getStringExtra("id"); |
| 65 | title = getIntent().getStringExtra("name"); | 66 | title = getIntent().getStringExtra("name"); |
| 66 | binding.tvTitle.setText(title); | 67 | binding.tvTitle.setText(title); |
| 67 | student = (Student) getIntent().getSerializableExtra("student"); | 68 | student = (Student) getIntent().getSerializableExtra("student"); |
| 68 | assert student != null; | 69 | assert student != null; |
| 69 | binding.tvName.setText(student.stuName); | 70 | binding.tvName.setText(student.stuName); |
| 70 | Glide.with(this).load(student.photo).centerCrop().error(R.mipmap.ic_avatar_male).into(binding.ivAvatar); | 71 | Glide.with(this).load(student.photo).centerCrop().error(R.mipmap.ic_avatar_male).into(binding.ivAvatar); |
| 71 | binding.tvGrade.setText("学员年级:" + getIntent().getStringExtra("grade")); | 72 | binding.tvGrade.setText("学员年级:" + getIntent().getStringExtra("grade")); |
| 72 | binding.tvSubject.setText("作业科目:" + getIntent().getStringExtra("subject")); | 73 | binding.tvSubject.setText("作业科目:" + getIntent().getStringExtra("subject")); |
| 73 | 74 | ||
| 74 | binding.btnShare.setOnClickListener(v -> { | 75 | binding.btnShare.setOnClickListener(v -> { |
| 75 | if (shareUri == null) shareUri = saveBitmap(); | 76 | if (shareUri == null) shareUri = saveBitmap(); |
| 76 | if (shareUri != null) { | 77 | if (shareUri != null) { |
| 77 | Intent shareIntent = new Intent(Intent.ACTION_SEND); | 78 | Intent shareIntent = new Intent(Intent.ACTION_SEND); |
| 78 | shareIntent.setType("image/jpeg"); | 79 | shareIntent.setType("image/jpeg"); |
| 79 | shareIntent.putExtra(Intent.EXTRA_STREAM, shareUri); | 80 | shareIntent.putExtra(Intent.EXTRA_STREAM, shareUri); |
| 80 | shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 81 | shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
| 81 | 82 | ||
| 82 | startActivity(shareIntent); | 83 | startActivity(shareIntent); |
| 83 | } | 84 | } |
| 84 | }); | 85 | }); |
| 85 | 86 | ||
| 86 | loadHomework(); | 87 | loadHomework(); |
| 87 | } | 88 | } |
| 88 | 89 | ||
| 89 | @SuppressLint("CheckResult") | 90 | @SuppressLint("CheckResult") |
| 90 | private void loadHomework() { | 91 | private void loadHomework() { |
| 91 | NetWorks.service_url.getHomeworkCompleteDetail(NetWorks.getHeader(), student.stuId, id, true) | 92 | NetWorks.service_url.getHomeworkCompleteDetail(NetWorks.getHeader(), student.stuId, id, true) |
| 92 | .compose(transformSingle()) | 93 | .compose(transformSingle()) |
| 93 | .map(ResponseResult::getData) | 94 | .map(ResponseResult::getData) |
| 94 | .map(data -> { | 95 | .map(data -> { |
| 95 | if (data.getHomeworkList() == null) return data; | 96 | if (data.getHomeworkList() == null) return data; |
| 96 | for (HomeWork homeWork: data.getHomeworkList()){ | 97 | for (HomeWork homeWork: data.getHomeworkList()){ |
| 97 | homeWork.formatPoints(new Gson()); | 98 | homeWork.formatPoints(new Gson()); |
| 98 | } | 99 | } |
| 99 | return data; | 100 | return data; |
| 100 | }) | 101 | }) |
| 101 | .subscribe((data, th) -> { | 102 | .subscribe((data, th) -> { |
| 102 | if (th != null) th.printStackTrace(); | 103 | if (th != null) th.printStackTrace(); |
| 103 | if (data != null) showHomework(data); | 104 | if (data != null) showHomework(data); |
| 104 | }); | 105 | }); |
| 105 | } | 106 | } |
| 106 | @SuppressLint({"SetTextI18n", "DefaultLocale"}) | 107 | @SuppressLint({"SetTextI18n", "DefaultLocale"}) |
| 107 | private void showHomework(HomeworkDetail detail) { | 108 | private void showHomework(HomeworkDetail detail) { |
| 108 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); | 109 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); |
| 109 | binding.tvDate.setText("作业时间:" + format.format(detail.getDate())); | 110 | binding.tvDate.setText("作业时间:" + format.format(detail.getDate())); |
| 110 | binding.flComment.setVisibility(detail.getComment() == null || detail.getComment().isEmpty() ? View.INVISIBLE : View.VISIBLE); | 111 | binding.flComment.setVisibility(detail.getComment() == null || detail.getComment().isEmpty() ? View.INVISIBLE : View.VISIBLE); |
| 111 | binding.tvComment.setText(ifEmpty(detail.getComment(), "-")); | 112 | binding.tvComment.setText(ifEmpty(detail.getComment(), "-")); |
| 112 | binding.tvRating.setText("-"); | 113 | binding.tvRating.setText("-"); |
| 113 | 114 | ||
| 114 | String temp = indent + "在本次作业中,答对题目有 %s 道,%s掌握的很好;答错题目有 %s 道,错题涵盖的知识点主要有%s,这部分还要再加强学习。错题老师已经帮你收录到错题本中,要记得复习整理错题,及时消灭薄弱知识点。"; | 115 | String temp = indent + "在本次作业中,答对题目有 %s 道,%s掌握的很好;答错题目有 %s 道,错题涵盖的知识点主要有%s,这部分还要再加强学习。错题老师已经帮你收录到错题本中,要记得复习整理错题,及时消灭薄弱知识点。"; |
| 115 | List<HomeWork> errorList = new ArrayList<>(); | 116 | List<HomeWork> errorList = new ArrayList<>(); |
| 116 | if (detail.getHomeworkList() != null && detail.getHomeworkList().size() != 0) { | 117 | if (detail.getHomeworkList() != null && detail.getHomeworkList().size() != 0) { |
| 117 | int total = detail.getHomeworkList().size(); | 118 | int total = detail.getHomeworkList().size(); |
| 118 | int correctNum = 0; | 119 | int correctNum = 0; |
| 119 | Set<KeyValue> correctSet = new HashSet<>(); | 120 | Set<KeyValue> correctSet = new HashSet<>(); |
| 120 | Set<KeyValue> errorSet = new HashSet<>(); | 121 | Set<KeyValue> errorSet = new HashSet<>(); |
| 121 | for (HomeWork homeWork: detail.getHomeworkList()) { | 122 | for (HomeWork homeWork: detail.getHomeworkList()) { |
| 122 | if (homeWork.correction == 0) { | 123 | if (homeWork.correction == 0) { |
| 123 | correctNum ++; | 124 | correctNum ++; |
| 124 | correctSet.addAll(homeWork.pointsObj); | 125 | correctSet.addAll(homeWork.pointsObj); |
| 125 | } else { | 126 | } else { |
| 126 | errorList.add(homeWork); | 127 | errorList.add(homeWork); |
| 127 | errorSet.addAll(homeWork.pointsObj); | 128 | errorSet.addAll(homeWork.pointsObj); |
| 128 | } | 129 | } |
| 129 | } | 130 | } |
| 130 | StringBuilder correctPoint = new StringBuilder(); | 131 | StringBuilder correctPoint = new StringBuilder(); |
| 131 | StringBuilder errorPoint = new StringBuilder(); | 132 | StringBuilder errorPoint = new StringBuilder(); |
| 132 | for (KeyValue point: correctSet) { | 133 | for (KeyValue point: correctSet) { |
| 133 | correctPoint.append("、").append(point.Value); | 134 | correctPoint.append("、").append(point.Value); |
| 134 | } | 135 | } |
| 135 | for (KeyValue point: errorSet) { | 136 | for (KeyValue point: errorSet) { |
| 136 | errorPoint.append("、").append(point.Value); | 137 | errorPoint.append("、").append(point.Value); |
| 137 | } | 138 | } |
| 138 | float rate = 100f * correctNum / total; | 139 | float rate = 100f * correctNum / total; |
| 139 | int errorNum = total - correctNum; | 140 | int errorNum = total - correctNum; |
| 140 | binding.tvPercent.setText(new DecimalFormat("0").format(rate)); | 141 | binding.tvPercent.setText(new DecimalFormat("0").format(rate)); |
| 141 | binding.tvCorrect.setText(String.valueOf(correctNum)); | 142 | binding.tvCorrect.setText(String.valueOf(correctNum)); |
| 142 | binding.tvWrong.setText(String.valueOf(errorNum)); | 143 | binding.tvWrong.setText(String.valueOf(errorNum)); |
| 143 | 144 | ||
| 144 | String correct = "-", error = "-"; | 145 | String correct = "-", error = "-"; |
| 145 | if (correctPoint.length() != 0) correct = correctPoint.substring(1); | 146 | if (correctPoint.length() != 0) correct = correctPoint.substring(1); |
| 146 | if (errorPoint.length() != 0) error = errorPoint.substring(1); | 147 | if (errorPoint.length() != 0) error = errorPoint.substring(1); |
| 147 | if (errorNum == 0) { | 148 | if (errorNum == 0) { |
| 148 | temp = indent + "在本次作业中,答对题目有 %s 道,%s掌握的很好。"; | 149 | temp = indent + "在本次作业中,答对题目有 %s 道,%s掌握的很好。"; |
| 149 | String s = String.format(temp, | 150 | String s = String.format(temp, |
| 150 | fromColor(String.valueOf(correctNum), "#489afa"), | 151 | fromColor(String.valueOf(correctNum), "#489afa"), |
| 151 | fromColor(correct, "#489afa") | 152 | fromColor(correct, "#489afa") |
| 152 | ); | 153 | ); |
| 153 | binding.tvRating.setText(Html.fromHtml(s, Html.FROM_HTML_MODE_COMPACT)); | 154 | binding.tvRating.setText(Html.fromHtml(s, Html.FROM_HTML_MODE_COMPACT)); |
| 154 | } else { | 155 | } else { |
| 155 | String s = String.format(temp, | 156 | String s = String.format(temp, |
| 156 | fromColor(String.valueOf(correctNum), "#489afa"), | 157 | fromColor(String.valueOf(correctNum), "#489afa"), |
| 157 | fromColor(correct, "#489afa"), | 158 | fromColor(correct, "#489afa"), |
| 158 | fromColor(String.valueOf(errorNum), "#ff4134"), | 159 | fromColor(String.valueOf(errorNum), "#ff4134"), |
| 159 | fromColor(error, "#ff4134") | 160 | fromColor(error, "#ff4134") |
| 160 | ); | 161 | ); |
| 161 | binding.tvRating.setText(Html.fromHtml(s, Html.FROM_HTML_MODE_COMPACT)); | 162 | binding.tvRating.setText(Html.fromHtml(s, Html.FROM_HTML_MODE_COMPACT)); |
| 162 | } | 163 | } |
| 163 | } | 164 | } |
| 164 | 165 | ||
| 165 | mAdapter.setNewData(errorList); | 166 | mAdapter.setNewData(errorList); |
| 166 | } | 167 | } |
| 167 | 168 | ||
| 168 | private String fromColor(String str, String color) { | 169 | private String fromColor(String str, String color) { |
| 169 | return String.format("<font color='%s'>%s</font>", color, str); | 170 | return String.format("<font color='%s'>%s</font>", color, str); |
| 170 | } | 171 | } |
| 171 | 172 | ||
| 172 | @Override | 173 | @Override |
| 173 | protected ActivityHomeworkShareBinding getViewBinding() { | 174 | protected ActivityHomeworkShareBinding getViewBinding() { |
| 174 | return ActivityHomeworkShareBinding.inflate(getLayoutInflater()); | 175 | return ActivityHomeworkShareBinding.inflate(getLayoutInflater()); |
| 175 | } | 176 | } |
| 176 | 177 | ||
| 177 | private Uri saveBitmap() { | 178 | private Uri saveBitmap() { |
| 178 | try { | 179 | try { |
| 179 | Bitmap bitmap = BitmapUtils.shotView(binding.viewRoot); | 180 | Bitmap bitmap = BitmapUtils.shotView(binding.viewRoot); |
| 180 | String fileName = student.stuName + "_" + title; | 181 | String fileName = student.stuName + "_" + title; |
| 181 | return ContentUtil.saveBitmapToGallery(this, bitmap, fileName); | 182 | return ContentUtil.saveBitmapToGallery(this, bitmap, fileName); |
| 182 | } catch (Exception e) { | 183 | } catch (Exception e) { |
| 183 | e.printStackTrace(); | 184 | e.printStackTrace(); |
| 184 | } | 185 | } |
| 185 | return null; | 186 | return null; |
| 186 | } | 187 | } |
| 187 | 188 | ||
| 188 | private static String ifEmpty(String s, String placeholder) { | 189 | private static String ifEmpty(String s, String placeholder) { |
| 189 | if (s == null || s.isEmpty()) return placeholder; | 190 | if (s == null || s.isEmpty()) return placeholder; |
| 190 | return s; | 191 | return s; |
| 191 | } | 192 | } |
| 192 | 193 | ||
| 193 | public static class ErrorAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 194 | public static class ErrorAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
| 194 | 195 | ||
| 195 | public ErrorAdapter() { | 196 | public ErrorAdapter() { |
| 196 | super(R.layout.item_homework_error); | 197 | super(R.layout.item_homework_error); |
| 197 | } | 198 | } |
| 198 | 199 | ||
| 199 | @Override | 200 | @Override |
| 200 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 201 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
| 201 | ImageView ivTopic = holder.getView(R.id.ivTopic); | 202 | ImageView ivTopic = holder.getView(R.id.ivTopic); |
| 202 | TextView tvPoints = holder.getView(R.id.tvPoints); | 203 | TextView tvPoints = holder.getView(R.id.tvPoints); |
| 203 | ImageView ivAnalyze = holder.getView(R.id.ivAnalyze); | 204 | ImageView ivAnalyze = holder.getView(R.id.ivAnalyze); |
| 204 | 205 | ||
| 205 | showImage(ivTopic, homeWork.url); | 206 | showImage(ivTopic, homeWork.url); |
| 206 | showImage(ivAnalyze, homeWork.analyseUrl); | 207 | showImage(ivAnalyze, homeWork.analyseUrl); |
| 207 | tvPoints.setText("-"); | 208 | tvPoints.setText("-"); |
| 208 | if (homeWork.pointsObj == null || homeWork.pointsObj.isEmpty()) return; | 209 | if (homeWork.pointsObj == null || homeWork.pointsObj.isEmpty()) return; |
| 209 | StringBuilder builder = new StringBuilder(); | 210 | StringBuilder builder = new StringBuilder(); |
| 210 | for (KeyValue pair: homeWork.pointsObj) { | 211 | for (KeyValue pair: homeWork.pointsObj) { |
| 211 | builder.append(pair.Value).append("\n"); | 212 | builder.append(pair.Value).append("\n"); |
| 212 | } | 213 | } |
| 213 | tvPoints.setText(ifEmpty(builder.toString().trim(), "-")); | 214 | tvPoints.setText(ifEmpty(builder.toString().trim(), "-")); |
| 214 | } | 215 | } |
| 215 | 216 | ||
| 216 | @SuppressLint("CheckResult") | 217 | @SuppressLint("CheckResult") |
| 217 | private void showImage(ImageView view, String url) { | 218 | private void showImage(ImageView view, String url) { |
| 218 | view.setVisibility(View.GONE); | 219 | view.setVisibility(View.GONE); |
| 219 | view.setImageBitmap(null); | 220 | view.setImageBitmap(null); |
| 220 | if (url == null) { | 221 | if (url == null) { |
| 221 | return; | 222 | return; |
| 222 | } | 223 | } |
| 224 | view.setOnClickListener(v -> { | ||
| 225 | new PhotoViewDialog(mContext).show(url); | ||
| 226 | }); | ||
| 223 | Single.just(url) | 227 | Single.just(url) |
| 224 | .subscribeOn(Schedulers.io()) | 228 | .subscribeOn(Schedulers.io()) |
| 225 | .map(u -> Glide.with(mContext).asBitmap().load(url).submit().get()) | 229 | .map(u -> Glide.with(mContext).asBitmap().load(url).submit().get()) |
| 226 | .observeOn(AndroidSchedulers.mainThread()) | 230 | .observeOn(AndroidSchedulers.mainThread()) |
| 227 | .subscribe((bitmap, th) -> { | 231 | .subscribe((bitmap, th) -> { |
| 228 | if (bitmap == null) return; | 232 | if (bitmap == null) return; |
| 229 | 233 | ||
| 230 | float imageHeight = bitmap.getHeight(); | 234 | float imageHeight = bitmap.getHeight(); |
| 231 | float imageWidth = bitmap.getWidth(); | 235 | float imageWidth = bitmap.getWidth(); |
| 232 | int viewHeight = (int) (CommonUtil.getScreenHeight(mContext) * 0.75f); | 236 | int viewHeight = (int) (CommonUtil.getScreenHeight(mContext) * 0.75f); |
| 233 | int viewWidth = (int) (CommonUtil.getScreenWidth(mContext) * 0.75f); | 237 | int viewWidth = (int) (CommonUtil.getScreenWidth(mContext) * 0.75f); |
| 234 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(view.getLayoutParams()); | 238 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(view.getLayoutParams()); |
| 235 | if (imageHeight > imageWidth) { | 239 | if (imageHeight > imageWidth) { |
| 236 | if (viewHeight > imageHeight) { | 240 | if (viewHeight > imageHeight) { |
| 237 | layoutParams.height = (int) imageHeight; | 241 | layoutParams.height = (int) imageHeight; |
| 238 | layoutParams.width = (int) imageWidth; | 242 | layoutParams.width = (int) imageWidth; |
| 239 | } else { | 243 | } else { |
| 240 | layoutParams.height = viewHeight; | 244 | layoutParams.height = viewHeight; |
| 241 | layoutParams.width = (int) (imageWidth / imageHeight * viewHeight); | 245 | layoutParams.width = (int) (imageWidth / imageHeight * viewHeight); |
| 242 | } | 246 | } |
| 243 | } else { | 247 | } else { |
| 244 | if (viewWidth > imageWidth) { | 248 | if (viewWidth > imageWidth) { |
| 245 | layoutParams.height = (int) imageHeight; | 249 | layoutParams.height = (int) imageHeight; |
| 246 | layoutParams.width = (int) imageWidth; | 250 | layoutParams.width = (int) imageWidth; |
| 247 | } else { | 251 | } else { |
| 248 | layoutParams.height = (int) (imageHeight / imageWidth * viewWidth); | 252 | layoutParams.height = (int) (imageHeight / imageWidth * viewWidth); |
| 249 | layoutParams.width = viewWidth; | 253 | layoutParams.width = viewWidth; |
| 250 | } | 254 | } |
| 251 | } | 255 | } |
| 252 | 256 | ||
| 253 | layoutParams.setMargins(CommonUtil.dpToPx(mContext, 5), CommonUtil.dpToPx(mContext, 5), CommonUtil.dpToPx(mContext, 5), CommonUtil.dpToPx(mContext, 5)); | 257 | layoutParams.setMargins(CommonUtil.dpToPx(mContext, 5), CommonUtil.dpToPx(mContext, 5), CommonUtil.dpToPx(mContext, 5), CommonUtil.dpToPx(mContext, 5)); |
| 254 | view.setLayoutParams(layoutParams); | 258 | view.setLayoutParams(layoutParams); |
| 255 | view.setImageBitmap(bitmap); | 259 | view.setImageBitmap(bitmap); |
| 256 | view.setVisibility(View.VISIBLE); | 260 | view.setVisibility(View.VISIBLE); |
| 257 | }); | 261 | }); |
| 258 | } | 262 | } |
| 259 | } | 263 | } |
| 260 | } | 264 | } |
| 261 | 265 |
app/src/main/java/com/hjx/parent/dialog/PhotoViewDialog.java
| File was created | 1 | package com.hjx.parent.dialog; | |
| 2 | |||
| 3 | import android.content.Context; | ||
| 4 | import android.graphics.Color; | ||
| 5 | import android.view.View; | ||
| 6 | import android.view.WindowManager; | ||
| 7 | |||
| 8 | import androidx.annotation.NonNull; | ||
| 9 | |||
| 10 | import com.bumptech.glide.Glide; | ||
| 11 | import com.hjx.parent.databinding.DialogPhotoViewBinding; | ||
| 12 | |||
| 13 | public class PhotoViewDialog extends BaseDialog<DialogPhotoViewBinding> { | ||
| 14 | public PhotoViewDialog(Context context) { | ||
| 15 | super(context); | ||
| 16 | } | ||
| 17 | |||
| 18 | private String url; | ||
| 19 | |||
| 20 | @Override | ||
| 21 | public void initView() { | ||
| 22 | setupWindow(); | ||
| 23 | setCancelable(true); | ||
| 24 | binding.btnClose.setOnClickListener(v -> dismiss()); | ||
| 25 | } | ||
| 26 | |||
| 27 | private void setupWindow() { | ||
| 28 | // 在显示 Dialog 之前对窗口进行设置 | ||
| 29 | getWindow().setFlags( | ||
| 30 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, | ||
| 31 | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | ||
| 32 | |||
| 33 | // 设置状态栏背景透明 | ||
| 34 | getWindow().setStatusBarColor(Color.TRANSPARENT); | ||
| 35 | |||
| 36 | // 让内容延伸到状态栏区域,并保持状态栏和导航栏的显示 | ||
| 37 | getWindow().getDecorView().setSystemUiVisibility( | ||
| 38 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | ||
| 39 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); | ||
| 40 | |||
| 41 | } | ||
| 42 | |||
| 43 | @Override | ||
| 44 | public void onDialogStart() { | ||
| 45 | super.onDialogStart(); | ||
| 46 | Glide.with(getContext()).load(url).into(binding.photoView); | ||
| 47 | } | ||
| 48 | |||
| 49 | public void show(String url) { | ||
| 50 | this.url = url; | ||
| 51 | super.show(); | ||
| 52 | } | ||
| 53 | |||
| 54 | @NonNull | ||
| 55 | @Override | ||
| 56 | public DialogPhotoViewBinding getBinding() { | ||
| 57 | return DialogPhotoViewBinding.inflate(getLayoutInflater()); | ||
| 58 | } | ||
| 59 | } | ||
| 60 |
app/src/main/res/layout/dialog_photo_view.xml
| File was created | 1 | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| 4 | xmlns:tools="http://schemas.android.com/tools" | ||
| 5 | android:orientation="vertical" | ||
| 6 | android:layout_width="match_parent" | ||
| 7 | android:layout_height="match_parent" | ||
| 8 | tools:background="#888" | ||
| 9 | tools:ignore="UseCompoundDrawables,HardcodedText,SmallSp,ContentDescription"> | ||
| 10 | |||
| 11 | <com.github.chrisbanes.photoview.PhotoView | ||
| 12 | android:id="@+id/photoView" | ||
| 13 | android:layout_width="match_parent" | ||
| 14 | android:layout_height="match_parent" /> | ||
| 15 | |||
| 16 | <ImageView | ||
| 17 | android:id="@+id/btnClose" | ||
| 18 | android:src="@drawable/svg_close_24" | ||
| 19 | android:padding="8dp" | ||
| 20 | android:background="@drawable/shape_circle" | ||
| 21 | android:backgroundTint="#88FFFFFF" | ||
| 22 | android:layout_gravity="end" | ||
| 23 | android:layout_marginTop="40dp" | ||
| 24 | android:layout_marginEnd="16dp" | ||
| 25 | android:layout_width="28dp" | ||
| 26 | android:layout_height="28dp"/> | ||
| 27 | |||
| 28 | </FrameLayout> |
app/src/main/res/values/styles.xml
| 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <resources> | 2 | <resources> |
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | <style name="ThemeSplash" parent="Theme.AppCompat.Light.NoActionBar"> | 5 | <style name="ThemeSplash" parent="Theme.AppCompat.Light.NoActionBar"> |
| 6 | <item name="android:windowBackground">@drawable/welcome_bg</item> | 6 | <item name="android:windowBackground">@drawable/welcome_bg</item> |
| 7 | <item name="colorPrimaryDark">@android:color/transparent</item> | 7 | <item name="colorPrimaryDark">@android:color/transparent</item> |
| 8 | <item name="windowActionBar">false</item> | 8 | <item name="windowActionBar">false</item> |
| 9 | <item name="windowNoTitle">true</item> | 9 | <item name="windowNoTitle">true</item> |
| 10 | <item name="android:windowFullscreen">true</item> | 10 | <item name="android:windowFullscreen">true</item> |
| 11 | </style> | 11 | </style> |
| 12 | 12 | ||
| 13 | <style name="main_bottom_navigaton_menu_item"> | 13 | <style name="main_bottom_navigaton_menu_item"> |
| 14 | <item name="android:layout_width">0dp</item> | 14 | <item name="android:layout_width">0dp</item> |
| 15 | <item name="android:layout_weight">1</item> | 15 | <item name="android:layout_weight">1</item> |
| 16 | <item name="android:layout_height">match_parent</item> | 16 | <item name="android:layout_height">match_parent</item> |
| 17 | <item name="android:background">@android:color/transparent</item> | 17 | <item name="android:background">@android:color/transparent</item> |
| 18 | <item name="android:button">@null</item> | 18 | <item name="android:button">@null</item> |
| 19 | <item name="android:gravity">center</item> | 19 | <item name="android:gravity">center</item> |
| 20 | <item name="android:textSize">11dp</item> | 20 | <item name="android:textSize">11dp</item> |
| 21 | <item name="android:drawablePadding">2dp</item> | 21 | <item name="android:drawablePadding">2dp</item> |
| 22 | </style> | 22 | </style> |
| 23 | <!--实现BottomSheetDialog圆角效果--> | 23 | <!--实现BottomSheetDialog圆角效果--> |
| 24 | <style name="BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog"> | 24 | <style name="BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog"> |
| 25 | <item name="bottomSheetStyle">@style/bottomSheetStyleWrapper</item> | 25 | <item name="bottomSheetStyle">@style/bottomSheetStyleWrapper</item> |
| 26 | </style> | 26 | </style> |
| 27 | 27 | ||
| 28 | <style name="bottomSheetStyleWrapper" parent="Widget.Design.BottomSheet.Modal"> | 28 | <style name="bottomSheetStyleWrapper" parent="Widget.Design.BottomSheet.Modal"> |
| 29 | <item name="android:background">@android:color/transparent</item> | 29 | <item name="android:background">@android:color/transparent</item> |
| 30 | <item name="android:navigationBarColor">@android:color/transparent</item> | 30 | <item name="android:navigationBarColor">@android:color/transparent</item> |
| 31 | <item name="behavior_peekHeight">500dp</item> | 31 | <item name="behavior_peekHeight">500dp</item> |
| 32 | </style> | 32 | </style> |
| 33 | 33 | ||
| 34 | <style name="MyAlertDialog" parent="android:Theme.Material.Dialog.Alert"> | 34 | <style name="MyAlertDialog" parent="android:Theme.Material.Dialog.Alert"> |
| 35 | <!--背景颜色及和透明程度--> | 35 | <!--背景颜色及和透明程度--> |
| 36 | <item name="android:windowBackground">@null</item> | 36 | <item name="android:windowBackground">@null</item> |
| 37 | <!--是否去除标题 --> | 37 | <!--是否去除标题 --> |
| 38 | <item name="android:windowNoTitle">true</item> | 38 | <item name="android:windowNoTitle">true</item> |
| 39 | <!--是否去除边框--> | 39 | <!--是否去除边框--> |
| 40 | <item name="android:windowFrame">@null</item> | 40 | <item name="android:windowFrame">@null</item> |
| 41 | <!--是否浮现在activity之上--> | 41 | <!--是否浮现在activity之上--> |
| 42 | <item name="android:windowIsFloating">true</item> | 42 | <item name="android:windowIsFloating">true</item> |
| 43 | <!--是否模糊--> | 43 | <!--是否模糊--> |
| 44 | <item name="android:backgroundDimEnabled">true</item> | 44 | <item name="android:backgroundDimEnabled">true</item> |
| 45 | <item name="android:windowIsTranslucent">true</item><!--半透明--> | 45 | <item name="android:windowIsTranslucent">true</item><!--半透明--> |
| 46 | <item name="android:windowSoftInputMode">stateVisible|adjustPan</item> | 46 | <item name="android:windowSoftInputMode">stateVisible|adjustPan</item> |
| 47 | </style> | 47 | </style> |
| 48 | 48 | ||
| 49 | <style name="customSpinnerStyle" parent="android:Widget.ListView.DropDown"> | 49 | <style name="customSpinnerStyle" parent="android:Widget.ListView.DropDown"> |
| 50 | <item name="divider">@color/border</item> | 50 | <item name="divider">@color/border</item> |
| 51 | <item name="android:scrollbars">none</item> | 51 | <item name="android:scrollbars">none</item> |
| 52 | <item name="android:dividerHeight">1dp</item> | 52 | <item name="android:dividerHeight">1dp</item> |
| 53 | <item name="android:textSize">15sp</item> | 53 | <item name="android:textSize">15sp</item> |
| 54 | </style> | 54 | </style> |
| 55 | 55 | ||
| 56 | <style name="empty_space"> | 56 | <style name="empty_space"> |
| 57 | <item name="android:layout_width">0dp</item> | 57 | <item name="android:layout_width">0dp</item> |
| 58 | <item name="android:layout_height">0dp</item> | 58 | <item name="android:layout_height">0dp</item> |
| 59 | <item name="android:layout_weight">1</item> | 59 | <item name="android:layout_weight">1</item> |
| 60 | </style> | 60 | </style> |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | <style name="BaseDialog"> | 63 | <style name="BaseDialog"> |
| 64 | <item name="android:background">@android:color/transparent</item> | 64 | <item name="android:background">@android:color/transparent</item> |
| 65 | <item name="android:windowBackground">@android:color/transparent</item> | 65 | <item name="android:windowBackground">@android:color/transparent</item> |
| 66 | <item name="android:windowIsFloating">true</item> | 66 | <item name="android:windowIsFloating">true</item> |
| 67 | </style> | 67 | </style> |
| 68 | 68 | ||
| 69 | <style name="BaseDialog.FullScreen"> | ||
| 70 | <item name="android:windowFullscreen">true</item> | ||
| 71 | <item name="android:windowIsTranslucent">true</item> | ||
| 72 | <item name="android:statusBarColor">@android:color/transparent</item> | ||
| 73 | </style> | ||
| 74 | |||
| 69 | <style name="tv_StudentHomeworkFilter"> | 75 | <style name="tv_StudentHomeworkFilter"> |
| 70 | <item name="android:textSize">13sp</item> | 76 | <item name="android:textSize">13sp</item> |
| 71 | <item name="android:textColor">@color/color_filter_state</item> | 77 | <item name="android:textColor">@color/color_filter_state</item> |
| 72 | <item name="android:drawableTint">@color/color_filter_state</item> | 78 | <item name="android:drawableTint">@color/color_filter_state</item> |
| 73 | <item name="android:drawableEnd">@drawable/svg_filter_drop_down</item> | 79 | <item name="android:drawableEnd">@drawable/svg_filter_drop_down</item> |
| 74 | <item name="android:drawablePadding">8dp</item> | 80 | <item name="android:drawablePadding">8dp</item> |
| 75 | <item name="android:layout_width">wrap_content</item> | 81 | <item name="android:layout_width">wrap_content</item> |
| 76 | <item name="android:layout_height">wrap_content</item> | 82 | <item name="android:layout_height">wrap_content</item> |
| 77 | </style> | 83 | </style> |
| 78 | 84 | ||
| 79 | <style name="chk_HomeworkFilterItem"> | 85 | <style name="chk_HomeworkFilterItem"> |
| 80 | <item name="android:textSize">13sp</item> | 86 | <item name="android:textSize">13sp</item> |
| 81 | <item name="android:textColor">@color/color_filter_item</item> | 87 | <item name="android:textColor">@color/color_filter_item</item> |
| 82 | <item name="android:gravity">center</item> | 88 | <item name="android:gravity">center</item> |
| 83 | <item name="android:button">@null</item> | 89 | <item name="android:button">@null</item> |
| 84 | <item name="android:background">@drawable/btn_homework_filter_item</item> | 90 | <item name="android:background">@drawable/btn_homework_filter_item</item> |
| 85 | <item name="android:layout_margin">8dp</item> | 91 | <item name="android:layout_margin">8dp</item> |
| 86 | <item name="android:layout_weight">1</item> | 92 | <item name="android:layout_weight">1</item> |
| 87 | <item name="android:layout_width">0dp</item> | 93 | <item name="android:layout_width">0dp</item> |
| 88 | <item name="android:layout_height">26dp</item> | 94 | <item name="android:layout_height">26dp</item> |
| 89 | </style> | 95 | </style> |
| 90 | 96 | ||
| 91 | </resources> | 97 | </resources> |