From 386965bf36c9c7543da3b14378e50dd25b1f1cd4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 15 Oct 2019 10:09:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kunfei/bookshelf/help/DataRestore.java | 93 ++++++++++--------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/kunfei/bookshelf/help/DataRestore.java b/app/src/main/java/com/kunfei/bookshelf/help/DataRestore.java index 8a3055ed04..0bea6ae59a 100644 --- a/app/src/main/java/com/kunfei/bookshelf/help/DataRestore.java +++ b/app/src/main/java/com/kunfei/bookshelf/help/DataRestore.java @@ -4,6 +4,7 @@ import com.kunfei.bookshelf.DbHelper; import com.kunfei.bookshelf.MApplication; +import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.bean.BookShelfBean; import com.kunfei.bookshelf.bean.BookSourceBean; import com.kunfei.bookshelf.bean.ReplaceRuleBean; @@ -34,57 +35,15 @@ public static DataRestore getInstance() { public Boolean run() { String dirPath = FileUtils.getSdCardPath() + File.separator + "YueDu"; - restoreConfig(dirPath); restoreBookSource(dirPath); restoreBookShelf(dirPath); restoreSearchHistory(dirPath); restoreReplaceRule(dirPath); restoreTxtChapterRule(dirPath); + restoreConfig(dirPath); return true; } - private void restoreConfig(String dirPath) { - Map entries = null; - try (FileInputStream ins = new FileInputStream(dirPath + File.separator + "config.xml")) { - entries = XmlUtils.readMapXml(ins); - } catch (Exception ignored) { - } - if (entries == null || entries.isEmpty()) return; - long donateHb = MApplication.getConfigPreferences().getLong("DonateHb", 0); - donateHb = donateHb > System.currentTimeMillis() ? 0 : donateHb; - SharedPreferences.Editor editor = MApplication.getConfigPreferences().edit(); - editor.clear(); - for (Map.Entry entry : entries.entrySet()) { - Object v = entry.getValue(); - String key = entry.getKey(); - String type = v.getClass().getSimpleName(); - - switch (type) { - case "Integer": - editor.putInt(key, (Integer) v); - break; - case "Boolean": - editor.putBoolean(key, (Boolean) v); - break; - case "String": - editor.putString(key, (String) v); - break; - case "Float": - editor.putFloat(key, (Float) v); - break; - case "Long": - editor.putLong(key, (Long) v); - break; - } - } - editor.putLong("DonateHb", donateHb); - editor.putInt("versionCode", MApplication.getVersionCode()); - editor.apply(); - ReadBookControl.getInstance().updateReaderSettings(); - MApplication.getInstance().upThemeStore(); - MApplication.getInstance().initNightTheme(); - } - private void restoreBookShelf(String file) { try { String json = DocumentHelper.readString("myBookShelf.json", file); @@ -151,4 +110,52 @@ private void restoreTxtChapterRule(String file) { e.printStackTrace(); } } + + private void restoreConfig(String dirPath) { + try { + Map entries = null; + try (FileInputStream ins = new FileInputStream(dirPath + File.separator + "config.xml")) { + entries = XmlUtils.readMapXml(ins); + } catch (Exception ignored) { + } + if (entries == null || entries.isEmpty()) return; + long donateHb = MApplication.getConfigPreferences().getLong("DonateHb", 0); + donateHb = donateHb > System.currentTimeMillis() ? 0 : donateHb; + SharedPreferences.Editor editor = MApplication.getConfigPreferences().edit(); + editor.clear(); + for (Map.Entry entry : entries.entrySet()) { + Object v = entry.getValue(); + String key = entry.getKey(); + String type = v.getClass().getSimpleName(); + + switch (type) { + case "Integer": + editor.putInt(key, (Integer) v); + break; + case "Boolean": + editor.putBoolean(key, (Boolean) v); + break; + case "String": + editor.putString(key, (String) v); + break; + case "Float": + editor.putFloat(key, (Float) v); + break; + case "Long": + editor.putLong(key, (Long) v); + break; + } + } + editor.putLong("DonateHb", donateHb); + editor.putInt("versionCode", MApplication.getVersionCode()); + editor.apply(); + LauncherIcon.ChangeIcon(MApplication.getConfigPreferences().getString("launcher_icon", MApplication.getInstance().getString(R.string.icon_main))); + ReadBookControl.getInstance().updateReaderSettings(); + MApplication.getInstance().upThemeStore(); + MApplication.getInstance().initNightTheme(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }