From 2aa90ca4a8f623dba63df60b0cb20bdb93847a58 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Thu, 20 Jan 2022 21:17:50 +0800 Subject: [PATCH] fix bug --- .idea/misc.xml | 1 + .../fycz/myreader/greendao/entity/Book.java | 55 ++++++++++- .../myreader/greendao/entity/Chapter.java | 10 +- .../model/third3/analyzeRule/JsExtensions.kt | 2 +- .../ui/activity/BookDetailedActivity.java | 24 +---- .../myreader/ui/activity/ReadActivity.java | 15 +-- .../myreader/ui/adapter/BookcaseAdapter.java | 23 +---- .../main/res/layout/activity_source_debug.xml | 98 ++++++++++--------- 8 files changed, 115 insertions(+), 113 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 6f853a3..d49b8d0 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -23,6 +23,7 @@ + diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/entity/Book.java b/app/src/main/java/xyz/fycz/myreader/greendao/entity/Book.java index c794003..91f81c4 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/entity/Book.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/entity/Book.java @@ -2,6 +2,7 @@ package xyz.fycz.myreader.greendao.entity; import android.text.TextUtils; +import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -16,6 +17,8 @@ import org.greenrobot.greendao.annotation.Transient; import xyz.fycz.myreader.greendao.service.BookService; import xyz.fycz.myreader.model.third3.analyzeRule.RuleDataInterface; import xyz.fycz.myreader.util.SharedPreUtils; +import xyz.fycz.myreader.util.help.StringHelper; +import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import java.io.Serializable; import java.util.HashMap; @@ -385,17 +388,21 @@ public class Book implements Serializable, RuleDataInterface { variableMap = new HashMap<>(); } variableMap.put(key, value); - variable = new Gson().toJson(variableMap); + variable = GsonExtensionsKt.getGSON().toJson(variableMap); } @NonNull public Map getVariableMap() { if (variableMap == null && !TextUtils.isEmpty(variable)) { - variableMap = new Gson().fromJson(variable, MAP_STRING); + variableMap = GsonExtensionsKt.getGSON().fromJson(variable, MAP_STRING); } return variableMap; } + public void setVariableMap(Map variableMap) { + this.variableMap = variableMap; + } + public String getVariable() { return this.variable; @@ -405,6 +412,10 @@ public class Book implements Serializable, RuleDataInterface { this.variable = variable; } + public Map getCatheMap() { + return catheMap; + } + public void putCathe(String key, String value) { if (catheMap == null) { catheMap = new HashMap<>(); @@ -419,6 +430,10 @@ public class Book implements Serializable, RuleDataInterface { return catheMap.get(key); } + public void setCatheMap(Map catheMap) { + this.catheMap = catheMap; + } + public void clearCathe(){ if (catheMap != null) { catheMap.clear(); @@ -436,6 +451,40 @@ public class Book implements Serializable, RuleDataInterface { @Nullable @Override public String getVariable(@NonNull String key) { - return variableMap.get(key); + return getVariableMap().get(key); + } + + public Book changeSource(Book newBook){ + Book bookTem = (Book) clone(); + bookTem.clearCathe(); + bookTem.setChapterUrl(newBook.getChapterUrl()); + bookTem.setInfoUrl(newBook.getInfoUrl()); + bookTem.setSource(newBook.getSource()); + if (!StringHelper.isEmpty(newBook.getImgUrl())) { + bookTem.setImgUrl(newBook.getImgUrl()); + } + if (!StringHelper.isEmpty(newBook.getType())) { + bookTem.setType(newBook.getType()); + } + if (!StringHelper.isEmpty(newBook.getDesc())) { + bookTem.setDesc(newBook.getDesc()); + } + if (!StringHelper.isEmpty(newBook.getUpdateDate())) { + bookTem.setUpdateDate(newBook.getUpdateDate()); + } + if (!StringHelper.isEmpty(newBook.getWordCount())) { + bookTem.setWordCount(newBook.getWordCount()); + } + if (!StringHelper.isEmpty(newBook.getStatus())) { + bookTem.setStatus(newBook.getStatus()); + } + if (!StringHelper.isEmpty(newBook.getVariable())) { + bookTem.setVariable(newBook.getVariable()); + bookTem.setVariableMap(newBook.getVariableMap()); + } + if (newBook.getCatheMap() != null){ + bookTem.setCatheMap(newBook.getCatheMap()); + } + return bookTem; } } diff --git a/app/src/main/java/xyz/fycz/myreader/greendao/entity/Chapter.java b/app/src/main/java/xyz/fycz/myreader/greendao/entity/Chapter.java index 427bd41..626545a 100644 --- a/app/src/main/java/xyz/fycz/myreader/greendao/entity/Chapter.java +++ b/app/src/main/java/xyz/fycz/myreader/greendao/entity/Chapter.java @@ -4,6 +4,7 @@ package xyz.fycz.myreader.greendao.entity; import static xyz.fycz.myreader.common.APPCONST.MAP_STRING; import android.text.TextUtils; +import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -18,6 +19,7 @@ import org.greenrobot.greendao.annotation.Transient; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.model.third3.analyzeRule.RuleDataInterface; import xyz.fycz.myreader.util.utils.FileUtils; +import xyz.fycz.myreader.util.utils.GsonExtensionsKt; import java.io.File; import java.util.HashMap; @@ -144,18 +146,18 @@ public class Chapter implements RuleDataInterface { this.end = end; } - public void putVariable(String key, String value) { + public void putVariable(@NonNull String key, String value) { if (variableMap == null) { variableMap = new HashMap<>(); } variableMap.put(key, value); - variable = new Gson().toJson(variableMap); + variable = GsonExtensionsKt.getGSON().toJson(variableMap); } @NonNull public Map getVariableMap() { if (variableMap == null && !TextUtils.isEmpty(variable)) { - variableMap = new Gson().fromJson(variable, MAP_STRING); + variableMap = GsonExtensionsKt.getGSON().fromJson(variable, MAP_STRING); } return variableMap; } @@ -163,7 +165,7 @@ public class Chapter implements RuleDataInterface { @Nullable @Override public String getVariable(@NonNull String key) { - return variableMap.get(key); + return getVariableMap().get(key); } public String getVariable() { diff --git a/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt b/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt index 198929c..cbd6416 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/third3/analyzeRule/JsExtensions.kt @@ -487,7 +487,7 @@ interface JsExtensions { Debug.log(it.sourceUrl, msg) } ?: Debug.log(msg)*/ if (App.isDebug()) { - Log.e(TAG, msg) + Log.d(TAG, msg) } return msg } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java index d48dd4d..6ad15c5 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java @@ -293,29 +293,7 @@ public class BookDetailedActivity extends BaseActivity { //换源对话框 mSourceDialog.setOnSourceChangeListener((bean, pos) -> { - Book bookTem = (Book) mBook.clone(); - bookTem.clearCathe(); - bookTem.setChapterUrl(bean.getChapterUrl()); - bookTem.setInfoUrl(bean.getInfoUrl()); - bookTem.setSource(bean.getSource()); - if (!StringHelper.isEmpty(bean.getImgUrl())) { - bookTem.setImgUrl(bean.getImgUrl()); - } - if (!StringHelper.isEmpty(bean.getType())) { - bookTem.setType(bean.getType()); - } - if (!StringHelper.isEmpty(bean.getDesc())) { - bookTem.setDesc(bean.getDesc()); - } - if (!StringHelper.isEmpty(bean.getUpdateDate())) { - bookTem.setUpdateDate(bean.getUpdateDate()); - } - if (!StringHelper.isEmpty(bean.getWordCount())) { - bookTem.setWordCount(bean.getWordCount()); - } - if (!StringHelper.isEmpty(bean.getStatus())) { - bookTem.setStatus(bean.getStatus()); - } + Book bookTem = mBook.changeSource(bean); if (isCollected) { mBookService.updateBook(mBook, bookTem); } 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 f2e1ad5..f6b3342 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 @@ -471,20 +471,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe initBottomMenuClick(); mSourceDialog.setOnSourceChangeListener((bean, pos) -> { - Book bookTem = (Book) mBook.clone(); - bookTem.clearCathe(); - bookTem.setInfoUrl(bean.getInfoUrl()); - bookTem.setChapterUrl(bean.getChapterUrl()); - bookTem.setSource(bean.getSource()); - if (!StringHelper.isEmpty(bean.getImgUrl())) { - bookTem.setImgUrl(bean.getImgUrl()); - } - if (!StringHelper.isEmpty(bean.getType())) { - bookTem.setType(bean.getType()); - } - if (!StringHelper.isEmpty(bean.getDesc())) { - bookTem.setDesc(bean.getDesc()); - } + Book bookTem = mBook.changeSource(bean); mBookService.updateBook(mBook, bookTem); mBook = bookTem; aBooks = mSourceDialog.getaBooks(); 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 c93f528..8cc4a5d 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 @@ -488,28 +488,7 @@ public abstract class BookcaseAdapter extends RecyclerView.Adapter { - Book bookTem = (Book) mBook.clone(); - bookTem.setChapterUrl(bean.getChapterUrl()); - bookTem.setInfoUrl(bean.getInfoUrl()); - if (!StringHelper.isEmpty(bean.getImgUrl())) { - bookTem.setImgUrl(bean.getImgUrl()); - } - if (!StringHelper.isEmpty(bean.getType())) { - bookTem.setType(bean.getType()); - } - if (!StringHelper.isEmpty(bean.getDesc())) { - bookTem.setDesc(bean.getDesc()); - } - if (!StringHelper.isEmpty(bean.getUpdateDate())) { - bookTem.setUpdateDate(bean.getUpdateDate()); - } - if (!StringHelper.isEmpty(bean.getWordCount())) { - bookTem.setWordCount(bean.getWordCount()); - } - if (!StringHelper.isEmpty(bean.getStatus())) { - bookTem.setStatus(bean.getStatus()); - } - bookTem.setSource(bean.getSource()); + Book bookTem = mBook.changeSource(bean); mBookService.updateBook(mBook, bookTem); mBook = bookTem; list.set(this.pos, mBook); diff --git a/app/src/main/res/layout/activity_source_debug.xml b/app/src/main/res/layout/activity_source_debug.xml index 420cf7a..4a88252 100644 --- a/app/src/main/res/layout/activity_source_debug.xml +++ b/app/src/main/res/layout/activity_source_debug.xml @@ -1,64 +1,70 @@ - + android:layout_height="match_parent"> - - + android:layout_height="match_parent" + android:orientation="vertical"> - + - + android:background="@color/colorForeground" + android:padding="10dp" + android:textColor="@color/textSecondary" + android:textSize="13sp" /> - + - + - + - + - - + android:background="#474949"> + + + + + - \ No newline at end of file + + \ No newline at end of file