Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
存储优化
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuecanzhu committed Jun 6, 2021
1 parent b76df12 commit df9054d
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 231 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ dependencies {
//noinspection GradleDependency
implementation 'com.github.gedoor:rhino-android:1.3'

//XXPermissions
implementation 'com.github.getActivity:XXPermissions:11.2'

}

greendao {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/assets/updatelog.fy
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2021.06.06
风月读书v2.1.0
更新内容:
1、储存优化

2021.06.05
风月读书v2.0.9
更新内容:
Expand Down
52 changes: 37 additions & 15 deletions app/src/main/java/xyz/fycz/myreader/common/APPCONST.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/xyz/fycz/myreader/enums/Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
18 changes: 0 additions & 18 deletions app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,24 +386,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

@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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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;
Expand All @@ -11,9 +10,13 @@
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;
Expand All @@ -22,7 +25,6 @@
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;
Expand All @@ -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;
Expand Down Expand Up @@ -104,16 +104,16 @@ protected void onDestroy() {
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);
Expand All @@ -124,9 +124,9 @@ public void onScanQRCodeSuccess(String result) {

@Override
public void onCameraAmbientBrightnessChanged(boolean isDark) {
if (isDark){
if (isDark) {
binding.llFlashlight.setVisibility(View.VISIBLE);
}else {
} else {
if (!flashlightIsOpen) {
binding.llFlashlight.setVisibility(View.GONE);
}
Expand All @@ -144,32 +144,23 @@ private void startScan() {
}

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<String> 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<String> permissions, boolean never) {
//申请权限失败
finish();
ToastUtils.showWarring("请给予相机权限,否则无法进行扫码!");
}
});
}

// 添加菜单
Expand Down Expand Up @@ -206,7 +197,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

private void scanFromPath(String path){
private void scanFromPath(String path) {
// 本来就用到 QRCodeView 时可直接调 QRCodeView 的方法,走通用的回调
Single.create((SingleOnSubscribe<Bitmap>) emitter -> {
Bitmap bitmap = BitmapFactory.decodeFile(path);
Expand All @@ -228,7 +219,7 @@ public void onSuccess(Bitmap bitmap) {

private void chooseFromGallery() {
try {
if (needScale){
if (needScale) {
ToastUtils.showInfo("选择图片仅支持扫描书籍分享图片");
}
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
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;
Expand Down Expand Up @@ -244,11 +246,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
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<String> 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<String> permissions, boolean never) {
ToastUtils.showWarring("没有储存权限!");
}
});
} else if (itemId == R.id.action_reverse) {
for (ReplaceRuleBean ruleBean : mReplaceRules) {
ruleBean.setEnable(!ruleBean.getEnable());
Expand Down
Loading

0 comments on commit df9054d

Please sign in to comment.