Commit 7bcb60ecb98a6185d86a11e5be0f29771c5b48d3
1 parent
6eabc0ad3d
Exists in
master
首页科目选中/非选中效果
Showing
11 changed files
with
48 additions
and
16 deletions
Show diff stats
app/src/main/java/com/hjx/parent/fragment/ErrorFragment.java
| 1 | package com.hjx.parent.fragment; | 1 | package com.hjx.parent.fragment; |
| 2 | 2 | ||
| 3 | import static android.app.Activity.RESULT_OK; | 3 | import static android.app.Activity.RESULT_OK; |
| 4 | 4 | ||
| 5 | import android.annotation.SuppressLint; | 5 | import android.annotation.SuppressLint; |
| 6 | import android.content.Intent; | 6 | import android.content.Intent; |
| 7 | import android.graphics.Bitmap; | 7 | import android.graphics.Bitmap; |
| 8 | import android.graphics.BitmapFactory; | 8 | import android.graphics.BitmapFactory; |
| 9 | import android.net.Uri; | 9 | import android.net.Uri; |
| 10 | import android.os.Bundle; | 10 | import android.os.Bundle; |
| 11 | import android.provider.MediaStore; | 11 | import android.provider.MediaStore; |
| 12 | import android.text.TextUtils; | 12 | import android.text.TextUtils; |
| 13 | import android.util.Log; | 13 | import android.util.Log; |
| 14 | import android.view.LayoutInflater; | 14 | import android.view.LayoutInflater; |
| 15 | import android.view.View; | 15 | import android.view.View; |
| 16 | import android.view.ViewGroup; | 16 | import android.view.ViewGroup; |
| 17 | import android.widget.TextView; | ||
| 17 | import android.widget.Toast; | 18 | import android.widget.Toast; |
| 18 | 19 | ||
| 19 | import androidx.annotation.NonNull; | 20 | import androidx.annotation.NonNull; |
| 20 | import androidx.annotation.Nullable; | 21 | import androidx.annotation.Nullable; |
| 21 | import androidx.core.content.FileProvider; | 22 | import androidx.core.content.FileProvider; |
| 22 | import androidx.recyclerview.widget.RecyclerView; | 23 | import androidx.recyclerview.widget.RecyclerView; |
| 23 | 24 | ||
| 24 | import com.bumptech.glide.Glide; | 25 | import com.bumptech.glide.Glide; |
| 25 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 26 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
| 26 | import com.bumptech.glide.request.RequestOptions; | 27 | import com.bumptech.glide.request.RequestOptions; |
| 27 | import com.chad.library.adapter.base.BaseQuickAdapter; | 28 | import com.chad.library.adapter.base.BaseQuickAdapter; |
| 28 | import com.chad.library.adapter.base.BaseViewHolder; | 29 | import com.chad.library.adapter.base.BaseViewHolder; |
| 29 | import com.google.android.material.tabs.TabLayout; | 30 | import com.google.android.material.tabs.TabLayout; |
| 30 | import com.google.gson.Gson; | 31 | import com.google.gson.Gson; |
| 31 | import com.hjq.permissions.OnPermissionCallback; | 32 | import com.hjq.permissions.OnPermissionCallback; |
| 32 | import com.hjq.permissions.Permission; | 33 | import com.hjq.permissions.Permission; |
| 33 | import com.hjq.permissions.XXPermissions; | 34 | import com.hjq.permissions.XXPermissions; |
| 34 | import com.hjx.parent.ErrorListActivity; | 35 | import com.hjx.parent.ErrorListActivity; |
| 35 | import com.hjx.parent.HomeworkDetailActivity; | 36 | import com.hjx.parent.HomeworkDetailActivity; |
| 36 | import com.hjx.parent.HomeworkShareActivity; | 37 | import com.hjx.parent.HomeworkShareActivity; |
| 37 | import com.hjx.parent.ImageActivity; | 38 | import com.hjx.parent.ImageActivity; |
| 38 | import com.hjx.parent.R; | 39 | import com.hjx.parent.R; |
| 39 | import com.hjx.parent.StuHomeworkActivity; | 40 | import com.hjx.parent.StuHomeworkActivity; |
| 40 | import com.hjx.parent.TeacherChooseActivity; | 41 | import com.hjx.parent.TeacherChooseActivity; |
| 41 | import com.hjx.parent.adapter.ErrorAdapter; | 42 | import com.hjx.parent.adapter.ErrorAdapter; |
| 42 | import com.hjx.parent.adapter.HomeworkAdapter; | 43 | import com.hjx.parent.adapter.HomeworkAdapter; |
| 43 | import com.hjx.parent.bean.StudentBean; | 44 | import com.hjx.parent.bean.StudentBean; |
| 44 | import com.hjx.parent.databinding.FragmentErrorBookBinding; | 45 | import com.hjx.parent.databinding.FragmentErrorBookBinding; |
| 45 | import com.hjx.parent.rx.BaseRxFragment; | 46 | import com.hjx.parent.rx.BaseRxFragment; |
| 46 | import com.prws.common.bean.PageInfo; | 47 | import com.prws.common.bean.PageInfo; |
| 47 | import com.prws.common.bean.ResponseResult; | 48 | import com.prws.common.bean.ResponseResult; |
| 48 | import com.prws.common.bean.Student; | 49 | import com.prws.common.bean.Student; |
| 49 | import com.prws.common.bean.TopicBean; | 50 | import com.prws.common.bean.TopicBean; |
| 50 | import com.prws.common.bean.homework.HomeworkList; | 51 | import com.prws.common.bean.homework.HomeworkList; |
| 51 | import com.prws.common.net.NetWorks; | 52 | import com.prws.common.net.NetWorks; |
| 52 | import com.prws.common.utils.BitmapUtils; | 53 | import com.prws.common.utils.BitmapUtils; |
| 53 | import com.prws.common.utils.CommonUtil; | 54 | import com.prws.common.utils.CommonUtil; |
| 54 | import com.prws.common.utils.ScreenUtils; | 55 | import com.prws.common.utils.ScreenUtils; |
| 55 | import com.prws.common.utils.SharedPreferencesUtil; | 56 | import com.prws.common.utils.SharedPreferencesUtil; |
| 56 | import com.prws.common.utils.dialog.MyButtomDialog; | 57 | import com.prws.common.utils.dialog.MyButtomDialog; |
| 57 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; | 58 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; |
| 58 | import com.zhangteng.imagepicker.bean.ImageInfo; | 59 | import com.zhangteng.imagepicker.bean.ImageInfo; |
| 59 | import com.zhangteng.imagepicker.config.ImagePickerConfig; | 60 | import com.zhangteng.imagepicker.config.ImagePickerConfig; |
| 60 | import com.zhangteng.imagepicker.config.ImagePickerEnum; | 61 | import com.zhangteng.imagepicker.config.ImagePickerEnum; |
| 61 | import com.zhangteng.imagepicker.config.ImagePickerOpen; | 62 | import com.zhangteng.imagepicker.config.ImagePickerOpen; |
| 62 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; | 63 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; |
| 63 | import com.zhangteng.utils.IHandlerCallBack; | 64 | import com.zhangteng.utils.IHandlerCallBack; |
| 64 | 65 | ||
| 65 | import java.io.File; | 66 | import java.io.File; |
| 66 | import java.text.SimpleDateFormat; | 67 | import java.text.SimpleDateFormat; |
| 67 | import java.util.ArrayList; | 68 | import java.util.ArrayList; |
| 68 | import java.util.Arrays; | 69 | import java.util.Arrays; |
| 69 | import java.util.HashMap; | 70 | import java.util.HashMap; |
| 70 | import java.util.List; | 71 | import java.util.List; |
| 71 | import java.util.Locale; | 72 | import java.util.Locale; |
| 72 | import java.util.Map; | 73 | import java.util.Map; |
| 73 | 74 | ||
| 74 | import io.reactivex.Observable; | 75 | import io.reactivex.Observable; |
| 75 | import io.reactivex.Observer; | 76 | import io.reactivex.Observer; |
| 76 | import io.reactivex.android.schedulers.AndroidSchedulers; | 77 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 77 | import io.reactivex.disposables.Disposable; | 78 | import io.reactivex.disposables.Disposable; |
| 78 | import io.reactivex.schedulers.Schedulers; | 79 | import io.reactivex.schedulers.Schedulers; |
| 79 | 80 | ||
| 80 | public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { | 81 | public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
| 81 | StudentBean studentBean; | 82 | StudentBean studentBean; |
| 82 | private int subject; | 83 | private int subject; |
| 83 | private ErrorAdapter errorAdapter; | 84 | private ErrorAdapter errorAdapter; |
| 84 | private HomeworkAdapter homeworkAdapter; | 85 | private HomeworkAdapter homeworkAdapter; |
| 85 | private String filePath; | 86 | private String filePath; |
| 86 | 87 | ||
| 87 | @Override | 88 | @Override |
| 88 | protected FragmentErrorBookBinding onCreateViewBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup parent) { | 89 | protected FragmentErrorBookBinding onCreateViewBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup parent) { |
| 89 | return FragmentErrorBookBinding.inflate(inflater, parent, false); | 90 | return FragmentErrorBookBinding.inflate(inflater, parent, false); |
| 90 | } | 91 | } |
| 91 | 92 | ||
| 92 | public void refreshStudent() { | 93 | public void refreshStudent() { |
| 93 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 94 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
| 94 | try { | 95 | try { |
| 95 | studentBean = new Gson().fromJson(student, StudentBean.class); | 96 | studentBean = new Gson().fromJson(student, StudentBean.class); |
| 96 | getBinding().tvChoose.setText(studentBean.getStuName()); | 97 | getBinding().tvChoose.setText(studentBean.getStuName()); |
| 97 | } catch (Exception e) { | 98 | } catch (Exception e) { |
| 98 | e.printStackTrace(); | 99 | e.printStackTrace(); |
| 99 | } | 100 | } |
| 100 | } | 101 | } |
| 101 | 102 | ||
| 102 | @Override | 103 | @Override |
| 103 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | 104 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
| 104 | super.onViewCreated(view, savedInstanceState); | 105 | super.onViewCreated(view, savedInstanceState); |
| 105 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); | 106 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); |
| 106 | if (!TextUtils.isEmpty(photo)) { | 107 | if (!TextUtils.isEmpty(photo)) { |
| 107 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); | 108 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); |
| 108 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 109 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
| 109 | Glide.with(getContext()).load(photo).apply(options).into(getBinding().ivStudent); | 110 | Glide.with(getContext()).load(photo).apply(options).into(getBinding().ivStudent); |
| 110 | } | 111 | } |
| 111 | String name = (String) SharedPreferencesUtil.getData("name", ""); | 112 | String name = (String) SharedPreferencesUtil.getData("name", ""); |
| 112 | getBinding().tvName.setText(name); | 113 | getBinding().tvName.setText(name); |
| 113 | refreshStudent(); | 114 | refreshStudent(); |
| 114 | getBinding().tvChoose.setOnClickListener(v -> startActivity(new Intent(getContext(), TeacherChooseActivity.class))); | 115 | getBinding().tvChoose.setOnClickListener(v -> startActivity(new Intent(getContext(), TeacherChooseActivity.class))); |
| 115 | getBinding().rlTakePhoto.setOnClickListener(v -> takePhoto(0)); | 116 | getBinding().rlTakePhoto.setOnClickListener(v -> takePhoto(0)); |
| 116 | getBinding().flEntryHomework.setOnClickListener(v -> takePhoto(1)); | 117 | getBinding().flEntryHomework.setOnClickListener(v -> takePhoto(1)); |
| 117 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_subject, Arrays.asList(getResources().getStringArray(R.array.filter_subject))) { | 118 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_subject, Arrays.asList(getResources().getStringArray(R.array.filter_subject))) { |
| 118 | @Override | 119 | @Override |
| 119 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | 120 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
| 120 | 121 | ||
| 121 | } | 122 | } |
| 122 | 123 | ||
| 123 | @Override | 124 | @Override |
| 124 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 125 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
| 125 | item.setText(R.id.tv_subject, getResources().getStringArray(R.array.filter_subject)[item.getAdapterPosition()]); | 126 | int position = item.getBindingAdapterPosition(); |
| 126 | switch (item.getAdapterPosition()) { | 127 | String name = getResources().getStringArray(R.array.filter_subject)[position]; |
| 127 | case 0: | 128 | item.setText(R.id.tv_subject, name); |
| 128 | item.setImageResource(R.id.iv_subject, R.drawable.png_ic_chinese); | 129 | switch (name) { |
| 130 | case "语文": | ||
| 131 | item.setImageResource(R.id.iv_subject, R.drawable.state_ic_chinese); | ||
| 129 | break; | 132 | break; |
| 130 | case 1: | 133 | case "数学": |
| 131 | item.setImageResource(R.id.iv_subject, R.drawable.png_ic_math); | 134 | item.setImageResource(R.id.iv_subject, R.drawable.state_ic_math); |
| 132 | break; | 135 | break; |
| 133 | case 2: | 136 | case "英语": |
| 134 | item.setImageResource(R.id.iv_subject, R.drawable.png_ic_english); | 137 | item.setImageResource(R.id.iv_subject, R.drawable.state_ic_english); |
| 135 | break; | 138 | break; |
| 136 | case 3: | 139 | case "物理": |
| 137 | item.setImageResource(R.id.iv_subject, R.drawable.png_ic_physics); | 140 | item.setImageResource(R.id.iv_subject, R.drawable.state_ic_physics); |
| 138 | break; | 141 | break; |
| 139 | case 4: | 142 | case "化学": |
| 140 | item.setImageResource(R.id.iv_subject, R.drawable.png_ic_chemistry); | 143 | item.setImageResource(R.id.iv_subject, R.drawable.state_ic_chemistry); |
| 141 | break; | 144 | break; |
| 142 | } | 145 | } |
| 146 | item.itemView.setActivated(subject == position); | ||
| 143 | ViewGroup.LayoutParams layoutParams = item.getView(R.id.rl_subject).getLayoutParams(); | 147 | ViewGroup.LayoutParams layoutParams = item.getView(R.id.rl_subject).getLayoutParams(); |
| 144 | layoutParams.width = (CommonUtil.getScreenWidth(getContext()) - CommonUtil.dpToPx(getContext(), 30)) / 4; | 148 | layoutParams.width = (CommonUtil.getScreenWidth(mContext) - CommonUtil.dpToPx(mContext, 30)) / 4; |
| 145 | item.getView(R.id.rl_subject).setLayoutParams(layoutParams); | 149 | item.getView(R.id.rl_subject).setLayoutParams(layoutParams); |
| 146 | item.getConvertView().setOnClickListener(v -> { | 150 | item.itemView.setOnClickListener(v -> { |
| 147 | if (subject != item.getAdapterPosition()) { | 151 | if (subject != position) { |
| 148 | subject = item.getAdapterPosition(); | 152 | subject = position; |
| 149 | String subStr = getResources().getStringArray(R.array.filter_subject)[subject]; | 153 | String subStr = getResources().getStringArray(R.array.filter_subject)[subject]; |
| 150 | getError(subStr); | 154 | getError(subStr); |
| 151 | getHomework(subStr); | 155 | getHomework(subStr); |
| 156 | notifyDataSetChanged(); | ||
| 152 | } | 157 | } |
| 153 | }); | 158 | }); |
| 154 | } | 159 | } |
| 155 | }; | 160 | }; |
| 156 | getBinding().rvSubject.setAdapter(adapter); | 161 | getBinding().rvSubject.setAdapter(adapter); |
| 157 | subject = 0; | 162 | subject = 0; |
| 158 | getError(getResources().getStringArray(R.array.filter_subject)[subject]); | 163 | getError(getResources().getStringArray(R.array.filter_subject)[subject]); |
| 159 | getBinding().llAll.setOnClickListener(v -> { | 164 | getBinding().llAll.setOnClickListener(v -> { |
| 160 | if (binding.tabLayout.getSelectedTabPosition() == 0) { | 165 | if (binding.tabLayout.getSelectedTabPosition() == 0) { |
| 161 | Intent intent = new Intent(getContext(), ErrorListActivity.class); | 166 | Intent intent = new Intent(getContext(), ErrorListActivity.class); |
| 162 | startActivity(intent); | 167 | startActivity(intent); |
| 163 | } else { | 168 | } else { |
| 164 | Intent intent = new Intent(getContext(), StuHomeworkActivity.class); | 169 | Intent intent = new Intent(getContext(), StuHomeworkActivity.class); |
| 165 | startActivity(intent); | 170 | startActivity(intent); |
| 166 | } | 171 | } |
| 167 | }); | 172 | }); |
| 168 | 173 | ||
| 169 | errorAdapter = new ErrorAdapter(getActivity(), new ArrayList<>(), false); | 174 | errorAdapter = new ErrorAdapter(getActivity(), new ArrayList<>(), false); |
| 170 | homeworkAdapter = new HomeworkAdapter(); | 175 | homeworkAdapter = new HomeworkAdapter(); |
| 171 | homeworkAdapter.setOnItemClickListener((baseQuickAdapter, view1, i) -> { | 176 | homeworkAdapter.setOnItemClickListener((baseQuickAdapter, view1, i) -> { |
| 172 | HomeworkList data = homeworkAdapter.getData().get(i); | 177 | HomeworkList data = homeworkAdapter.getData().get(i); |
| 173 | Gson gson = new Gson(); | 178 | Gson gson = new Gson(); |
| 174 | String json = gson.toJson(studentBean); | 179 | String json = gson.toJson(studentBean); |
| 175 | Student s = gson.fromJson(json, Student.class); | 180 | Student s = gson.fromJson(json, Student.class); |
| 176 | if (data.getRight() == null) { | 181 | if (data.getRight() == null) { |
| 177 | Intent intent = new Intent(requireContext(), HomeworkDetailActivity.class); | 182 | Intent intent = new Intent(requireContext(), HomeworkDetailActivity.class); |
| 178 | intent.putExtra("student", s); | 183 | intent.putExtra("student", s); |
| 179 | intent.putExtra("data", data); | 184 | intent.putExtra("data", data); |
| 180 | startActivity(intent); | 185 | startActivity(intent); |
| 181 | } else { | 186 | } else { |
| 182 | Intent intent = new Intent(requireContext(), HomeworkShareActivity.class); | 187 | Intent intent = new Intent(requireContext(), HomeworkShareActivity.class); |
| 183 | intent.putExtra("student", s); | 188 | intent.putExtra("student", s); |
| 184 | intent.putExtra("id", data.getId()); | 189 | intent.putExtra("id", data.getId()); |
| 185 | intent.putExtra("grade", data.getGrade()); | 190 | intent.putExtra("grade", data.getGrade()); |
| 186 | intent.putExtra("subject", data.getSubject()); | 191 | intent.putExtra("subject", data.getSubject()); |
| 187 | String name1 = new SimpleDateFormat("yyyy年M月d日作业", Locale.CHINA).format(data.uploadTime); | 192 | String name1 = new SimpleDateFormat("yyyy年M月d日作业", Locale.CHINA).format(data.uploadTime); |
| 188 | intent.putExtra("name", name1); | 193 | intent.putExtra("name", name1); |
| 189 | startActivity(intent); | 194 | startActivity(intent); |
| 190 | } | 195 | } |
| 191 | }); | 196 | }); |
| 192 | binding.rvMain.setAdapter(errorAdapter); | 197 | binding.rvMain.setAdapter(errorAdapter); |
| 193 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("最近错题")); | 198 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("最近错题")); |
| 194 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("最近作业")); | 199 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("最近作业")); |
| 195 | binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { | 200 | binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { |
| 196 | @Override | 201 | @Override |
| 197 | public void onTabSelected(TabLayout.Tab tab) { | 202 | public void onTabSelected(TabLayout.Tab tab) { |
| 198 | if (tab.getPosition() == 0) { | 203 | if (tab.getPosition() == 0) { |
| 199 | binding.rvMain.setAdapter(errorAdapter); | 204 | binding.rvMain.setAdapter(errorAdapter); |
| 200 | binding.rvMain.setVisibility(errorAdapter.list.isEmpty() ? View.GONE : View.VISIBLE); | 205 | binding.rvMain.setVisibility(errorAdapter.list.isEmpty() ? View.GONE : View.VISIBLE); |
| 201 | binding.llEmpty.setVisibility(errorAdapter.list.isEmpty() ? View.VISIBLE : View.GONE); | 206 | binding.llEmpty.setVisibility(errorAdapter.list.isEmpty() ? View.VISIBLE : View.GONE); |
| 202 | binding.tvListTitle.setText("最近错题"); | 207 | binding.tvListTitle.setText("最近错题"); |
| 203 | binding.tvEmpty.setText("暂无错题~"); | 208 | binding.tvEmpty.setText("暂无错题~"); |
| 204 | } else { | 209 | } else { |
| 205 | binding.rvMain.setAdapter(homeworkAdapter); | 210 | binding.rvMain.setAdapter(homeworkAdapter); |
| 206 | binding.rvMain.setVisibility(homeworkAdapter.getData().isEmpty() ? View.GONE : View.VISIBLE); | 211 | binding.rvMain.setVisibility(homeworkAdapter.getData().isEmpty() ? View.GONE : View.VISIBLE); |
| 207 | binding.llEmpty.setVisibility(homeworkAdapter.getData().isEmpty() ? View.VISIBLE : View.GONE); | 212 | binding.llEmpty.setVisibility(homeworkAdapter.getData().isEmpty() ? View.VISIBLE : View.GONE); |
| 208 | binding.tvListTitle.setText("最近作业"); | 213 | binding.tvListTitle.setText("最近作业"); |
| 209 | binding.tvEmpty.setText("暂无作业~"); | 214 | binding.tvEmpty.setText("暂无作业~"); |
| 210 | } | 215 | } |
| 211 | } | 216 | } |
| 212 | @Override | 217 | @Override |
| 213 | public void onTabUnselected(TabLayout.Tab tab) { | 218 | public void onTabUnselected(TabLayout.Tab tab) { |
| 214 | } | 219 | } |
| 215 | @Override | 220 | @Override |
| 216 | public void onTabReselected(TabLayout.Tab tab) { | 221 | public void onTabReselected(TabLayout.Tab tab) { |
| 217 | } | 222 | } |
| 218 | }); | 223 | }); |
| 219 | } | 224 | } |
| 220 | 225 | ||
| 221 | private void takePhoto(int type) { | 226 | private void takePhoto(int type) { |
| 222 | if (!XXPermissions.isGranted(getContext(), Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE)) { | 227 | if (!XXPermissions.isGranted(getContext(), Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE)) { |
| 223 | XXPermissions.with(getContext()) | 228 | XXPermissions.with(getContext()) |
| 224 | // 申请多个权限 | 229 | // 申请多个权限 |
| 225 | .permission(Permission.CAMERA).request(new OnPermissionCallback() { | 230 | .permission(Permission.CAMERA).request(new OnPermissionCallback() { |
| 226 | @Override | 231 | @Override |
| 227 | public void onGranted(List<String> permissions, boolean all) { | 232 | public void onGranted(List<String> permissions, boolean all) { |
| 228 | if (all) { | 233 | if (all) { |
| 229 | //开启扫码界面 | 234 | //开启扫码界面 |
| 230 | showButtonDialog(type); | 235 | showButtonDialog(type); |
| 231 | } else { | 236 | } else { |
| 232 | Toast.makeText(getContext(), "需要权限", Toast.LENGTH_SHORT).show(); | 237 | Toast.makeText(getContext(), "需要权限", Toast.LENGTH_SHORT).show(); |
| 233 | } | 238 | } |
| 234 | } | 239 | } |
| 235 | 240 | ||
| 236 | @Override | 241 | @Override |
| 237 | public void onDenied(List<String> permissions, boolean never) { | 242 | public void onDenied(List<String> permissions, boolean never) { |
| 238 | XXPermissions.startPermissionActivity(getContext(), permissions); | 243 | XXPermissions.startPermissionActivity(getContext(), permissions); |
| 239 | } | 244 | } |
| 240 | }); | 245 | }); |
| 241 | } else { | 246 | } else { |
| 242 | showButtonDialog(type); | 247 | showButtonDialog(type); |
| 243 | } | 248 | } |
| 244 | } | 249 | } |
| 245 | 250 | ||
| 246 | private void showButtonDialog(int type) { | 251 | private void showButtonDialog(int type) { |
| 247 | MyButtomDialog dialog = new MyButtomDialog(getActivity(), R.style.BottomSheetDialog); | 252 | MyButtomDialog dialog = new MyButtomDialog(getActivity(), R.style.BottomSheetDialog); |
| 248 | View bottomView = LayoutInflater.from(getActivity()).inflate(R.layout.bottom_sheet_layout, null); | 253 | View bottomView = LayoutInflater.from(getActivity()).inflate(R.layout.bottom_sheet_layout, null); |
| 249 | dialog.setContentView(bottomView); | 254 | dialog.setContentView(bottomView); |
| 250 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | 255 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { |
| 251 | @Override | 256 | @Override |
| 252 | public void onClick(View view) { | 257 | public void onClick(View view) { |
| 253 | dialog.dismiss(); | 258 | dialog.dismiss(); |
| 254 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 259 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| 255 | //确保有相机来处理Intent | 260 | //确保有相机来处理Intent |
| 256 | filePath = requireActivity().getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; | 261 | filePath = requireActivity().getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; |
| 257 | File photoFile = new File(filePath); | 262 | File photoFile = new File(filePath); |
| 258 | 263 | ||
| 259 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | 264 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri |
| 260 | Uri photoUri = FileProvider.getUriForFile(requireActivity(), "com.hjx.parent.fileprovider", photoFile); | 265 | Uri photoUri = FileProvider.getUriForFile(requireActivity(), "com.hjx.parent.fileprovider", photoFile); |
| 261 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 266 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
| 262 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | 267 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); |
| 263 | startActivityForResult(takePictureIntent, type == 0 ? 0xA01 : 0xA02); | 268 | startActivityForResult(takePictureIntent, type == 0 ? 0xA01 : 0xA02); |
| 264 | } | 269 | } |
| 265 | }); | 270 | }); |
| 266 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | 271 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { |
| 267 | @Override | 272 | @Override |
| 268 | public void onClick(View view) { | 273 | public void onClick(View view) { |
| 269 | dialog.dismiss(); | 274 | dialog.dismiss(); |
| 270 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getActivity().getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 | 275 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getActivity().getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 |
| 271 | .iHandlerCallBack(new HandlerCallBack(type)) //图片选择器生命周期监听(直接打开摄像头时无效) | 276 | .iHandlerCallBack(new HandlerCallBack(type)) //图片选择器生命周期监听(直接打开摄像头时无效) |
| 272 | .multiSelect(true) //是否多选 | 277 | .multiSelect(true) //是否多选 |
| 273 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false | 278 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false |
| 274 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 | 279 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 |
| 275 | .maxImageSelectable(5) //图片可选择数 | 280 | .maxImageSelectable(5) //图片可选择数 |
| 276 | .maxHeight(1920) //图片最大高度 | 281 | .maxHeight(1920) //图片最大高度 |
| 277 | .maxWidth(1920) //图片最大宽度 | 282 | .maxWidth(1920) //图片最大宽度 |
| 278 | .maxImageSize(3) //图片最大大小Mb | 283 | .maxImageSize(3) //图片最大大小Mb |
| 279 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); | 284 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); |
| 280 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(getActivity()); | 285 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(getActivity()); |
| 281 | 286 | ||
| 282 | } | 287 | } |
| 283 | }); | 288 | }); |
| 284 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | 289 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { |
| 285 | @Override | 290 | @Override |
| 286 | public void onClick(View view) { | 291 | public void onClick(View view) { |
| 287 | dialog.dismiss(); | 292 | dialog.dismiss(); |
| 288 | } | 293 | } |
| 289 | }); | 294 | }); |
| 290 | dialog.show(); | 295 | dialog.show(); |
| 291 | } | 296 | } |
| 292 | 297 | ||
| 293 | @SuppressLint("CheckResult") | 298 | @SuppressLint("CheckResult") |
| 294 | protected void getHomework(String subject) { | 299 | protected void getHomework(String subject) { |
| 295 | if (studentBean == null) return; | 300 | if (studentBean == null) return; |
| 296 | NetWorks.service_url.getStudentHomework(NetWorks.getHeader(), studentBean.getStuId()) | 301 | NetWorks.service_url.getStudentHomework(NetWorks.getHeader(), studentBean.getStuId()) |
| 297 | .subscribeOn(Schedulers.io()) | 302 | .subscribeOn(Schedulers.io()) |
| 298 | .observeOn(AndroidSchedulers.mainThread()) | 303 | .observeOn(AndroidSchedulers.mainThread()) |
| 299 | .compose(RxLifecycleAndroid.bindFragment(getRxLifecycle())) | 304 | .compose(RxLifecycleAndroid.bindFragment(getRxLifecycle())) |
| 300 | .map(ResponseResult::getData) | 305 | .map(ResponseResult::getData) |
| 301 | .toObservable() | 306 | .toObservable() |
| 302 | .concatMap(Observable::fromIterable) | 307 | .concatMap(Observable::fromIterable) |
| 303 | .filter(data -> subject.equals(data.getSubject())) | 308 | .filter(data -> subject.equals(data.getSubject())) |
| 304 | //.filter(data -> data.getRight() == null) | 309 | //.filter(data -> data.getRight() == null) |
| 305 | .take(5) | 310 | .take(5) |
| 306 | .toList() | 311 | .toList() |
| 307 | .subscribe((data, th) -> { | 312 | .subscribe((data, th) -> { |
| 308 | if (th != null) th.printStackTrace(); | 313 | if (th != null) th.printStackTrace(); |
| 309 | homeworkAdapter.setNewData(data); | 314 | homeworkAdapter.setNewData(data); |
| 310 | if (binding.tabLayout.getSelectedTabPosition() == 1) { | 315 | if (binding.tabLayout.getSelectedTabPosition() == 1) { |
| 311 | binding.rvMain.setVisibility(data == null || data.isEmpty() ? View.GONE : View.VISIBLE); | 316 | binding.rvMain.setVisibility(data == null || data.isEmpty() ? View.GONE : View.VISIBLE); |
| 312 | binding.llEmpty.setVisibility(data == null || data.isEmpty() ? View.VISIBLE : View.GONE); | 317 | binding.llEmpty.setVisibility(data == null || data.isEmpty() ? View.VISIBLE : View.GONE); |
| 313 | } | 318 | } |
| 314 | }); | 319 | }); |
| 315 | } | 320 | } |
| 316 | 321 | ||
| 317 | private void getError(String subject) { | 322 | private void getError(String subject) { |
| 318 | if (studentBean == null) { | 323 | if (studentBean == null) { |
| 319 | return; | 324 | return; |
| 320 | } | 325 | } |
| 321 | Map<String, Object> map = new HashMap<>(); | 326 | Map<String, Object> map = new HashMap<>(); |
| 322 | map.put("subject", subject); | 327 | map.put("subject", subject); |
| 323 | map.put("stuId", studentBean.getStuId()); | 328 | map.put("stuId", studentBean.getStuId()); |
| 324 | map.put("pageSize", 5); | 329 | map.put("pageSize", 5); |
| 325 | map.put("pageNum", 1); | 330 | map.put("pageNum", 1); |
| 326 | NetWorks.getError(map, new Observer<ResponseResult<PageInfo<TopicBean>>>() { | 331 | NetWorks.getError(map, new Observer<ResponseResult<PageInfo<TopicBean>>>() { |
| 327 | @Override | 332 | @Override |
| 328 | public void onSubscribe(Disposable d) { | 333 | public void onSubscribe(Disposable d) { |
| 329 | } | 334 | } |
| 330 | @Override | 335 | @Override |
| 331 | public void onNext(ResponseResult<PageInfo<TopicBean>> result) { | 336 | public void onNext(ResponseResult<PageInfo<TopicBean>> result) { |
| 332 | if (result.getData() != null && result.getCode() == 200) { | 337 | if (result.getData() != null && result.getCode() == 200) { |
| 333 | List<TopicBean> topicBeans = result.getData().getList(); | 338 | List<TopicBean> topicBeans = result.getData().getList(); |
| 334 | errorAdapter.refresh(topicBeans); | 339 | errorAdapter.refresh(topicBeans); |
| 335 | if (binding.tabLayout.getSelectedTabPosition() == 0) { | 340 | if (binding.tabLayout.getSelectedTabPosition() == 0) { |
| 336 | if (topicBeans.size() > 0) { | 341 | if (topicBeans.size() > 0) { |
| 337 | getBinding().rvMain.setVisibility(View.VISIBLE); | 342 | getBinding().rvMain.setVisibility(View.VISIBLE); |
| 338 | getBinding().llEmpty.setVisibility(View.GONE); | 343 | getBinding().llEmpty.setVisibility(View.GONE); |
| 339 | } else { | 344 | } else { |
| 340 | getBinding().rvMain.setVisibility(View.GONE); | 345 | getBinding().rvMain.setVisibility(View.GONE); |
| 341 | getBinding().llEmpty.setVisibility(View.VISIBLE); | 346 | getBinding().llEmpty.setVisibility(View.VISIBLE); |
| 342 | } | 347 | } |
| 343 | } | 348 | } |
| 344 | } | 349 | } |
| 345 | } | 350 | } |
| 346 | @Override | 351 | @Override |
| 347 | public void onError(Throwable e) { | 352 | public void onError(Throwable e) { |
| 348 | e.printStackTrace(); | 353 | e.printStackTrace(); |
| 349 | } | 354 | } |
| 350 | @Override | 355 | @Override |
| 351 | public void onComplete() { | 356 | public void onComplete() { |
| 352 | } | 357 | } |
| 353 | }); | 358 | }); |
| 354 | } | 359 | } |
| 355 | 360 | ||
| 356 | @Override | 361 | @Override |
| 357 | public void onResume() { | 362 | public void onResume() { |
| 358 | super.onResume(); | 363 | super.onResume(); |
| 359 | String subStr = getResources().getStringArray(R.array.filter_subject)[subject]; | 364 | String subStr = getResources().getStringArray(R.array.filter_subject)[subject]; |
| 360 | getError(subStr); | 365 | getError(subStr); |
| 361 | getHomework(subStr); | 366 | getHomework(subStr); |
| 362 | } | 367 | } |
| 363 | 368 | ||
| 364 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { | 369 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { |
| 365 | int type; | 370 | int type; |
| 366 | public HandlerCallBack(int type) { | 371 | public HandlerCallBack(int type) { |
| 367 | this.type = type; | 372 | this.type = type; |
| 368 | } | 373 | } |
| 369 | 374 | ||
| 370 | private String TAG = "---ImagePicker---"; | 375 | private String TAG = "---ImagePicker---"; |
| 371 | List<ImageInfo> photoList = new ArrayList<>(); | 376 | List<ImageInfo> photoList = new ArrayList<>(); |
| 372 | 377 | ||
| 373 | @Override | 378 | @Override |
| 374 | public void onStart() { | 379 | public void onStart() { |
| 375 | Log.i(TAG, "onStart: 开启"); | 380 | Log.i(TAG, "onStart: 开启"); |
| 376 | } | 381 | } |
| 377 | 382 | ||
| 378 | @Override | 383 | @Override |
| 379 | public void onSuccess(List<ImageInfo> photoList) { | 384 | public void onSuccess(List<ImageInfo> photoList) { |
| 380 | this.photoList = photoList; | 385 | this.photoList = photoList; |
| 381 | Log.i(TAG, "onSuccess: 返回数据"); | 386 | Log.i(TAG, "onSuccess: 返回数据"); |
| 382 | } | 387 | } |
| 383 | 388 | ||
| 384 | @Override | 389 | @Override |
| 385 | public void onCancel() { | 390 | public void onCancel() { |
| 386 | Log.i(TAG, "onCancel: 取消"); | 391 | Log.i(TAG, "onCancel: 取消"); |
| 387 | } | 392 | } |
| 388 | 393 | ||
| 389 | @Override | 394 | @Override |
| 390 | public void onFinish(List<ImageInfo> selectImage) { | 395 | public void onFinish(List<ImageInfo> selectImage) { |
| 391 | if (selectImage.size() == photoList.size()) { | 396 | if (selectImage.size() == photoList.size()) { |
| 392 | ArrayList<String> strings = new ArrayList<>(); | 397 | ArrayList<String> strings = new ArrayList<>(); |
| 393 | Intent intent = new Intent(getActivity(), ImageActivity.class); | 398 | Intent intent = new Intent(getActivity(), ImageActivity.class); |
| 394 | for (ImageInfo imageInfo : selectImage) { | 399 | for (ImageInfo imageInfo : selectImage) { |
| 395 | strings.add(imageInfo.getPath()); | 400 | strings.add(imageInfo.getPath()); |
| 396 | } | 401 | } |
| 397 | intent.putStringArrayListExtra("images", strings); | 402 | intent.putStringArrayListExtra("images", strings); |
| 398 | intent.putExtra("type", type); | 403 | intent.putExtra("type", type); |
| 399 | startActivity(intent); | 404 | startActivity(intent); |
| 400 | } | 405 | } |
| 401 | } | 406 | } |
| 402 | 407 | ||
| 403 | @Override | 408 | @Override |
| 404 | public void onError() { | 409 | public void onError() { |
| 405 | Log.i(TAG, "onError: 出错"); | 410 | Log.i(TAG, "onError: 出错"); |
| 406 | } | 411 | } |
| 407 | } | 412 | } |
| 408 | 413 | ||
| 409 | @Override | 414 | @Override |
| 410 | public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 415 | public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 411 | super.onActivityResult(requestCode, resultCode, data); | 416 | super.onActivityResult(requestCode, resultCode, data); |
| 412 | if (resultCode != RESULT_OK) return; | 417 | if (resultCode != RESULT_OK) return; |
| 413 | if (requestCode == 0xA01 || requestCode == 0xA02 && !TextUtils.isEmpty(filePath)) { | 418 | if (requestCode == 0xA01 || requestCode == 0xA02 && !TextUtils.isEmpty(filePath)) { |
| 414 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); | 419 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); |
| 415 | String path = getContext().getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; | 420 | String path = getContext().getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; |
| 416 | CommonUtil.saveBitmapToUri(b, path); | 421 | CommonUtil.saveBitmapToUri(b, path); |
| 417 | ArrayList<String> strings = new ArrayList<>(); | 422 | ArrayList<String> strings = new ArrayList<>(); |
| 418 | Intent intent = new Intent(getContext(), ImageActivity.class); | 423 | Intent intent = new Intent(getContext(), ImageActivity.class); |
| 419 | strings.add(path); | 424 | strings.add(path); |
| 420 | intent.putStringArrayListExtra("images", strings); | 425 | intent.putStringArrayListExtra("images", strings); |
| 421 | intent.putExtra("type", requestCode == 0xA01 ? 0 : 1); | 426 | intent.putExtra("type", requestCode == 0xA01 ? 0 : 1); |
| 422 | startActivity(intent); | 427 | startActivity(intent); |
| 423 | } | 428 | } |
| 424 | } | 429 | } |
| 425 | } | 430 | } |
| 426 | 431 |
app/src/main/res/drawable/png_ic_chemistry_off.png
12.3 KB
app/src/main/res/drawable/png_ic_chinese_off.png
11.1 KB
app/src/main/res/drawable/png_ic_english_off.png
13.9 KB
app/src/main/res/drawable/png_ic_math_off.png
10.8 KB
app/src/main/res/drawable/png_ic_physics_off.png
11.8 KB
app/src/main/res/drawable/state_ic_chemistry.xml
| File was created | 1 | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | <selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| 3 | <item android:drawable="@drawable/png_ic_chemistry" android:state_activated="true"/> | ||
| 4 | <item android:drawable="@drawable/png_ic_chemistry_off"/> | ||
| 5 | </selector> |
app/src/main/res/drawable/state_ic_chinese.xml
| File was created | 1 | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | <selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| 3 | <item android:drawable="@drawable/png_ic_chinese" android:state_activated="true"/> | ||
| 4 | <item android:drawable="@drawable/png_ic_chinese_off" /> | ||
| 5 | </selector> |
app/src/main/res/drawable/state_ic_english.xml
| File was created | 1 | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | <selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| 3 | <item android:drawable="@drawable/png_ic_english" android:state_activated="true"/> | ||
| 4 | <item android:drawable="@drawable/png_ic_english_off"/> | ||
| 5 | </selector> |
app/src/main/res/drawable/state_ic_math.xml
| File was created | 1 | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | <selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| 3 | |||
| 4 | <item android:drawable="@drawable/png_ic_math" android:state_activated="true"/> | ||
| 5 | <item android:drawable="@drawable/png_ic_math_off"/> | ||
| 6 | |||
| 7 | </selector> |
app/src/main/res/drawable/state_ic_physics.xml
| File was created | 1 | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | <selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| 3 | <item android:drawable="@drawable/png_ic_physics" android:state_activated="true"/> | ||
| 4 | <item android:drawable="@drawable/png_ic_physics_off"/> | ||
| 5 | </selector> |