Commit fc85bfe19718e0d59cd1566bb7c76bcff50a5e31
1 parent
fdaf2a78b4
Exists in
master
图片全屏查看
Showing
1 changed file
with
8 additions
and
0 deletions
Show diff stats
app/src/main/java/com/hjx/parent/HomeworkTopicActivity.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.res.ColorStateList; | 4 | import android.content.res.ColorStateList; |
| 5 | import android.os.Bundle; | 5 | import android.os.Bundle; |
| 6 | import android.view.View; | 6 | import android.view.View; |
| 7 | import android.widget.TextView; | 7 | import android.widget.TextView; |
| 8 | 8 | ||
| 9 | import androidx.annotation.NonNull; | 9 | import androidx.annotation.NonNull; |
| 10 | import androidx.annotation.Nullable; | 10 | import androidx.annotation.Nullable; |
| 11 | 11 | ||
| 12 | import com.bumptech.glide.Glide; | 12 | import com.bumptech.glide.Glide; |
| 13 | import com.chad.library.adapter.base.BaseQuickAdapter; | 13 | import com.chad.library.adapter.base.BaseQuickAdapter; |
| 14 | import com.chad.library.adapter.base.BaseViewHolder; | 14 | import com.chad.library.adapter.base.BaseViewHolder; |
| 15 | import com.google.gson.Gson; | 15 | import com.google.gson.Gson; |
| 16 | import com.hjx.parent.databinding.ActivityTopicDetailBinding; | 16 | import com.hjx.parent.databinding.ActivityTopicDetailBinding; |
| 17 | import com.hjx.parent.dialog.PhotoViewDialog; | ||
| 17 | import com.hjx.parent.rx.BaseRxActivity; | 18 | import com.hjx.parent.rx.BaseRxActivity; |
| 18 | import com.prws.common.bean.homework.HomeWork; | 19 | import com.prws.common.bean.homework.HomeWork; |
| 19 | import com.prws.common.bean.homework.KeyValue; | 20 | import com.prws.common.bean.homework.KeyValue; |
| 20 | 21 | ||
| 21 | import java.util.ArrayList; | 22 | import java.util.ArrayList; |
| 22 | import java.util.List; | 23 | import java.util.List; |
| 23 | 24 | ||
| 24 | public class HomeworkTopicActivity extends BaseRxActivity<ActivityTopicDetailBinding> { | 25 | public class HomeworkTopicActivity extends BaseRxActivity<ActivityTopicDetailBinding> { |
| 25 | private ArrayList<HomeWork> mList; | 26 | private ArrayList<HomeWork> mList; |
| 26 | private int position; | 27 | private int position; |
| 27 | 28 | ||
| 28 | @SuppressWarnings("unchecked") | 29 | @SuppressWarnings("unchecked") |
| 29 | @Override | 30 | @Override |
| 30 | public void initView(Bundle savedInstanceState) { | 31 | public void initView(Bundle savedInstanceState) { |
| 31 | mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list"); | 32 | mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list"); |
| 32 | position = getIntent().getIntExtra("position", 0); | 33 | position = getIntent().getIntExtra("position", 0); |
| 33 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); | 34 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); |
| 34 | NumberAdapter adapter = new NumberAdapter(mList); | 35 | NumberAdapter adapter = new NumberAdapter(mList); |
| 35 | binding.rvNumber.setAdapter(adapter); | 36 | binding.rvNumber.setAdapter(adapter); |
| 36 | 37 | ||
| 37 | binding.btnPre.setOnClickListener(v -> showTopic(position - 1)); | 38 | binding.btnPre.setOnClickListener(v -> showTopic(position - 1)); |
| 38 | binding.btnNext.setOnClickListener(v -> showTopic(position + 1)); | 39 | binding.btnNext.setOnClickListener(v -> showTopic(position + 1)); |
| 39 | adapter.setOnItemClickListener((baseQuickAdapter, view, i) -> { | 40 | adapter.setOnItemClickListener((baseQuickAdapter, view, i) -> { |
| 40 | if (position == i) return; | 41 | if (position == i) return; |
| 41 | showTopic(i); | 42 | showTopic(i); |
| 42 | }); | 43 | }); |
| 43 | showTopic(position); | 44 | showTopic(position); |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | @SuppressLint("SetTextI18n") | 47 | @SuppressLint("SetTextI18n") |
| 47 | private void showTopic(int position) { | 48 | private void showTopic(int position) { |
| 48 | if (position < 0 || position >= mList.size()) return; | 49 | if (position < 0 || position >= mList.size()) return; |
| 49 | this.position = position; | 50 | this.position = position; |
| 50 | binding.btnPre.setEnabled(position > 0); | 51 | binding.btnPre.setEnabled(position > 0); |
| 51 | binding.btnNext.setEnabled(position < mList.size() - 1); | 52 | binding.btnNext.setEnabled(position < mList.size() - 1); |
| 52 | binding.tvTitle.setText((position + 1) + "/" + mList.size()); | 53 | binding.tvTitle.setText((position + 1) + "/" + mList.size()); |
| 53 | binding.tvNo.setText("题目" + (position + 1)); | 54 | binding.tvNo.setText("题目" + (position + 1)); |
| 54 | 55 | ||
| 55 | HomeWork homeWork = mList.get(position); | 56 | HomeWork homeWork = mList.get(position); |
| 56 | Glide.with(this).load(homeWork.url).into(binding.ivTopic); | 57 | Glide.with(this).load(homeWork.url).into(binding.ivTopic); |
| 58 | binding.ivTopic.setOnClickListener(v -> { | ||
| 59 | new PhotoViewDialog(this).show(homeWork.url); | ||
| 60 | }); | ||
| 57 | Glide.with(this).load(homeWork.analyseUrl).into(binding.ivAnalyse); | 61 | Glide.with(this).load(homeWork.analyseUrl).into(binding.ivAnalyse); |
| 62 | binding.ivAnalyse.setOnClickListener(v -> { | ||
| 63 | if (homeWork.analyseUrl == null || homeWork.analyseUrl.isEmpty()) return; | ||
| 64 | new PhotoViewDialog(this).show(homeWork.analyseUrl); | ||
| 65 | }); | ||
| 58 | String answer = homeWork.answer == null ? "" : homeWork.answer | 66 | String answer = homeWork.answer == null ? "" : homeWork.answer |
| 59 | .replace("<br />", "\n") | 67 | .replace("<br />", "\n") |
| 60 | .replace("${", "") | 68 | .replace("${", "") |
| 61 | .replace("}$", ""); | 69 | .replace("}$", ""); |
| 62 | binding.tvAnswer.setText(answer); | 70 | binding.tvAnswer.setText(answer); |
| 63 | if (homeWork.pointsObj == null) homeWork.formatPoints(new Gson()); | 71 | if (homeWork.pointsObj == null) homeWork.formatPoints(new Gson()); |
| 64 | StringBuilder pointBuilder = new StringBuilder(); | 72 | StringBuilder pointBuilder = new StringBuilder(); |
| 65 | for (KeyValue point: homeWork.pointsObj) { | 73 | for (KeyValue point: homeWork.pointsObj) { |
| 66 | pointBuilder.append("\n").append(point.Value); | 74 | pointBuilder.append("\n").append(point.Value); |
| 67 | } | 75 | } |
| 68 | binding.tvPoint.setText(homeWork.pointsObj.size() == 0 ? "" : pointBuilder.substring(1)); | 76 | binding.tvPoint.setText(homeWork.pointsObj.size() == 0 ? "" : pointBuilder.substring(1)); |
| 69 | } | 77 | } |
| 70 | 78 | ||
| 71 | @Override | 79 | @Override |
| 72 | protected ActivityTopicDetailBinding getViewBinding() { | 80 | protected ActivityTopicDetailBinding getViewBinding() { |
| 73 | return ActivityTopicDetailBinding.inflate(getLayoutInflater()); | 81 | return ActivityTopicDetailBinding.inflate(getLayoutInflater()); |
| 74 | } | 82 | } |
| 75 | 83 | ||
| 76 | static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 84 | static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
| 77 | 85 | ||
| 78 | public NumberAdapter(@Nullable List<HomeWork> data) { | 86 | public NumberAdapter(@Nullable List<HomeWork> data) { |
| 79 | super(R.layout.item_topic_number, data); | 87 | super(R.layout.item_topic_number, data); |
| 80 | } | 88 | } |
| 81 | 89 | ||
| 82 | @Override | 90 | @Override |
| 83 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 91 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
| 84 | TextView textView = (TextView) holder.itemView; | 92 | TextView textView = (TextView) holder.itemView; |
| 85 | textView.setText(String.valueOf(getData().indexOf(homeWork) + 1)); | 93 | textView.setText(String.valueOf(getData().indexOf(homeWork) + 1)); |
| 86 | 94 | ||
| 87 | int color = homeWork.check ? 0xFFFF4133 : 0xFF4ABC78; | 95 | int color = homeWork.check ? 0xFFFF4133 : 0xFF4ABC78; |
| 88 | textView.setBackgroundTintList(ColorStateList.valueOf(color)); | 96 | textView.setBackgroundTintList(ColorStateList.valueOf(color)); |
| 89 | } | 97 | } |
| 90 | } | 98 | } |
| 91 | } | 99 | } |
| 92 | 100 |