|
1 | 1 | package net.coding.program.maopao; |
2 | 2 |
|
| 3 | +import android.annotation.SuppressLint; |
3 | 4 | import android.app.Activity; |
4 | 5 | import android.content.Intent; |
5 | 6 | import android.graphics.Bitmap; |
|
25 | 26 | import com.nostra13.universalimageloader.core.ImageLoader; |
26 | 27 | import com.nostra13.universalimageloader.core.assist.ImageSize; |
27 | 28 | import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; |
| 29 | +import com.tbruyelle.rxpermissions2.RxPermissions; |
28 | 30 |
|
29 | 31 | import net.coding.program.R; |
30 | 32 | import net.coding.program.common.Global; |
@@ -276,26 +278,28 @@ private void setPopTopicIconShow() { |
276 | 278 | ((ImageView) findViewById(R.id.popTopic)).setImageResource(icon); |
277 | 279 | } |
278 | 280 |
|
| 281 | + @SuppressLint("CheckResult") |
279 | 282 | private void startPhotoPickActivity() { |
280 | | - if (!PermissionUtil.writeExtralStorage(this)) { |
281 | | - return; |
282 | | - } |
283 | | - |
284 | | - int count = Global.PHOTO_MAX_COUNT - mData.size(); |
285 | | - if (count <= 0) { |
286 | | - showButtomToast(String.format("最多能添加%s张图片", Global.PHOTO_MAX_COUNT)); |
287 | | - return; |
288 | | - } |
289 | | - |
290 | | - Intent intent = new Intent(MaopaoAddActivity.this, PhotoPickActivity.class); |
291 | | - intent.putExtra(PhotoPickActivity.Companion.getEXTRA_MAX(), Global.PHOTO_MAX_COUNT); |
292 | | - |
293 | | - ArrayList<ImageInfo> pickImages = new ArrayList<>(); |
294 | | - for (PhotoData item : mData) { |
295 | | - pickImages.add(item.mImageinfo); |
296 | | - } |
297 | | - intent.putExtra(PhotoPickActivity.Companion.getEXTRA_PICKED(), pickImages); |
298 | | - startActivityForResult(intent, RESULT_REQUEST_PICK_PHOTO); |
| 283 | + new RxPermissions(this) |
| 284 | + .request(PermissionUtil.STORAGE) |
| 285 | + .subscribe(granted -> { |
| 286 | + if (granted) { |
| 287 | + int count = Global.PHOTO_MAX_COUNT - mData.size(); |
| 288 | + if (count <= 0) { |
| 289 | + showButtomToast(String.format("最多能添加%s张图片", Global.PHOTO_MAX_COUNT)); |
| 290 | + } else { |
| 291 | + Intent intent = new Intent(MaopaoAddActivity.this, PhotoPickActivity.class); |
| 292 | + intent.putExtra(PhotoPickActivity.Companion.getEXTRA_MAX(), Global.PHOTO_MAX_COUNT); |
| 293 | + |
| 294 | + ArrayList<ImageInfo> pickImages = new ArrayList<>(); |
| 295 | + for (PhotoData item : mData) { |
| 296 | + pickImages.add(item.mImageinfo); |
| 297 | + } |
| 298 | + intent.putExtra(PhotoPickActivity.Companion.getEXTRA_PICKED(), pickImages); |
| 299 | + startActivityForResult(intent, RESULT_REQUEST_PICK_PHOTO); |
| 300 | + } |
| 301 | + } |
| 302 | + }); |
299 | 303 | } |
300 | 304 |
|
301 | 305 | private void updateAddButton() { |
@@ -653,18 +657,22 @@ public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { |
653 | 657 | } |
654 | 658 | } |
655 | 659 |
|
| 660 | + @SuppressLint("CheckResult") |
656 | 661 | @Click(R.id.locationText) |
657 | 662 | void chooseLocation() { |
658 | 663 | if (PhoneType.isX86or64()) { |
659 | 664 | showMiddleToast("定位功能不支持x86手机"); |
660 | 665 | return; |
661 | 666 | } |
662 | 667 |
|
663 | | - if (!PermissionUtil.checkLocation(this)) { |
664 | | - return; |
665 | | - } |
| 668 | + new RxPermissions(this) |
| 669 | + .request(PermissionUtil.LOCATION) |
| 670 | + .subscribe(granted -> { |
| 671 | + if (granted) { |
| 672 | + LocationSearchActivity_.intent(this).selectedLocation(currentLocation).startForResult(RESULT_REQUEST_LOCATION); |
| 673 | + } |
| 674 | + }); |
666 | 675 |
|
667 | | - LocationSearchActivity_.intent(this).selectedLocation(currentLocation).startForResult(RESULT_REQUEST_LOCATION); |
668 | 676 | } |
669 | 677 |
|
670 | 678 | @OnActivityResult(RESULT_REQUEST_LOCATION) |
|
0 commit comments