Skip to content

Commit

Permalink
use rx permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirtyDegreesRay committed Jan 2, 2018
1 parent 4ffe6b2 commit d2e09bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
7 changes: 1 addition & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,7 @@ dependencies {
compile "com.google.dagger:dagger:${DAGGER_VERSION}"
annotationProcessor "com.google.dagger:dagger-compiler:${DAGGER_VERSION}"

//Android6.0以上权限获取工具
//PermissionsDispatcher provides a simple annotation-based API to handle runtime permissions in Android Marshmallow.
// androidApt: 'com.neenbedankt.gradle.plugins:android-apt:1.8',
// compile "com.github.hotchemi:permissionsdispatcher:${PERMISSIONS_DISPATCHER_VERSION}"
// annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:${PERMISSIONS_DISPATCHER_VERSION}"
compile "com.yanzhenjie:permission:${AND_PERMISSION_VERSION}"
compile "com.tbruyelle.rxpermissions:rxpermissions:${RX_PERMISSION_VERSION}"

compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
Expand Down
31 changes: 13 additions & 18 deletions app/src/main/java/com/thirtydegreesray/openhub/http/Downloader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.thirtydegreesray.openhub.http;

import android.Manifest;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
Expand All @@ -9,18 +10,14 @@
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.widget.Toast;

import com.orhanobut.logger.Logger;
import com.tbruyelle.rxpermissions.RxPermissions;
import com.thirtydegreesray.openhub.R;
import com.thirtydegreesray.openhub.ui.activity.base.BaseActivity;
import com.thirtydegreesray.openhub.util.AppUtils;
import com.thirtydegreesray.openhub.util.StringUtils;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.Permission;
import com.yanzhenjie.permission.PermissionListener;

import java.util.List;

import es.dmoral.toasty.Toasty;

Expand Down Expand Up @@ -62,22 +59,20 @@ public void start(String url, String fileName) {
AppUtils.showDownloadServiceSetting(mContext);
return ;
}

AndPermission.with(mContext)
.permission(Permission.STORAGE)
.callback(new PermissionListener() {
@Override
public void onSucceed(int requestCode, @NonNull List<String> grantPermissions) {
if(BaseActivity.getCurActivity() == null){
Toasty.error(mContext, mContext.getString(R.string.download_failed), Toast.LENGTH_SHORT).show();
return;
}
new RxPermissions(BaseActivity.getCurActivity())
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.subscribe(granted -> {
if (granted) {
start();
}

@Override
public void onFailed(int requestCode, @NonNull List<String> deniedPermissions) {
} else {
Toasty.error(mContext, mContext.getString(R.string.permission_storage_denied),
Toast.LENGTH_LONG).show();
}
})
.start();
});
}catch (Exception e){
Toasty.error(mContext, e.getMessage()).show();
}
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ FILE_DOWNLOADER_VERSION=0.3.1
RXJAVA_VERSION=1.1.0
RETROFIT_VERSION=2.1.0
DAGGER_VERSION=2.11
#PERMISSIONS_DISPATCHER_VERSION=2.1.3
AND_PERMISSION_VERSION=1.1.0
RX_PERMISSION_VERSION=0.9.4@aar
RETROLAMBDA_VERSION=2.3.0
OKHTTP_VERSION=3.6.0
FASTJSON_VERSION=1.1.46.android
Expand Down

0 comments on commit d2e09bb

Please sign in to comment.