From df9054d817fad89dba6f73be287633b9ba8af9e4 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Sun, 6 Jun 2021 10:49:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=98=E5=82=A8=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 + app/src/main/assets/updatelog.fy | 5 ++ .../xyz/fycz/myreader/common/APPCONST.java | 52 +++++++++----- .../java/xyz/fycz/myreader/enums/Font.java | 2 +- .../myreader/ui/activity/MainActivity.java | 18 ----- .../ui/activity/QRCodeScanActivity.java | 67 ++++++++----------- .../ui/activity/ReplaceRuleActivity.java | 24 +++++-- .../myreader/ui/activity/SplashActivity.java | 66 ++++++------------ .../myreader/ui/adapter/BookcaseAdapter.java | 20 +++++- .../fycz/myreader/ui/dialog/UpdateDialog.java | 49 ++++++-------- .../ui/fragment/DIYSourceFragment.java | 48 ++++++++----- .../myreader/ui/fragment/MineFragment.java | 2 +- .../ui/popmenu/CustomizeLayoutMenu.java | 29 ++++++-- .../ui/presenter/BookcasePresenter.java | 44 ++++++------ .../myreader/util/PermissionsChecker.java | 31 --------- .../fycz/myreader/util/help/JsExtensions.java | 1 + .../fycz/myreader/util/utils/FileUtils.java | 4 ++ app/src/main/res/values/strings.xml | 5 +- app/version_code.properties | 4 +- 19 files changed, 243 insertions(+), 231 deletions(-) delete mode 100644 app/src/main/java/xyz/fycz/myreader/util/PermissionsChecker.java diff --git a/app/build.gradle b/app/build.gradle index d4d5008..074096d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -210,6 +210,9 @@ dependencies { //noinspection GradleDependency implementation 'com.github.gedoor:rhino-android:1.3' + //XXPermissions + implementation 'com.github.getActivity:XXPermissions:11.2' + } greendao { diff --git a/app/src/main/assets/updatelog.fy b/app/src/main/assets/updatelog.fy index 3c1f928..3bd54b9 100644 --- a/app/src/main/assets/updatelog.fy +++ b/app/src/main/assets/updatelog.fy @@ -1,3 +1,8 @@ +2021.06.06 +风月读书v2.1.0 +更新内容: +1、储存优化 + 2021.06.05 风月读书v2.0.9 更新内容: diff --git a/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java b/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java index b4f0ff3..e795aa2 100644 --- a/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java +++ b/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java @@ -3,8 +3,11 @@ package xyz.fycz.myreader.common; import android.os.Environment; import com.google.gson.reflect.TypeToken; +import com.hjq.permissions.Permission; +import com.hjq.permissions.XXPermissions; import xyz.fycz.myreader.R; +import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.util.utils.FileUtils; import java.io.File; @@ -22,21 +25,34 @@ public class APPCONST { public static String privateKey;//app私钥 public static final String KEY = ""; - public static final String FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/"; - public static final String SHARE_FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/share/"; - public static final String LOG_DIR = Environment.getExternalStorageDirectory() + "/FYReader/log/"; - public static final String BG_FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/bg/"; - public static final String TEM_FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/tem/"; - public static final String BACKUP_FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/backup/"; - public static final String TXT_BOOK_DIR = Environment.getExternalStorageDirectory() + "/FYReader/noveltxt/"; - public static final String FONT_BOOK_DIR = Environment.getExternalStorageDirectory() + "/FYReader/font/"; - public static final String UPDATE_APK_FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/apk/"; - public static final String QQ_DATA_DIR = Environment.getExternalStorageDirectory() + "/tencent/MobileQQ/data/"; + public static final String[] STORAGE_PERMISSIONS = new String[]{Permission.WRITE_EXTERNAL_STORAGE, + Permission.READ_EXTERNAL_STORAGE}; + + public static final String FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/"; + public static String TXT_BOOK_DIR = Environment.getExternalStorageDirectory().getAbsolutePath() + "/FYReader/noveltxt/"; + + public static String SHARE_FILE_DIR = (hasStoragePermission() ? + Environment.getExternalStorageDirectory().getAbsolutePath() : + FileUtils.getDataDir()) + "/FYReader/share/"; + public static String LOG_DIR = (hasStoragePermission() ? + Environment.getExternalStorageDirectory().getAbsolutePath() : + FileUtils.getDataDir()) + "/FYReader/log/"; + public static String BG_FILE_DIR = (hasStoragePermission() ? + Environment.getExternalStorageDirectory().getAbsolutePath() : + FileUtils.getDataDir()) + "/FYReader/bg/"; + public static String TEM_FILE_DIR = (hasStoragePermission() ? + Environment.getExternalStorageDirectory().getAbsolutePath() : + FileUtils.getDataDir()) + "/FYReader/tem/"; + public static String BACKUP_FILE_DIR = (hasStoragePermission() ? + Environment.getExternalStorageDirectory().getAbsolutePath() : + FileUtils.getDataDir()) + "/FYReader/backup/"; + public static String FONT_BOOK_DIR = (hasStoragePermission() ? + Environment.getExternalStorageDirectory().getAbsolutePath() : + FileUtils.getDataDir()) + "/FYReader/font/"; + public static String QQ_DATA_DIR = Environment.getExternalStorageDirectory() + "/tencent/MobileQQ/data/"; //BookCachePath (因为getCachePath引用了Context,所以必须是静态变量,不能够是静态常量) public static String BOOK_CACHE_PATH = FileUtils.getCachePath() + File.separator - + "book_cache"+ File.separator ; - public static String HTML_CACHE_PATH = FileUtils.getCachePath() + File.separator - + "html_cache"+ File.separator ; + + "book_cache" + File.separator; public static long exitTime; public static final int exitConfirmTime = 2000; @@ -94,8 +110,6 @@ public class APPCONST { public static final int SELECT_FILE_CODE = 10000; - public static final int PERMISSIONS_REQUEST_STORAGE = 10001; - //设置版本号 public static final int SETTING_VERSION = 11; @@ -120,4 +134,12 @@ public class APPCONST { public static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4168.3 Safari/537.36"; + private static Boolean hasStoragePermission = null; + + public static boolean hasStoragePermission() { + if (hasStoragePermission == null) { + hasStoragePermission = XXPermissions.isGranted(App.getmContext(), STORAGE_PERMISSIONS); + } + return hasStoragePermission; + } } diff --git a/app/src/main/java/xyz/fycz/myreader/enums/Font.java b/app/src/main/java/xyz/fycz/myreader/enums/Font.java index 052f5ad..f9a18f9 100644 --- a/app/src/main/java/xyz/fycz/myreader/enums/Font.java +++ b/app/src/main/java/xyz/fycz/myreader/enums/Font.java @@ -6,7 +6,7 @@ public enum Font { 默认字体( "默认字体"), 本地字体( "默认字体"), - 方正楷体( URLCONST.LAN_ZOUS_URL + " /ilLFMe6kefe"), + 方正楷体( URLCONST.LAN_ZOUS_URL + "/ilLFMe6kefe"), 方正行楷( URLCONST.LAN_ZOUS_URL + "/imFvne6keji"), 经典宋体(URLCONST.LAN_ZOUS_URL + "/idhI5e6keqf"), 方正硬笔行书(URLCONST.LAN_ZOUS_URL + "/ilVh6ep9xja"), diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java index 750c1e8..382d380 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java @@ -386,24 +386,6 @@ public class MainActivity extends BaseActivity { } } - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - switch (requestCode) { - case APPCONST.PERMISSIONS_REQUEST_STORAGE: { - // 如果取消权限,则返回的值为0 - if (grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - //跳转到 FileSystemActivity - Intent intent = new Intent(this, FileSystemActivity.class); - startActivity(intent); - - } else { - ToastUtils.showWarring("用户拒绝开启读写权限"); - } - } - } - } @Override protected void onDestroy() { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/QRCodeScanActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/QRCodeScanActivity.java index 343ef46..a334286 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/QRCodeScanActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/QRCodeScanActivity.java @@ -2,7 +2,6 @@ package xyz.fycz.myreader.ui.activity; import android.app.Activity; import android.content.Intent; -import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; @@ -11,9 +10,13 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; -import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; -import androidx.core.app.ActivityCompat; + +import com.hjq.permissions.OnPermissionCallback; +import com.hjq.permissions.Permission; +import com.hjq.permissions.XXPermissions; + +import java.util.List; import cn.bingoogolapple.qrcode.core.QRCodeView; import io.reactivex.Single; @@ -22,7 +25,6 @@ import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.BaseActivity; import xyz.fycz.myreader.base.observer.MySingleObserver; import xyz.fycz.myreader.databinding.ActivityQrcodeCaptureBinding; -import xyz.fycz.myreader.util.PermissionsChecker; import xyz.fycz.myreader.util.help.StringHelper; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.RxUtils; @@ -40,8 +42,6 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg private ActivityQrcodeCaptureBinding binding; private final int REQUEST_QR_IMAGE = 202; - private static final String CAMERA = "android.permission.CAMERA"; - private static final int PERMISSIONS_REQUEST_CAMERA = 101; private boolean flashlightIsOpen; private boolean needScale = true; private String picPath; @@ -104,16 +104,16 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg public void onScanQRCodeSuccess(String result) { Log.d("onScanQRCodeSuccess", needScale + ""); if (result == null) { - if (!needScale){ + if (!needScale) { needScale = true; if (StringHelper.isEmpty(picPath)) { return; } scanFromPath(picPath); - }else { + } else { ToastUtils.showError("二维码扫描失败"); } - }else { + } else { Intent intent = new Intent(); Log.d("result", result); intent.putExtra("result", result); @@ -124,9 +124,9 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg @Override public void onCameraAmbientBrightnessChanged(boolean isDark) { - if (isDark){ + if (isDark) { binding.llFlashlight.setVisibility(View.VISIBLE); - }else { + } else { if (!flashlightIsOpen) { binding.llFlashlight.setVisibility(View.GONE); } @@ -144,32 +144,23 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg } private void requestPermission() { - //获取读取和写入SD卡的权限 - if (new PermissionsChecker(this).lacksPermissions(CAMERA)) { - ActivityCompat.requestPermissions(this, new String[]{CAMERA}, PERMISSIONS_REQUEST_CAMERA); - } else { - startScan(); - } - } + //获取相机权限 + XXPermissions.with(this) + .permission(Permission.CAMERA) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + //申请权限成功 + startScan(); + } - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - switch (requestCode) { - case PERMISSIONS_REQUEST_CAMERA: { - // 如果取消权限,则返回的值为0 - if (grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - //申请权限成功 - startScan(); - } else { - //申请权限失败 - finish(); - ToastUtils.showWarring("请给予相机权限,否则无法进行扫码!"); - } - return; - } - } + @Override + public void onDenied(List permissions, boolean never) { + //申请权限失败 + finish(); + ToastUtils.showWarring("请给予相机权限,否则无法进行扫码!"); + } + }); } // 添加菜单 @@ -206,7 +197,7 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg } } - private void scanFromPath(String path){ + private void scanFromPath(String path) { // 本来就用到 QRCodeView 时可直接调 QRCodeView 的方法,走通用的回调 Single.create((SingleOnSubscribe) emitter -> { Bitmap bitmap = BitmapFactory.decodeFile(path); @@ -228,7 +219,7 @@ public class QRCodeScanActivity extends BaseActivity implements QRCodeView.Deleg private void chooseFromGallery() { try { - if (needScale){ + if (needScale) { ToastUtils.showInfo("选择图片仅支持扫描书籍分享图片"); } Intent intent = new Intent(Intent.ACTION_GET_CONTENT); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReplaceRuleActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReplaceRuleActivity.java index 9548af7..9e52ea6 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReplaceRuleActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReplaceRuleActivity.java @@ -17,6 +17,8 @@ import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; +import com.hjq.permissions.OnPermissionCallback; +import com.hjq.permissions.XXPermissions; import com.kongzue.dialogx.dialogs.BottomMenu; import java.util.ArrayList; @@ -244,11 +246,23 @@ public class ReplaceRuleActivity extends BaseActivity { ToastUtils.showWarring("当前没有任何规则,无法导出!"); return true; } - if (FileUtils.writeText(GsonExtensionsKt.getGSON().toJson(mReplaceRules), - FileUtils.getFile(APPCONST.FILE_DIR + "ReplaceRule.json"))) { - DialogCreator.createTipDialog(this, - "内容替换规则导出成功,导出位置:" + APPCONST.FILE_DIR + "ReplaceRule.json"); - } + XXPermissions.with(this) + .permission(APPCONST.STORAGE_PERMISSIONS) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + if (FileUtils.writeText(GsonExtensionsKt.getGSON().toJson(mReplaceRules), + FileUtils.getFile(APPCONST.FILE_DIR + "ReplaceRule.json"))) { + DialogCreator.createTipDialog(ReplaceRuleActivity.this, + "内容替换规则导出成功,导出位置:" + APPCONST.FILE_DIR + "ReplaceRule.json"); + } + } + + @Override + public void onDenied(List permissions, boolean never) { + ToastUtils.showWarring("没有储存权限!"); + } + }); } else if (itemId == R.id.action_reverse) { for (ReplaceRuleBean ruleBean : mReplaceRules) { ruleBean.setEnable(!ruleBean.getEnable()); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java index dd50568..c9735d5 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java @@ -17,11 +17,15 @@ import androidx.core.app.ActivityCompat; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.signature.ObjectKey; import com.gyf.immersionbar.ImmersionBar; +import com.hjq.permissions.OnPermissionCallback; +import com.hjq.permissions.Permission; +import com.hjq.permissions.XXPermissions; import com.weaction.ddsdk.ad.DdSdkSplashAd; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; +import java.util.List; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; @@ -33,7 +37,6 @@ import xyz.fycz.myreader.greendao.service.BookGroupService; import xyz.fycz.myreader.ui.dialog.MyAlertDialog; import xyz.fycz.myreader.util.help.DateHelper; import xyz.fycz.myreader.util.IOUtils; -import xyz.fycz.myreader.util.PermissionsChecker; import xyz.fycz.myreader.util.SharedPreUtils; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.AdUtils; @@ -46,12 +49,6 @@ public class SplashActivity extends BaseActivity { /*************Constant**********/ public static final String TAG = SplashActivity.class.getSimpleName(); public static int WAIT_INTERVAL = 0; - private static final int PERMISSIONS_REQUEST_STORAGE = 1; - - static final String[] PERMISSIONS = { - Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE - }; private ActivitySplashBinding binding; private SharedPreUtils spu; @@ -59,7 +56,6 @@ public class SplashActivity extends BaseActivity { private int adTimes; private boolean hasStart = false; - private PermissionsChecker mPermissionsChecker; //创建子线程 private Runnable start = () -> { if (!hasStart && !App.isDestroy(SplashActivity.this)) { @@ -115,22 +111,12 @@ public class SplashActivity extends BaseActivity { //loadImage(); boolean agreePrivacyPolicy = SharedPreUtils.getInstance().getBoolean("agreePrivacyPolicy"); if (agreePrivacyPolicy) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { - mPermissionsChecker = new PermissionsChecker(this); - requestPermission(); - } else { - start(); - } + requestPermission(); } else { MyAlertDialog.showPrivacyDialog(this, (dialog, which) -> { SharedPreUtils.getInstance().putBoolean("agreePrivacyPolicy", true); - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { - mPermissionsChecker = new PermissionsChecker(this); - requestPermission(); - } else { - start(); - } - }, (dialog, which) -> finish()); + requestPermission(); + }, (dialog, which) -> android.os.Process.killProcess(android.os.Process.myPid())); } } @@ -348,33 +334,23 @@ public class SplashActivity extends BaseActivity { private void requestPermission() { //获取读取和写入SD卡的权限 - if (mPermissionsChecker.lacksPermissions(PERMISSIONS)) { - ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSIONS_REQUEST_STORAGE); - } else { - start(); - } - } + XXPermissions.with(this) + .permission(APPCONST.STORAGE_PERMISSIONS) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + start(); + } - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - switch (requestCode) { - case PERMISSIONS_REQUEST_STORAGE: { - // 如果取消权限,则返回的值为0 - if (grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - //申请权限成功 - start(); - } else { - //申请权限失败 - finish(); - ToastUtils.showWarring("请给予储存权限,否则程序无法正常运行!"); - } - return; - } - } + @Override + public void onDenied(List permissions, boolean never) { + ToastUtils.showWarring("储存权限被拒绝,部分功能可能无法正常运行!"); + start(); + } + }); } + private void countTodayAd() { String today = DateHelper.getYearMonthDay1(); todayAdCount++; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseAdapter.java index 37e09ad..0594d31 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseAdapter.java @@ -12,6 +12,8 @@ import androidx.annotation.NonNull; import androidx.appcompat.widget.SwitchCompat; import androidx.recyclerview.widget.RecyclerView; +import com.hjq.permissions.OnPermissionCallback; +import com.hjq.permissions.XXPermissions; import com.kongzue.dialogx.dialogs.BottomDialog; import com.kongzue.dialogx.dialogs.BottomMenu; import com.kongzue.dialogx.interfaces.OnBindView; @@ -450,7 +452,23 @@ public abstract class BookcaseAdapter extends RecyclerView.Adapter { dialog.dismiss(); Single.create((SingleOnSubscribe) emitter -> { - emitter.onSuccess(unionChapterCathe(mBook)); + XXPermissions.with(mContext) + .permission(APPCONST.STORAGE_PERMISSIONS) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + try { + emitter.onSuccess(unionChapterCathe(mBook)); + } catch (IOException e) { + emitter.onError(e); + } + } + + @Override + public void onDenied(List permissions, boolean never) { + ToastUtils.showWarring("没有储存权限!"); + } + }); }).compose(RxUtils::toSimpleSingle).subscribe(new MySingleObserver() { @Override public void onSuccess(@NotNull Boolean aBoolean) { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/dialog/UpdateDialog.java b/app/src/main/java/xyz/fycz/myreader/ui/dialog/UpdateDialog.java index 85955a6..d1cc913 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/dialog/UpdateDialog.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/dialog/UpdateDialog.java @@ -25,6 +25,9 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentTransaction; +import com.hjq.permissions.OnPermissionCallback; +import com.hjq.permissions.Permission; +import com.hjq.permissions.XXPermissions; import com.liulishuo.filedownloader.BaseDownloadTask; import com.liulishuo.filedownloader.FileDownloadLargeFileListener; import com.liulishuo.filedownloader.FileDownloader; @@ -35,9 +38,11 @@ import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLDecoder; +import java.util.List; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; +import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.databinding.FragmentUpdateBinding; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.webapi.LanZousApi; @@ -91,11 +96,19 @@ public class UpdateDialog extends Fragment { // if (listener != null) { // listener.onConfirm(v); // } else { - if (ActivityCompat.checkSelfPermission(mActivity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_WRITE_EXTERNAL_STORAGE); - } else { - downloadApk(appUrl); - } + XXPermissions.with(mActivity) + .permission(APPCONST.STORAGE_PERMISSIONS) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + downloadApk(appUrl); + } + + @Override + public void onDenied(List permissions, boolean never) { + ToastUtils.showWarring("请勿拒绝储存权限,否则无法更新应用!"); + } + }); // } }); binding.btBrowser.setOnClickListener(v -> { @@ -255,7 +268,7 @@ public class UpdateDialog extends Fragment { baseDownloadTask = FileDownloader.getImpl() .create(decodeUrl) .setPath(path, new File(path).isDirectory()) - .setCallbackProgressMinInterval(100) + .setCallbackProgressMinInterval(30) .setListener(new FileDownloadLargeFileListener() { @Override protected void pending(BaseDownloadTask task, long soFarBytes, long totalBytes) { @@ -300,30 +313,6 @@ public class UpdateDialog extends Fragment { baseDownloadTask.start(); } - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - if (requestCode == PERMISSION_WRITE_EXTERNAL_STORAGE) { - if (grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - // 权限被用户同意,可以去放肆了。 - if (ActivityCompat.checkSelfPermission(mActivity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - // TODO: Consider calling - // ActivityCompat#requestPermissions - // here to request the missing permissions, and then overriding - // public void onRequestPermissionsResult(int requestCode, String[] permissions, - // int[] grantResults) - // to handle the case where the user grants the permission. See the documentation - // for ActivityCompat#requestPermissions for more details. - return; - } else { - downloadApk(appUrl); - } - } else { - // 权限被用户拒绝了,洗洗睡吧。 - } - } - } /** * 安装 diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/DIYSourceFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/DIYSourceFragment.java index d43283a..e6fadc2 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/DIYSourceFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/DIYSourceFragment.java @@ -17,6 +17,8 @@ import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.hjq.permissions.OnPermissionCallback; +import com.hjq.permissions.XXPermissions; import com.kongzue.dialogx.dialogs.BottomMenu; import java.io.File; @@ -197,7 +199,7 @@ public class DIYSourceFragment extends BaseFragment { }); binding.tvSourceTip.setOnClickListener(v -> { - MyAlertDialog.showTipDialogWithLink(getContext(), "书源说明",R.string.DIY_source_tip); + MyAlertDialog.showTipDialogWithLink(getContext(), "书源说明", R.string.DIY_source_tip); }); binding.ivGroup.setOnClickListener(this::showSourceGroupMenu); @@ -383,20 +385,32 @@ public class DIYSourceFragment extends BaseFragment { ToastUtils.showWarring("当前没有选择任何书源,无法导出!"); return; } - Single.create((SingleOnSubscribe) emitter -> { - emitter.onSuccess(FileUtils.writeText(GsonExtensionsKt.getGSON().toJson(sources), - FileUtils.getFile(APPCONST.FILE_DIR + "BookSources.json"))); - }).compose(RxUtils::toSimpleSingle).subscribe(new MySingleObserver() { - @Override - public void onSuccess(@NonNull Boolean aBoolean) { - if (aBoolean) { - DialogCreator.createTipDialog(sourceActivity, - "书源导出成功,导出位置:" + APPCONST.FILE_DIR + "BookSources.json"); - } else { - ToastUtils.showError("书源导出失败"); - } - } - }); + XXPermissions.with(this) + .permission(APPCONST.STORAGE_PERMISSIONS) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + Single.create((SingleOnSubscribe) emitter -> { + emitter.onSuccess(FileUtils.writeText(GsonExtensionsKt.getGSON().toJson(sources), + FileUtils.getFile(APPCONST.FILE_DIR + "BookSources.json"))); + }).compose(RxUtils::toSimpleSingle).subscribe(new MySingleObserver() { + @Override + public void onSuccess(@NonNull Boolean aBoolean) { + if (aBoolean) { + DialogCreator.createTipDialog(sourceActivity, + "书源导出成功,导出位置:" + APPCONST.FILE_DIR + "BookSources.json"); + } else { + ToastUtils.showError("书源导出失败"); + } + } + }); + } + + @Override + public void onDenied(List permissions, boolean never) { + ToastUtils.showWarring("没有储存权限!"); + } + }); } private void shareSources(List bookSources) { @@ -406,9 +420,9 @@ public class DIYSourceFragment extends BaseFragment { } Single.create((SingleOnSubscribe) emitter -> { File share = FileUtils.getFile(APPCONST.SHARE_FILE_DIR + "ShareBookSources.json"); - if (FileUtils.writeText(GsonExtensionsKt.getGSON().toJson(bookSources), share)){ + if (FileUtils.writeText(GsonExtensionsKt.getGSON().toJson(bookSources), share)) { emitter.onSuccess(share); - }else { + } else { emitter.onError(new Exception("书源文件写出失败")); } }).compose(RxUtils::toSimpleSingle).subscribe(new MySingleObserver() { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/fragment/MineFragment.java b/app/src/main/java/xyz/fycz/myreader/ui/fragment/MineFragment.java index e1176a0..582a6c2 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/fragment/MineFragment.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/fragment/MineFragment.java @@ -390,7 +390,7 @@ public class MineFragment extends BaseFragment { @Override public void backupError(@io.reactivex.annotations.NonNull String msg) { - DialogCreator.createTipDialog(getContext(), "未给予储存权限,备份失败!"); + DialogCreator.createTipDialog(getContext(), "未给予储存权限,备份失败!\n" + msg); } }, false); }, (dialogInterface, i) -> dialogInterface.dismiss()); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeLayoutMenu.java b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeLayoutMenu.java index f7aa30e..5b3402f 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeLayoutMenu.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/popmenu/CustomizeLayoutMenu.java @@ -22,6 +22,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; +import com.hjq.permissions.OnPermissionCallback; +import com.hjq.permissions.XXPermissions; import com.jaredrummler.android.colorpicker.ColorPickerDialog; import com.kongzue.dialogx.dialogs.BottomMenu; @@ -95,7 +97,7 @@ public class CustomizeLayoutMenu extends FrameLayout { public void upColor() { int curStyleIndex = setting.getCurReadStyleIndex(); - if (!setting.isDayStyle()){ + if (!setting.isDayStyle()) { ToastUtils.showInfo("当前正在编辑夜间模式"); curStyleIndex = 6; } @@ -237,10 +239,22 @@ public class CustomizeLayoutMenu extends FrameLayout { }).show();*/ BottomMenu.show("选择需要导出的布局", items) .setOnMenuItemClickListener((dialog, text, which) -> { - if (setting.exportLayout(which)){ - DialogCreator.createTipDialog(context, - "布局配置导出成功,导出位置:" + APPCONST.FILE_DIR + "readConfig.zip"); - } + XXPermissions.with(context) + .permission(APPCONST.STORAGE_PERMISSIONS) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + if (setting.exportLayout(which)) { + DialogCreator.createTipDialog(context, + "布局配置导出成功,导出位置:" + APPCONST.FILE_DIR + "readConfig.zip"); + } + } + + @Override + public void onDenied(List permissions, boolean never) { + ToastUtils.showWarring("没有储存权限!"); + } + }); return false; }); } @@ -274,8 +288,8 @@ public class CustomizeLayoutMenu extends FrameLayout { BottomMenu.show("选择要覆盖的布局", items) .setOnMenuItemClickListener((dialog, text, which) -> { setting.importLayout(which, readStyle); - if (!readStyle.bgIsColor() && !readStyle.bgIsAssert()){ - FileUtils.copy(APPCONST.TEM_FILE_DIR + "bg.fyl",APPCONST.BG_FILE_DIR + "bg" + which + ".fyl"); + if (!readStyle.bgIsColor() && !readStyle.bgIsAssert()) { + FileUtils.copy(APPCONST.TEM_FILE_DIR + "bg.fyl", APPCONST.BG_FILE_DIR + "bg" + which + ".fyl"); readStyle.setBgPath(APPCONST.BG_FILE_DIR + "bg" + which + ".fyl"); } FileUtils.deleteFile(APPCONST.TEM_FILE_DIR + "readConfig.fyl"); @@ -292,6 +306,7 @@ public class CustomizeLayoutMenu extends FrameLayout { public interface Callback { void upBg(); + void upStyle(); } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/presenter/BookcasePresenter.java b/app/src/main/java/xyz/fycz/myreader/ui/presenter/BookcasePresenter.java index 2102244..66ff6ce 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/presenter/BookcasePresenter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/presenter/BookcasePresenter.java @@ -21,6 +21,9 @@ import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; +import com.hjq.permissions.OnPermissionCallback; +import com.hjq.permissions.Permission; +import com.hjq.permissions.XXPermissions; import com.kongzue.dialogx.dialogs.BottomMenu; import org.jetbrains.annotations.NotNull; @@ -85,7 +88,6 @@ public class BookcasePresenter implements BasePresenter { private final ChapterService mChapterService; private final BookGroupService mBookGroupService; private final MainActivity mMainActivity; - private PermissionsChecker mPermissionsChecker; private boolean isBookcaseStyleChange; private Setting mSetting; private final List errorLoadingBooks = new ArrayList<>(); @@ -356,7 +358,7 @@ public class BookcasePresenter implements BasePresenter { } - public void refreshBook(Book book, boolean isChangeSource){ + public void refreshBook(Book book, boolean isChangeSource) { mBookcaseAdapter.getIsLoading().put(book.getId(), true); mBookcaseAdapter.refreshBook(book.getChapterUrl()); final ArrayList mChapters = (ArrayList) mChapterService.findBookAllChapterByBookId(book.getId()); @@ -367,7 +369,7 @@ public class BookcasePresenter implements BasePresenter { book.setNewestChapterTitle(chapters.get(chapters.size() - 1).getTitle()); mChapterService.updateAllOldChapterData(mChapters, chapters, book.getId()); mBookService.updateEntity(book); - if (isChangeSource){ + if (isChangeSource) { if (mBookService.matchHistoryChapterPos(book, chapters)) { ToastUtils.showSuccess("历史阅读章节匹配成功!"); } else { @@ -487,19 +489,7 @@ public class BookcasePresenter implements BasePresenter { showGroupManDia(); return true; case R.id.action_addLocalBook: - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { - if (mPermissionsChecker == null) { - mPermissionsChecker = new PermissionsChecker(mMainActivity); - } - //获取读取和写入SD卡的权限 - if (mPermissionsChecker.lacksPermissions(PERMISSIONS)) { - //请求权限 - ActivityCompat.requestPermissions(mMainActivity, PERMISSIONS, APPCONST.PERMISSIONS_REQUEST_STORAGE); - return true; - } - } - Intent fileSystemIntent = new Intent(mMainActivity, FileSystemActivity.class); - mMainActivity.startActivity(fileSystemIntent); + addLocalBook(); break; case R.id.action_download_all: if (!SharedPreUtils.getInstance().getBoolean(mMainActivity.getString(R.string.isReadDownloadAllTip), false)) { @@ -518,6 +508,23 @@ public class BookcasePresenter implements BasePresenter { return false; } + private void addLocalBook() { + XXPermissions.with(mMainActivity) + .permission(APPCONST.STORAGE_PERMISSIONS) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + Intent fileSystemIntent = new Intent(mMainActivity, FileSystemActivity.class); + mMainActivity.startActivity(fileSystemIntent); + } + + @Override + public void onDenied(List permissions, boolean never) { + ToastUtils.showWarring("储存权限被拒绝,无法添加本地书籍!"); + } + }); + } + /** * 显示书籍分组菜单 */ @@ -554,7 +561,7 @@ public class BookcasePresenter implements BasePresenter { if (canEditBookcase()) { mMainActivity.getViewPagerMain().setEnableScroll(false); mBookcaseFragment.getSrlContent().setEnableRefresh(false); - if (mSetting.getSortStyle() == 0){ + if (mSetting.getSortStyle() == 0) { ToastUtils.showInfo("长按可移动书籍哦!"); } itemTouchCallback.setLongPressDragEnable(mSetting.getSortStyle() == 0); @@ -690,7 +697,7 @@ public class BookcasePresenter implements BasePresenter { } //加入分组 - public void addGroup(Book book){ + public void addGroup(Book book) { mBookGroupDia.addGroup(book, new BookGroupDialog.OnGroup() { @Override public void change() { @@ -884,7 +891,6 @@ public class BookcasePresenter implements BasePresenter { } - /** * 发送通知 */ diff --git a/app/src/main/java/xyz/fycz/myreader/util/PermissionsChecker.java b/app/src/main/java/xyz/fycz/myreader/util/PermissionsChecker.java deleted file mode 100644 index e783f0c..0000000 --- a/app/src/main/java/xyz/fycz/myreader/util/PermissionsChecker.java +++ /dev/null @@ -1,31 +0,0 @@ -package xyz.fycz.myreader.util; - -import android.content.Context; -import android.content.pm.PackageManager; -import androidx.core.content.ContextCompat; - - - -public class PermissionsChecker { - private final Context mContext; - - public PermissionsChecker(Context context) { - mContext = context.getApplicationContext(); - } - - // 判断权限集合 - public boolean lacksPermissions(String... permissions) { - for (String permission : permissions) { - if (lacksPermission(permission)) { - return true; - } - } - return false; - } - - // 判断是否缺少权限 - private boolean lacksPermission(String permission) { - return ContextCompat.checkSelfPermission(mContext, permission) == - PackageManager.PERMISSION_DENIED; - } -} \ No newline at end of file diff --git a/app/src/main/java/xyz/fycz/myreader/util/help/JsExtensions.java b/app/src/main/java/xyz/fycz/myreader/util/help/JsExtensions.java index f7dea3e..e1c2fdb 100644 --- a/app/src/main/java/xyz/fycz/myreader/util/help/JsExtensions.java +++ b/app/src/main/java/xyz/fycz/myreader/util/help/JsExtensions.java @@ -33,6 +33,7 @@ import xyz.fycz.myreader.util.utils.OkHttpUtils; import xyz.fycz.myreader.util.utils.StringUtils; @Keep + @SuppressWarnings({"unused"}) public interface JsExtensions { String TAG = JsExtensions.class.getSimpleName(); diff --git a/app/src/main/java/xyz/fycz/myreader/util/utils/FileUtils.java b/app/src/main/java/xyz/fycz/myreader/util/utils/FileUtils.java index 393ea7e..9eab6e8 100644 --- a/app/src/main/java/xyz/fycz/myreader/util/utils/FileUtils.java +++ b/app/src/main/java/xyz/fycz/myreader/util/utils/FileUtils.java @@ -72,6 +72,10 @@ public class FileUtils { return file; } + public static String getDataDir(){ + return getFileDir().getParent(); + } + //获取Cache文件夹 public static String getCachePath(){ if (isSdCardExist()){ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3d8f0cb..67998ee 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -492,7 +492,10 @@ 段友影视,超清无水印广告视频站 总阅读时间:%s 阅读记录 - \n感谢您使用风月读书APP!\n我们非常重视您的个人信息和隐私保护。为了更好地保障您的个人权益,在您使用我们的产品前,请务必审慎阅读《隐私政策》内的所有条款,当您点击“同意并继续”即表示您己阅读完毕并同意以上协议的全部内容,开始使用我们的产品和服务。 + \n感谢您使用风月读书APP! + \n\n1.我们非常重视您的个人信息和隐私保护。为了更好地保障您的个人权益,在您使用我们的产品前,请务必审慎阅读《隐私政策》内的所有条款. + \n\n2.我们可能会申请存储权限,以实现下载、分享、备份、应用升级、导入本地书籍等相关功能. + \n\n如果您己阅读完毕并同意以上协议的全部内容,请点击下方“同意并继续”按钮以开始使用我们的产品和服务. 关闭 官网 隐私政策 diff --git a/app/version_code.properties b/app/version_code.properties index 3866553..7cb57ca 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Fri Jun 04 20:20:53 CST 2021 -VERSION_CODE=208 +#Sun Jun 06 10:44:17 CST 2021 +VERSION_CODE=210