Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Oct 15, 2019
1 parent 3d0afad commit a79c41a
Showing 1 changed file with 50 additions and 30 deletions.
80 changes: 50 additions & 30 deletions app/src/main/java/com/kunfei/bookshelf/help/DataRestore.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,49 +86,69 @@ private void restoreConfig(String dirPath) {
}

private void restoreBookShelf(String file) {
String json = DocumentHelper.readString("myBookShelf.json", file);
if (json == null) return;
List<BookShelfBean> bookShelfList = GsonUtils.parseJArray(json, BookShelfBean.class);
if (bookShelfList == null) return;
for (BookShelfBean bookshelf : bookShelfList) {
if (bookshelf.getNoteUrl() != null) {
DbHelper.getDaoSession().getBookShelfBeanDao().insertOrReplace(bookshelf);
}
if (bookshelf.getBookInfoBean().getNoteUrl() != null) {
DbHelper.getDaoSession().getBookInfoBeanDao().insertOrReplace(bookshelf.getBookInfoBean());
try {
String json = DocumentHelper.readString("myBookShelf.json", file);
if (json == null) return;
List<BookShelfBean> bookShelfList = GsonUtils.parseJArray(json, BookShelfBean.class);
if (bookShelfList == null) return;
for (BookShelfBean bookshelf : bookShelfList) {
if (bookshelf.getNoteUrl() != null) {
DbHelper.getDaoSession().getBookShelfBeanDao().insertOrReplace(bookshelf);
}
if (bookshelf.getBookInfoBean().getNoteUrl() != null) {
DbHelper.getDaoSession().getBookInfoBeanDao().insertOrReplace(bookshelf.getBookInfoBean());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

private void restoreBookSource(String file) {
String json = DocumentHelper.readString("myBookSource.json", file);
if (json == null) return;
List<BookSourceBean> bookSourceBeans = GsonUtils.parseJArray(json, BookSourceBean.class);
if (bookSourceBeans == null) return;
BookSourceManager.addBookSource(bookSourceBeans);
try {
String json = DocumentHelper.readString("myBookSource.json", file);
if (json == null) return;
List<BookSourceBean> bookSourceBeans = GsonUtils.parseJArray(json, BookSourceBean.class);
if (bookSourceBeans == null) return;
BookSourceManager.addBookSource(bookSourceBeans);
} catch (Exception e) {
e.printStackTrace();
}
}

private void restoreSearchHistory(String file) {
String json = DocumentHelper.readString("myBookSearchHistory.json", file);
if (json == null) return;
List<SearchHistoryBean> searchHistoryBeans = GsonUtils.parseJArray(json, SearchHistoryBean.class);
if (searchHistoryBeans == null) return;
DbHelper.getDaoSession().getSearchHistoryBeanDao().insertOrReplaceInTx(searchHistoryBeans);
try {
String json = DocumentHelper.readString("myBookSearchHistory.json", file);
if (json == null) return;
List<SearchHistoryBean> searchHistoryBeans = GsonUtils.parseJArray(json, SearchHistoryBean.class);
if (searchHistoryBeans == null) return;
DbHelper.getDaoSession().getSearchHistoryBeanDao().insertOrReplaceInTx(searchHistoryBeans);
} catch (Exception e) {
e.printStackTrace();
}
}

private void restoreReplaceRule(String file) {
String json = DocumentHelper.readString("myBookReplaceRule.json", file);
if (json == null) return;
List<ReplaceRuleBean> replaceRuleBeans = GsonUtils.parseJArray(json, ReplaceRuleBean.class);
if (replaceRuleBeans == null) return;
ReplaceRuleManager.addDataS(replaceRuleBeans);
try {
String json = DocumentHelper.readString("myBookReplaceRule.json", file);
if (json == null) return;
List<ReplaceRuleBean> replaceRuleBeans = GsonUtils.parseJArray(json, ReplaceRuleBean.class);
if (replaceRuleBeans == null) return;
ReplaceRuleManager.addDataS(replaceRuleBeans);
} catch (Exception e) {
e.printStackTrace();
}
}

private void restoreTxtChapterRule(String file) {
String json = DocumentHelper.readString("myTxtChapterRule.json", file);
if (json == null) return;
List<TxtChapterRuleBean> ruleBeanList = GsonUtils.parseJArray(json, TxtChapterRuleBean.class);
if (ruleBeanList == null) return;
TxtChapterRuleManager.save(ruleBeanList);
try {
String json = DocumentHelper.readString("myTxtChapterRule.json", file);
if (json == null) return;
List<TxtChapterRuleBean> ruleBeanList = GsonUtils.parseJArray(json, TxtChapterRuleBean.class);
if (ruleBeanList == null) return;
TxtChapterRuleManager.save(ruleBeanList);
} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit a79c41a

Please sign in to comment.