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

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuecanzhu committed Jun 2, 2021
1 parent e4da857 commit 0cf2304
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 54 deletions.
7 changes: 7 additions & 0 deletions app/src/main/assets/updatelog.fy
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2021.06.02
风月读书v2.0.6
更新内容:
1、阅读记录支持备份/恢复
2、修复阅读时切换后台记录异常的问题
3、私密书籍不保存阅读记录

2021.06.01
风月读书v2.0.5
更新内容:
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/xyz/fycz/myreader/model/storage/Backup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ object Backup {
"readStyles.json",
"replaceRule.json",
"bookSource.json",
"readRecord.json",
"config.xml"
)
}
Expand Down Expand Up @@ -102,6 +103,13 @@ object Backup {
.writeText(json)
}
}
DbManager.getInstance().session.readRecordDao.queryBuilder().list().let {
if (it.isNotEmpty()) {
val json = GSON.toJson(it)
FileUtils.getFile(backupPath + File.separator + "readRecord.json")
.writeText(json)
}
}
try {
val setting = SysManager.getNewSetting()
val readStyles = setting.readStyles
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/xyz/fycz/myreader/model/storage/Restore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ object Restore {
} catch (e: Exception) {
e.printStackTrace()
}
try {
val file = FileUtils.getFile(path + File.separator + "readRecord.json")
val json = file.readText()
GSON.fromJsonArray<ReadRecord>(json)?.let {
DbManager.getInstance().session.readRecordDao.insertOrReplaceInTx(it)
}
} catch (e: Exception) {
e.printStackTrace()
}
try {
val settingFile = FileUtils.getFile(path + File.separator + "setting.json")
val settingJson = settingFile.readText()
Expand Down
32 changes: 24 additions & 8 deletions app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe

private long lastRecordTime;//上次记录时间

private boolean isPrivate;//是否私密书籍


// 接收电池信息和时间更新的广播
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
Expand Down Expand Up @@ -280,6 +282,24 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
protected void onStop() {
recordReadTime();
super.onStop();
}

@Override
protected void onStart() {
lastRecordTime = System.currentTimeMillis();
super.onStart();
}

@Override
protected void onResume() {
super.onResume();
hideSystemBar();
}

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
Expand Down Expand Up @@ -337,7 +357,8 @@ protected void initData(Bundle savedInstanceState) {
if (aBooks != null) {
mSourceDialog.setABooks(aBooks);
}
lastRecordTime = System.currentTimeMillis();
String privateGroupId = SharedPreUtils.getInstance().getString("privateGroupId");
isPrivate = privateGroupId.equals(mBook.getGroupId());
}

@Override
Expand Down Expand Up @@ -588,9 +609,8 @@ protected void processLogic() {
intentFilter.addAction(Intent.ACTION_TIME_TICK);
registerReceiver(mReceiver, intentFilter);
//当书籍Collected且书籍id不为空的时候保存上次阅读信息
String privateGroupId = SharedPreUtils.getInstance().getString("privateGroupId");
if (isCollected && !StringHelper.isEmpty(mBook.getId())
&& !privateGroupId.equals(mBook.getGroupId())) {
&& !isPrivate) {
//保存上次阅读信息
SharedPreUtils.getInstance().putString(getString(R.string.lastRead), mBook.getId());
}
Expand All @@ -599,11 +619,6 @@ protected void processLogic() {
getData();
}

@Override
protected void onResume() {
super.onResume();
hideSystemBar();
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Expand Down Expand Up @@ -2098,6 +2113,7 @@ public void speak(Context context, String text) {
* 记录阅读时间
*/
private void recordReadTime() {
if (isPrivate) return;
Single.create(emitter -> {
if (mBook == null) return;
if (record == null) {
Expand Down
84 changes: 40 additions & 44 deletions app/src/main/res/layout/gridview_book_item.xml
Original file line number Diff line number Diff line change
@@ -1,71 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:paddingHorizontal="25dp"
android:paddingVertical="10dp">

<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp" >
android:orientation="vertical">

<xyz.fycz.myreader.widget.CoverImageView
android:id="@+id/iv_book_img"
android:layout_width="80dp"
android:layout_height="110dp"
android:layout_gravity="center"
android:scaleType="fitXY"
app:srcCompat="@mipmap/default_cover" />
android:id="@+id/iv_book_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitXY"
app:srcCompat="@mipmap/default_cover" />

<TextView
android:layout_marginTop="5dp"
android:layout_gravity="center"
android:id="@+id/tv_book_name"
android:layout_width="86dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:text="bookname"
android:gravity="center"
android:textColor="@color/textPrimary"/>
android:maxLines="2"
android:text="@string/app_name"
android:textColor="@color/textPrimary" />

</LinearLayout>


<xyz.fycz.myreader.widget.BadgeView
android:id="@+id/tv_no_read_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="15dp"
android:layout_marginEnd="25dp"
android:includeFontPadding="false" />
android:id="@+id/tv_no_read_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_margin="3dp"
android:includeFontPadding="false" />

<ProgressBar
android:id="@+id/pb_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginEnd="28dp"
android:visibility="gone"
android:layout_alignParentEnd="true"
style="?android:attr/progressBarStyleSmall"
/>
android:id="@+id/pb_loading"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_margin="3dp"
android:visibility="gone" />

<CheckBox
android:id="@+id/cb_book_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:enabled="true"
android:clickable="false"
android:focusable="true"
android:layout_margin="5dp"
android:paddingEnd="2dp"
android:theme="@style/MyCheckBox"
android:visibility="visible"/>
android:id="@+id/cb_book_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:enabled="true"
android:focusable="true"
android:theme="@style/MyCheckBox"
android:visibility="visible" />


</RelativeLayout>
4 changes: 2 additions & 2 deletions app/version_code.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Tue Jun 01 18:16:41 CST 2021
VERSION_CODE=204
#Tue Jun 01 21:40:04 CST 2021
VERSION_CODE=205

0 comments on commit 0cf2304

Please sign in to comment.