diff --git a/app/src/main/assets/updatelog.fy b/app/src/main/assets/updatelog.fy index 3bd54b9..e65dda4 100644 --- a/app/src/main/assets/updatelog.fy +++ b/app/src/main/assets/updatelog.fy @@ -1,4 +1,9 @@ 2021.06.06 +风月读书v2.1.1 +更新内容: +1、修复阅读界面日夜间切换后底部对话框不显示的bug +2、修复存储bug + 风月读书v2.1.0 更新内容: 1、储存优化 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 e795aa2..0353c42 100644 --- a/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java +++ b/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java @@ -28,31 +28,21 @@ public class APPCONST { 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/"; + public static final String FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/"; + public static final String SHARE_FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/share/"; + public static String LOG_DIR = FileUtils.getCachePath() + "/log/"; + public static final String BG_FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/bg/"; + public static String TEM_FILE_DIR = FileUtils.getCachePath() + "/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/"; //BookCachePath (因为getCachePath引用了Context,所以必须是静态变量,不能够是静态常量) public static String BOOK_CACHE_PATH = FileUtils.getCachePath() + File.separator - + "book_cache" + File.separator; + + "book_cache"+ File.separator ; + public static String HTML_CACHE_PATH = FileUtils.getCachePath() + File.separator + + "html_cache"+ File.separator ; public static long exitTime; public static final int exitConfirmTime = 2000; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java index fddd6e6..e91a6f6 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java @@ -1475,7 +1475,10 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe SysManager.saveSetting(mSetting); App.getApplication().setNightTheme(isNight); mHandler.postDelayed(() -> { - BaseDialog.initActivityContext(ActivityManage.getByClass(this.getClass())); + AppCompatActivity activity = ActivityManage.getByClass(this.getClass()); + if (activity != null) { + BaseDialog.initActivityContext(activity); + } }, 1000); //mPageLoader.setPageStyle(!isCurDayStyle); } 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 9e52ea6..ca36276 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 @@ -47,6 +47,7 @@ import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.ClipBoardUtil; import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.GsonExtensionsKt; +import xyz.fycz.myreader.util.utils.StoragePermissionUtils; import xyz.fycz.myreader.widget.DividerItemDecoration; import xyz.fycz.myreader.widget.swipemenu.SwipeMenuLayout; @@ -246,23 +247,13 @@ public class ReplaceRuleActivity extends BaseActivity { ToastUtils.showWarring("当前没有任何规则,无法导出!"); return true; } - 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("没有储存权限!"); - } - }); + StoragePermissionUtils.request(this, (permissions, all) -> { + if (FileUtils.writeText(GsonExtensionsKt.getGSON().toJson(mReplaceRules), + FileUtils.getFile(APPCONST.FILE_DIR + "ReplaceRule.json"))) { + DialogCreator.createTipDialog(ReplaceRuleActivity.this, + "内容替换规则导出成功,导出位置:" + APPCONST.FILE_DIR + "ReplaceRule.json"); + } + }); } 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/adapter/BookcaseAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseAdapter.java index 0594d31..159bba6 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 @@ -51,6 +51,7 @@ import xyz.fycz.myreader.ui.dialog.SourceExchangeDialog; import xyz.fycz.myreader.util.help.StringHelper; import xyz.fycz.myreader.util.utils.RxUtils; import xyz.fycz.myreader.util.utils.ShareBookUtil; +import xyz.fycz.myreader.util.utils.StoragePermissionUtils; import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil; import xyz.fycz.myreader.webapi.crawler.base.ReadCrawler; import xyz.fycz.myreader.widget.CoverImageView; @@ -452,23 +453,13 @@ public abstract class BookcaseAdapter extends RecyclerView.Adapter { dialog.dismiss(); Single.create((SingleOnSubscribe) emitter -> { - 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("没有储存权限!"); - } - }); + StoragePermissionUtils.request(mContext, (permissions, all) -> { + try { + emitter.onSuccess(unionChapterCathe(mBook)); + } catch (IOException e) { + emitter.onError(e); + } + }); }).compose(RxUtils::toSimpleSingle).subscribe(new MySingleObserver() { @Override public void onSuccess(@NotNull Boolean aBoolean) { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/FontsAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/FontsAdapter.java index a84775f..4b82ae2 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/FontsAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/FontsAdapter.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.application.SysManager; +import xyz.fycz.myreader.util.utils.StoragePermissionUtils; import xyz.fycz.myreader.webapi.LanZousApi; import xyz.fycz.myreader.webapi.ResultCallback; import xyz.fycz.myreader.common.APPCONST; @@ -165,11 +166,13 @@ public class FontsAdapter extends ArrayAdapter { } }).create(); dialog.show();*/ - ToastUtils.showInfo("请选择一个ttf格式的字体文件"); - Intent intent = new Intent(Intent.ACTION_GET_CONTENT); - intent.setType("*/*"); - intent.addCategory(Intent.CATEGORY_OPENABLE); - mFontsActivity.startActivityForResult(intent, APPCONST.SELECT_FILE_CODE); + StoragePermissionUtils.request(mFontsActivity, (permissions, all) -> { + ToastUtils.showInfo("请选择一个ttf格式的字体文件"); + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("*/*"); + intent.addCategory(Intent.CATEGORY_OPENABLE); + mFontsActivity.startActivityForResult(intent, APPCONST.SELECT_FILE_CODE); + }); }); return; } @@ -178,8 +181,10 @@ public class FontsAdapter extends ArrayAdapter { viewHolder.btnFontUse.setButtonColor(mFontsActivity.getResources().getColor(R.color.sys_blue_littler)); viewHolder.btnFontUse.setText(getContext().getString(R.string.font_download)); viewHolder.btnFontUse.setOnClickListener(v -> { - viewHolder.btnFontUse.setEnabled(false); - addDownloadFont(font, viewHolder); + StoragePermissionUtils.request(mFontsActivity, (permissions, all) -> { + viewHolder.btnFontUse.setEnabled(false); + addDownloadFont(font, viewHolder); + }); }); } else if (setting.getFont() == font) { viewHolder.btnFontUse.setText(getContext().getString(R.string.font_using)); @@ -206,6 +211,7 @@ public class FontsAdapter extends ArrayAdapter { mHandler.sendMessage(mHandler.obtainMessage(3)); return; } + final String[] url = {URLCONST.FONT_DOWNLOAD_URL + font.toString() + ".ttf"}; viewHolder.btnFontUse.setText("获取连接..."); LanZousApi.getUrl(font.downloadPath, new ResultCallback() { 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 e6fadc2..a3b2916 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 @@ -54,6 +54,7 @@ import xyz.fycz.myreader.util.utils.ClipBoardUtil; import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import xyz.fycz.myreader.util.utils.RxUtils; +import xyz.fycz.myreader.util.utils.StoragePermissionUtils; import xyz.fycz.myreader.widget.DividerItemDecoration; import xyz.fycz.myreader.widget.swipemenu.SwipeMenuLayout; @@ -385,32 +386,22 @@ public class DIYSourceFragment extends BaseFragment { ToastUtils.showWarring("当前没有选择任何书源,无法导出!"); return; } - 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("没有储存权限!"); + StoragePermissionUtils.request(this, (permissions, 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("书源导出失败"); } - }); + } + }); + }); } private void shareSources(List bookSources) { @@ -418,24 +409,27 @@ public class DIYSourceFragment extends BaseFragment { ToastUtils.showWarring("当前没有选择任何书源,无法分享!"); return; } - Single.create((SingleOnSubscribe) emitter -> { - File share = FileUtils.getFile(APPCONST.SHARE_FILE_DIR + "ShareBookSources.json"); - if (FileUtils.writeText(GsonExtensionsKt.getGSON().toJson(bookSources), share)) { - emitter.onSuccess(share); - } else { - emitter.onError(new Exception("书源文件写出失败")); - } - }).compose(RxUtils::toSimpleSingle).subscribe(new MySingleObserver() { - @Override - public void onSuccess(@NonNull File share) { - ShareUtils.share(sourceActivity, share, "书源分享", "text/plain"); - } + StoragePermissionUtils.request(this, (permissions, all) -> { + Single.create((SingleOnSubscribe) emitter -> { + File share = FileUtils.getFile(APPCONST.SHARE_FILE_DIR + "ShareBookSources.json"); + if (FileUtils.writeText(GsonExtensionsKt.getGSON().toJson(bookSources), share)) { + emitter.onSuccess(share); + } else { + emitter.onError(new Exception("书源文件写出失败")); + } + }).compose(RxUtils::toSimpleSingle).subscribe(new MySingleObserver() { + @Override + public void onSuccess(@NonNull File share) { + ShareUtils.share(sourceActivity, share, "书源分享", "text/plain"); + } - @Override - public void onError(Throwable e) { - ToastUtils.showError("书源分享失败\n" + e.getLocalizedMessage()); - } + @Override + public void onError(Throwable e) { + ToastUtils.showError("书源分享失败\n" + e.getLocalizedMessage()); + } + }); }); + } private void reverseSources(List mBookSources) { 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 582a6c2..db21487 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 @@ -58,6 +58,7 @@ import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import xyz.fycz.myreader.util.utils.ImageLoader; import xyz.fycz.myreader.util.utils.NetworkUtils; +import xyz.fycz.myreader.util.utils.StoragePermissionUtils; import xyz.fycz.myreader.webapi.ResultCallback; import static android.app.Activity.RESULT_OK; @@ -374,35 +375,38 @@ public class MineFragment extends BaseFragment { ToastUtils.showWarring("当前书架无任何书籍,无法备份!"); return; } - DialogCreator.createCommonDialog(getContext(), "确认备份吗?", "新备份会替换原有备份!", true, - (dialogInterface, i) -> { - dialogInterface.dismiss(); + StoragePermissionUtils.request(this, (permissions, all) -> { + DialogCreator.createCommonDialog(getContext(), "确认备份吗?", "新备份会替换原有备份!", true, + (dialogInterface, i) -> { + dialogInterface.dismiss(); /*if (mBackupAndRestore.backup("localBackup")) { DialogCreator.createTipDialog(getContext(), "备份成功,备份文件路径:" + APPCONST.BACKUP_FILE_DIR); } else { DialogCreator.createTipDialog(getContext(), "未给予储存权限,备份失败!"); }*/ - Backup.INSTANCE.backup(App.getmContext(), APPCONST.BACKUP_FILE_DIR, new Backup.CallBack() { - @Override - public void backupSuccess() { - DialogCreator.createTipDialog(getContext(), "备份成功,备份文件路径:" + APPCONST.BACKUP_FILE_DIR); - } + Backup.INSTANCE.backup(App.getmContext(), APPCONST.BACKUP_FILE_DIR, new Backup.CallBack() { + @Override + public void backupSuccess() { + DialogCreator.createTipDialog(getContext(), "备份成功,备份文件路径:" + APPCONST.BACKUP_FILE_DIR); + } - @Override - public void backupError(@io.reactivex.annotations.NonNull String msg) { - DialogCreator.createTipDialog(getContext(), "未给予储存权限,备份失败!\n" + msg); - } - }, false); - }, (dialogInterface, i) -> dialogInterface.dismiss()); + @Override + public void backupError(@io.reactivex.annotations.NonNull String msg) { + DialogCreator.createTipDialog(getContext(), "未给予储存权限,备份失败!\n" + msg); + } + }, false); + }, (dialogInterface, i) -> dialogInterface.dismiss()); + }); } /** * 恢复 */ private void restore() { - DialogCreator.createCommonDialog(getContext(), "确认恢复吗?", "恢复书架会覆盖原有书架!", true, - (dialogInterface, i) -> { - dialogInterface.dismiss(); + StoragePermissionUtils.request(this, (permissions, all) -> { + DialogCreator.createCommonDialog(getContext(), "确认恢复吗?", "恢复书架会覆盖原有书架!", true, + (dialogInterface, i) -> { + dialogInterface.dismiss(); /*if (mBackupAndRestore.restore("localBackup")) { mHandler.sendMessage(mHandler.obtainMessage(7)); // DialogCreator.createTipDialog(mMainActivity, @@ -412,26 +416,27 @@ public class MineFragment extends BaseFragment { } else { DialogCreator.createTipDialog(getContext(), "未找到备份文件或未给予储存权限,恢复失败!"); }*/ - Restore.INSTANCE.restore(APPCONST.BACKUP_FILE_DIR, new Restore.CallBack() { - @Override - public void restoreSuccess() { - mHandler.sendMessage(mHandler.obtainMessage(7)); + Restore.INSTANCE.restore(APPCONST.BACKUP_FILE_DIR, new Restore.CallBack() { + @Override + public void restoreSuccess() { + mHandler.sendMessage(mHandler.obtainMessage(7)); // DialogCreator.createTipDialog(mMainActivity, // "恢复成功!\n注意:本功能属于实验功能,书架恢复后,书籍初次加载时可能加载失败,返回重新加载即可!"); - SysManager.regetmSetting(); - ToastUtils.showSuccess("书架恢复成功!"); - if (getActivity() != null) { - getActivity().finish(); + SysManager.regetmSetting(); + ToastUtils.showSuccess("书架恢复成功!"); + if (getActivity() != null) { + getActivity().finish(); + } + startActivity(new Intent(getContext(), MainActivity.class)); } - startActivity(new Intent(getContext(), MainActivity.class)); - } - @Override - public void restoreError(@io.reactivex.annotations.NonNull String msg) { - DialogCreator.createTipDialog(getContext(), "未找到备份文件或未给予储存权限,恢复失败!"); - } - }); - }, (dialogInterface, i) -> dialogInterface.dismiss()); + @Override + public void restoreError(@io.reactivex.annotations.NonNull String msg) { + DialogCreator.createTipDialog(getContext(), "未找到备份文件或未给予储存权限,恢复失败!"); + } + }); + }, (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 5b3402f..22f4219 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 @@ -45,6 +45,7 @@ import xyz.fycz.myreader.util.ZipUtils; import xyz.fycz.myreader.util.utils.FileUtils; import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import xyz.fycz.myreader.util.utils.MeUtils; +import xyz.fycz.myreader.util.utils.StoragePermissionUtils; public class CustomizeLayoutMenu extends FrameLayout { @@ -217,11 +218,13 @@ public class CustomizeLayoutMenu extends FrameLayout { } private void importLayout() { - ToastUtils.showInfo("请选择布局配置压缩文件"); - Intent intent = new Intent(Intent.ACTION_GET_CONTENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("application/zip"); - context.startActivityForResult(intent, APPCONST.REQUEST_IMPORT_LAYOUT); + StoragePermissionUtils.request(context, (permissions, all) -> { + ToastUtils.showInfo("请选择布局配置压缩文件"); + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("application/zip"); + context.startActivityForResult(intent, APPCONST.REQUEST_IMPORT_LAYOUT); + }); } private void exportLayout() { @@ -237,26 +240,17 @@ public class CustomizeLayoutMenu extends FrameLayout { "布局配置导出成功,导出位置:" + APPCONST.FILE_DIR + "readConfig.zip"); } }).show();*/ - BottomMenu.show("选择需要导出的布局", items) - .setOnMenuItemClickListener((dialog, text, which) -> { - 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; - }); + StoragePermissionUtils.request(context, (permissions, all) -> { + BottomMenu.show("选择需要导出的布局", items) + .setOnMenuItemClickListener((dialog, text, which) -> { + if (setting.exportLayout(which)) { + DialogCreator.createTipDialog(context, + "布局配置导出成功,导出位置:" + APPCONST.FILE_DIR + "readConfig.zip"); + } + return false; + }); + }); + } public void zip2Layout(String zipPath) { 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 e1c2fdb..f7dea3e 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,7 +33,6 @@ 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/ShareBookUtil.java b/app/src/main/java/xyz/fycz/myreader/util/utils/ShareBookUtil.java index 8c0f06a..1d29e35 100644 --- a/app/src/main/java/xyz/fycz/myreader/util/utils/ShareBookUtil.java +++ b/app/src/main/java/xyz/fycz/myreader/util/utils/ShareBookUtil.java @@ -39,10 +39,16 @@ import xyz.fycz.myreader.util.ToastUtils; * @date 2021/6/3 21:46 */ public class ShareBookUtil { + public static void shareBook(Context context, Book mBook, ImageView cover) { + StoragePermissionUtils.request(context, (permissions, all) -> { + shareBook2(context, mBook, cover); + }); + } + /** * 分享书籍 */ - public static void shareBook(Context context, Book mBook, ImageView cover) { + public static void shareBook2(Context context, Book mBook, ImageView cover) { if ("本地书籍".equals(mBook.getType())) { File file = new File(mBook.getChapterUrl()); if (!file.exists()) { diff --git a/app/src/main/java/xyz/fycz/myreader/util/utils/StoragePermissionUtils.java b/app/src/main/java/xyz/fycz/myreader/util/utils/StoragePermissionUtils.java new file mode 100644 index 0000000..5629678 --- /dev/null +++ b/app/src/main/java/xyz/fycz/myreader/util/utils/StoragePermissionUtils.java @@ -0,0 +1,54 @@ +package xyz.fycz.myreader.util.utils; + +import android.content.Context; + +import androidx.fragment.app.Fragment; + +import com.hjq.permissions.OnPermissionCallback; +import com.hjq.permissions.XXPermissions; + +import java.util.List; + +import xyz.fycz.myreader.common.APPCONST; +import xyz.fycz.myreader.ui.dialog.DialogCreator; +import xyz.fycz.myreader.util.ToastUtils; + +/** + * @author fengyue + * @date 2021/6/6 18:37 + */ +public class StoragePermissionUtils { + public static void request(Context context, OnPermissionCallback callback){ + XXPermissions.with(context) + .permission(APPCONST.STORAGE_PERMISSIONS) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + callback.onGranted(permissions, all); + } + + @Override + public void onDenied(List permissions, boolean never) { + ToastUtils.showWarring("没有储存权限!"); + callback.onDenied(permissions, never); + } + }); + } + + public static void request(Fragment fragment, OnPermissionCallback callback){ + XXPermissions.with(fragment) + .permission(APPCONST.STORAGE_PERMISSIONS) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + callback.onGranted(permissions, all); + } + + @Override + public void onDenied(List permissions, boolean never) { + ToastUtils.showWarring("没有储存权限!"); + callback.onDenied(permissions, never); + } + }); + } +}