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