From 0cf2304b222d5278ded012c6a3dc05f0d72de332 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Wed, 2 Jun 2021 18:49:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updatelog.fy | 7 ++ .../xyz/fycz/myreader/model/storage/Backup.kt | 8 ++ .../fycz/myreader/model/storage/Restore.kt | 9 ++ .../myreader/ui/activity/ReadActivity.java | 32 +++++-- .../main/res/layout/gridview_book_item.xml | 84 +++++++++---------- app/version_code.properties | 4 +- 6 files changed, 90 insertions(+), 54 deletions(-) diff --git a/app/src/main/assets/updatelog.fy b/app/src/main/assets/updatelog.fy index 1249864..f69e8a3 100644 --- a/app/src/main/assets/updatelog.fy +++ b/app/src/main/assets/updatelog.fy @@ -1,3 +1,10 @@ +2021.06.02 +风月读书v2.0.6 +更新内容: +1、阅读记录支持备份/恢复 +2、修复阅读时切换后台记录异常的问题 +3、私密书籍不保存阅读记录 + 2021.06.01 风月读书v2.0.5 更新内容: diff --git a/app/src/main/java/xyz/fycz/myreader/model/storage/Backup.kt b/app/src/main/java/xyz/fycz/myreader/model/storage/Backup.kt index f6094df..c477d07 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/storage/Backup.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/storage/Backup.kt @@ -41,6 +41,7 @@ object Backup { "readStyles.json", "replaceRule.json", "bookSource.json", + "readRecord.json", "config.xml" ) } @@ -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 diff --git a/app/src/main/java/xyz/fycz/myreader/model/storage/Restore.kt b/app/src/main/java/xyz/fycz/myreader/model/storage/Restore.kt index 01e9f27..0c05456 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/storage/Restore.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/storage/Restore.kt @@ -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(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() 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 8b95fb9..3e3693f 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 @@ -185,6 +185,8 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe private long lastRecordTime;//上次记录时间 + private boolean isPrivate;//是否私密书籍 + // 接收电池信息和时间更新的广播 private BroadcastReceiver mReceiver = new BroadcastReceiver() { @@ -280,6 +282,24 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe 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); @@ -337,7 +357,8 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe if (aBooks != null) { mSourceDialog.setABooks(aBooks); } - lastRecordTime = System.currentTimeMillis(); + String privateGroupId = SharedPreUtils.getInstance().getString("privateGroupId"); + isPrivate = privateGroupId.equals(mBook.getGroupId()); } @Override @@ -588,9 +609,8 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe 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()); } @@ -599,11 +619,6 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe getData(); } - @Override - protected void onResume() { - super.onResume(); - hideSystemBar(); - } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { @@ -2098,6 +2113,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe * 记录阅读时间 */ private void recordReadTime() { + if (isPrivate) return; Single.create(emitter -> { if (mBook == null) return; if (record == null) { diff --git a/app/src/main/res/layout/gridview_book_item.xml b/app/src/main/res/layout/gridview_book_item.xml index 9c1f1ac..9f6138e 100644 --- a/app/src/main/res/layout/gridview_book_item.xml +++ b/app/src/main/res/layout/gridview_book_item.xml @@ -1,71 +1,67 @@ + android:orientation="vertical" + android:paddingHorizontal="25dp" + android:paddingVertical="10dp"> + android:orientation="vertical"> + 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" /> + android:maxLines="2" + android:text="@string/app_name" + android:textColor="@color/textPrimary" /> + 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" /> + 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" /> + 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" /> \ No newline at end of file diff --git a/app/version_code.properties b/app/version_code.properties index 5170aff..ae81465 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -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