From f31870819e82dad022ad1159bafedd705f391c8a Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 14:01:00 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E4=B8=BB=E9=A2=98=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/themeConfig.json | 4 ++-- app/src/main/java/io/legado/app/help/ThemeConfig.kt | 5 +---- app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt | 3 +++ app/src/main/res/values-zh-rHK/strings.xml | 1 - app/src/main/res/values-zh-rTW/strings.xml | 1 - app/src/main/res/values-zh/strings.xml | 1 - 6 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/main/assets/themeConfig.json b/app/src/main/assets/themeConfig.json index d785fd22e..a8826cf98 100644 --- a/app/src/main/assets/themeConfig.json +++ b/app/src/main/assets/themeConfig.json @@ -9,7 +9,7 @@ }, { "themeName": "黑白", - "isNightTheme": false, + "isNightTheme": true, "primaryColor": "#303030", "accentColor": "#E0E0E0", "backgroundColor": "#424242", @@ -17,7 +17,7 @@ }, { "themeName": "A屏黑", - "isNightTheme": false, + "isNightTheme": true, "primaryColor": "#000000", "accentColor": "#FFFFFF", "backgroundColor": "#000000", diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt index 6a2402485..1cea05cbd 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -66,10 +66,7 @@ object ThemeConfig { fun applyConfig(context: Context, config: Config) { val primary = Color.parseColor(config.primaryColor) val accent = Color.parseColor(config.accentColor) - var background = Color.parseColor(config.backgroundColor) - if (!ColorUtils.isColorLight(background)) { - background = context.getCompatColor(R.color.md_grey_100) - } + val background = Color.parseColor(config.backgroundColor) val bBackground = Color.parseColor(config.bottomBackground) if (config.isNightTheme) { context.putPrefInt(PreferKey.cNPrimary, primary) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt index 16d6d68b9..b7cf85e19 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt @@ -85,6 +85,9 @@ class ThemeListDialog : BaseDialogFragment() { override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { + onClick { + ThemeConfig.applyConfig(context, ThemeConfig.configList[holder.layoutPosition]) + } iv_share.onClick { share(holder.layoutPosition) } diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index ba63066b7..c007a530c 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -757,5 +757,4 @@ 保存夜间主题配置以共调用和分享 主题列表 使用保存主题,导入,分享主题 - 切換默認主題 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 8a977be9e..94e5a1760 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -757,6 +757,5 @@ 保存夜间主题配置以共调用和分享 主题列表 使用保存主题,导入,分享主题 - 切換默認主題 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index c8d1709d3..9e10e4ff9 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -757,5 +757,4 @@ 保存夜间主题配置以共调用和分享 主题列表 使用保存主题,导入,分享主题 - 切换默认主题 From fb860c23490b57c88317cadb0181d3daa7cf3a08 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 15:58:17 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E4=B8=BB=E9=A2=98=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/ThemeConfig.kt | 20 +++++++++++------- .../source/edit/BookSourceEditActivity.kt | 11 ++-------- .../legado/app/ui/config/ThemeListDialog.kt | 21 ++++++++++++++++++- .../rss/source/edit/RssSourceEditActivity.kt | 11 ++-------- .../io/legado/app/utils/ContextExtensions.kt | 10 +++++++++ app/src/main/res/menu/theme_list.xml | 10 +++++++++ 6 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 app/src/main/res/menu/theme_list.xml diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt index 1cea05cbd..91342bfc9 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -40,7 +40,13 @@ object ThemeConfig { } } - fun addConfig(newConfig: Config) { + fun addConfig(json: String) { + GSON.fromJsonObject(json)?.let { + addConfig(it) + } + } + + private fun addConfig(newConfig: Config) { configList.forEachIndexed { index, config -> if (newConfig.themeName == config.themeName) { configList[index] = newConfig @@ -125,12 +131,12 @@ object ThemeConfig { } class Config( - var themeName: String = "典雅蓝", - var isNightTheme: Boolean = false, - var primaryColor: String = "#03A9F4", - var accentColor: String = "#AD1457", - var backgroundColor: String = "#F5F5F5", - var bottomBackground: String = "#EEEEEE" + var themeName: String, + var isNightTheme: Boolean, + var primaryColor: String, + var accentColor: String, + var backgroundColor: String, + var bottomBackground: String ) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 457a2b0ba..8a7deb2ab 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -1,9 +1,6 @@ package io.legado.app.ui.book.source.edit import android.app.Activity -import android.content.ClipData -import android.content.ClipboardManager -import android.content.Context import android.content.Intent import android.graphics.Rect import android.net.Uri @@ -28,10 +25,7 @@ import io.legado.app.ui.book.source.debug.BookSourceDebugActivity import io.legado.app.ui.login.SourceLogin import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.widget.KeyboardToolPop -import io.legado.app.utils.GSON -import io.legado.app.utils.applyTint -import io.legado.app.utils.getViewModel -import io.legado.app.utils.shareWithQr +import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_source_edit.* import org.jetbrains.anko.* import kotlin.math.abs @@ -82,8 +76,7 @@ class BookSourceEditActivity : } R.id.menu_copy_source -> getSource().let { source -> GSON.toJson(source)?.let { sourceStr -> - val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager - clipboard?.setPrimaryClip(ClipData.newPlainText(null, sourceStr)) + sendToClip(sourceStr) } } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt index b7cf85e19..ceb96fe02 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt @@ -3,8 +3,10 @@ package io.legado.app.ui.config import android.os.Bundle import android.util.DisplayMetrics import android.view.LayoutInflater +import android.view.MenuItem import android.view.View import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.BaseDialogFragment @@ -18,12 +20,13 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.GSON import io.legado.app.utils.applyTint +import io.legado.app.utils.getClipText import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_theme_config.view.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.share -class ThemeListDialog : BaseDialogFragment() { +class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { private lateinit var adapter: Adapter @@ -46,6 +49,7 @@ class ThemeListDialog : BaseDialogFragment() { tool_bar.setBackgroundColor(primaryColor) tool_bar.setTitle(R.string.theme_list) initView() + initMenu() initData() } @@ -56,10 +60,25 @@ class ThemeListDialog : BaseDialogFragment() { recycler_view.adapter = adapter } + private fun initMenu() { + tool_bar.setOnMenuItemClickListener(this) + } + fun initData() { adapter.setItems(ThemeConfig.configList) } + override fun onMenuItemClick(item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.menu_import -> { + requireContext().getClipText()?.let { + ThemeConfig.addConfig(it) + } + } + } + return true + } + fun delete(index: Int) { alert(R.string.delete, R.string.sure_del) { okButton { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index bd070639a..5072861ec 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -1,9 +1,6 @@ package io.legado.app.ui.rss.source.edit import android.app.Activity -import android.content.ClipData -import android.content.ClipboardManager -import android.content.Context import android.content.Intent import android.graphics.Rect import android.os.Bundle @@ -23,10 +20,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop -import io.legado.app.utils.GSON -import io.legado.app.utils.applyTint -import io.legado.app.utils.getViewModel -import io.legado.app.utils.shareWithQr +import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_rss_source_edit.* import org.jetbrains.anko.* import kotlin.math.abs @@ -99,8 +93,7 @@ class RssSourceEditActivity : } R.id.menu_copy_source -> { GSON.toJson(getRssSource())?.let { sourceStr -> - val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager - clipboard?.setPrimaryClip(ClipData.newPlainText(null, sourceStr)) + sendToClip(sourceStr) } } R.id.menu_qr_code_camera -> startActivityForResult(qrRequestCode) diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index 272c8d02d..489f5d508 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -146,6 +146,16 @@ fun Context.sendToClip(text: String) { } } +fun Context.getClipText(): String? { + val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? + clipboard?.primaryClip?.let { + if (it.itemCount > 0) { + return it.getItemAt(0).text.toString().trim() + } + } + return null +} + /** * 系统是否暗色主题 */ diff --git a/app/src/main/res/menu/theme_list.xml b/app/src/main/res/menu/theme_list.xml new file mode 100644 index 000000000..bd7f6194d --- /dev/null +++ b/app/src/main/res/menu/theme_list.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file From c8a9a03430f61de516f5196569e9e67880754587 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 16:07:25 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E4=B8=BB=E9=A2=98=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt index ceb96fe02..d971fcd58 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt @@ -62,6 +62,8 @@ class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { private fun initMenu() { tool_bar.setOnMenuItemClickListener(this) + tool_bar.inflateMenu(R.menu.theme_list) + tool_bar.menu.applyTint(requireContext()) } fun initData() { From 209350ae347df193b33c146de3d3de3c4854c785 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 16:10:05 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/source/edit/BookSourceEditViewModel.kt | 11 +++-------- .../app/ui/rss/source/edit/RssSourceEditViewModel.kt | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 81f3d22f0..7e1f70089 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -1,8 +1,6 @@ package io.legado.app.ui.book.source.edit import android.app.Application -import android.content.ClipboardManager -import android.content.Context import android.content.Intent import io.legado.app.App import io.legado.app.base.BaseViewModel @@ -10,6 +8,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.help.storage.OldRule import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonObject +import io.legado.app.utils.getClipText import kotlinx.coroutines.Dispatchers class BookSourceEditViewModel(application: Application) : BaseViewModel(application) { @@ -54,12 +53,8 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat fun pasteSource(onSuccess: (source: BookSource) -> Unit) { execute(context = Dispatchers.Main) { var source: BookSource? = null - val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? - clipboard?.primaryClip?.let { - if (it.itemCount > 0) { - val json = it.getItemAt(0).text.toString() - source = OldRule.jsonToBookSource(json) - } + context.getClipText()?.let { json -> + source = OldRule.jsonToBookSource(json) } source }.onError { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index eb9c4e034..88a9a78dd 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -1,14 +1,13 @@ package io.legado.app.ui.rss.source.edit import android.app.Application -import android.content.ClipboardManager -import android.content.Context import android.content.Intent import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssSource import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonObject +import io.legado.app.utils.getClipText import kotlinx.coroutines.Dispatchers class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { @@ -53,12 +52,8 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati fun pasteSource(onSuccess: (source: RssSource) -> Unit) { execute(context = Dispatchers.Main) { var source: RssSource? = null - val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? - clipboard?.primaryClip?.let { - if (it.itemCount > 0) { - val json = it.getItemAt(0).text.toString().trim() - source = GSON.fromJsonObject(json) - } + context.getClipText()?.let { json -> + source = GSON.fromJsonObject(json) } source }.onError { From 18d3019df8b4ea70b988993d8ae822b7b4c6b1f6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 16:19:28 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/read/page/ContentView.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index 3537fade5..66333c901 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -32,7 +32,9 @@ class ContentView(context: Context) : FrameLayout(context) { private var tvPageAndTotal: BatteryView? = null val headerHeight: Int - get() = if (ReadBookConfig.hideStatusBar) ll_header.height else context.statusBarHeight + get() = if (ReadBookConfig.hideStatusBar) { + if (ll_header.isGone) 0 else ll_header.height + } else context.statusBarHeight init { //设置背景防止切换背景时文字重叠 From 6da3dc9e5310702541bc32e55097f8a93a9bc9c3 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 16:26:52 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt index d971fcd58..87cb180dd 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt @@ -75,6 +75,7 @@ class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { R.id.menu_import -> { requireContext().getClipText()?.let { ThemeConfig.addConfig(it) + initData() } } } From 29074ddd1aceff49da3d1b6030605db8dacb3b23 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 16:56:32 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/ThemeConfig.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt index 91342bfc9..8add0a1ff 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -2,6 +2,7 @@ package io.legado.app.help import android.content.Context import android.graphics.Color +import androidx.annotation.Keep import io.legado.app.App import io.legado.app.R import io.legado.app.constant.EventBus @@ -130,6 +131,7 @@ object ThemeConfig { addConfig(config) } + @Keep class Config( var themeName: String, var isNightTheme: Boolean, From a32966022815a6760c99459ae3be14c97ca84e40 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 17:06:48 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/ThemeConfig.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt index 8add0a1ff..412b6b8bf 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -44,6 +44,7 @@ object ThemeConfig { fun addConfig(json: String) { GSON.fromJsonObject(json)?.let { addConfig(it) + save() } } From 49b6d1db200891e67732b8a6e4d81f2871167857 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 17:20:35 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/storage/Backup.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 7efc5a723..c08f0dd1d 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -6,6 +6,7 @@ import androidx.documentfile.provider.DocumentFile import io.legado.app.App import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig +import io.legado.app.help.ThemeConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO @@ -34,6 +35,7 @@ object Backup { "readRecord.json", "httpTTS.json", ReadBookConfig.configFileName, + ThemeConfig.configFileName, "config.xml" ) } @@ -65,6 +67,10 @@ object Backup { FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName) .writeText(it) } + GSON.toJson(ThemeConfig.configList)?.let { + FileUtils.createFileIfNotExist(backupPath + File.separator + ThemeConfig.configFileName) + .writeText(it) + } Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp -> val edit = sp.edit() App.INSTANCE.defaultSharedPreferences.all.map { From e8bc9374ce45b3f7964c9e1e9338c9cc622f8a83 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 17:27:09 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/storage/Backup.kt | 4 ++-- .../ui/book/source/edit/BookSourceEditActivity.kt | 12 +++--------- .../ui/rss/source/edit/RssSourceEditActivity.kt | 14 +++----------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index c08f0dd1d..b52688846 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -63,11 +63,11 @@ object Backup { writeListToJson(App.db.txtTocRule().all, "txtTocRule.json", backupPath) writeListToJson(App.db.readRecordDao().all, "readRecord.json", backupPath) writeListToJson(App.db.httpTTSDao().all, "httpTTS.json", backupPath) - GSON.toJson(ReadBookConfig.configList)?.let { + GSON.toJson(ReadBookConfig.configList).let { FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName) .writeText(it) } - GSON.toJson(ThemeConfig.configList)?.let { + GSON.toJson(ThemeConfig.configList).let { FileUtils.createFileIfNotExist(backupPath + File.separator + ThemeConfig.configFileName) .writeText(it) } diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 8a7deb2ab..57421991d 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -74,17 +74,11 @@ class BookSourceEditActivity : } } } - R.id.menu_copy_source -> getSource().let { source -> - GSON.toJson(source)?.let { sourceStr -> - sendToClip(sourceStr) - } - } + R.id.menu_copy_source -> sendToClip(GSON.toJson(getSource())) R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_qr_code_camera -> startActivityForResult(qrRequestCode) - R.id.menu_share_str -> GSON.toJson(getSource())?.let { share(it) } - R.id.menu_share_qr -> GSON.toJson(getSource())?.let { sourceStr -> - shareWithQr(getString(R.string.share_book_source), sourceStr) - } + R.id.menu_share_str -> share(GSON.toJson(getSource())) + R.id.menu_share_qr -> shareWithQr(getString(R.string.share_book_source), GSON.toJson(getSource())) R.id.menu_rule_summary -> { try { val intent = Intent(Intent.ACTION_VIEW) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 5072861ec..34b795a2b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -91,19 +91,11 @@ class RssSourceEditActivity : } } } - R.id.menu_copy_source -> { - GSON.toJson(getRssSource())?.let { sourceStr -> - sendToClip(sourceStr) - } - } + R.id.menu_copy_source -> sendToClip(GSON.toJson(getRssSource())) R.id.menu_qr_code_camera -> startActivityForResult(qrRequestCode) R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } - R.id.menu_share_str -> GSON.toJson(getRssSource())?.let { sourceStr -> - share(sourceStr) - } - R.id.menu_share_qr -> GSON.toJson(getRssSource())?.let { sourceStr -> - shareWithQr(getString(R.string.share_rss_source), sourceStr) - } + R.id.menu_share_str -> share(GSON.toJson(getRssSource())) + R.id.menu_share_qr -> shareWithQr(getString(R.string.share_rss_source), GSON.toJson(getRssSource())) } return super.onCompatOptionsItemSelected(item) } From 3597b75c8a461468aa5e6db058f96bc8f6a0f83a Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 17:35:46 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 25ecc6c7f..d15998f6b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -132,7 +132,7 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' - implementation 'com.google.android.material:material:1.2.0' + implementation 'com.google.android.material:material:1.2.1' implementation 'com.google.android:flexbox:1.1.0' implementation 'com.google.code.gson:gson:2.8.6' From 6252019bc5cdc8d9de4f5851b3375d5b9d0d3e07 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 17:44:55 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt | 2 +- .../java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt | 2 +- .../main/java/io/legado/app/ui/book/group/GroupManageDialog.kt | 2 +- .../main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt | 2 +- .../java/io/legado/app/ui/book/read/config/TocRegexDialog.kt | 2 +- .../io/legado/app/ui/book/source/manage/BookSourceActivity.kt | 2 +- .../io/legado/app/ui/book/source/manage/BookSourceAdapter.kt | 2 +- .../java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt | 2 +- .../java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt | 2 +- .../io/legado/app/ui/rss/source/manage/RssSourceActivity.kt | 2 +- .../java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt | 2 +- .../app/{help => ui/widget/recycler}/ItemTouchCallback.kt | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) rename app/src/main/java/io/legado/app/{help => ui/widget/recycler}/ItemTouchCallback.kt (99%) diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index ab37c5fe1..f23a2008c 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -14,7 +14,6 @@ import io.legado.app.constant.AppConst import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookGroup -import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.okButton @@ -22,6 +21,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.group.GroupManageDialog import io.legado.app.ui.book.group.GroupSelectDialog import io.legado.app.ui.widget.SelectActionBar +import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefInt diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt index 4917ea6cb..84e070259 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt @@ -8,8 +8,8 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookGroup -import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.theme.backgroundColor +import io.legado.app.ui.widget.recycler.ItemTouchCallback import kotlinx.android.synthetic.main.item_arrange_book.view.* import org.jetbrains.anko.backgroundColor import org.jetbrains.anko.sdk27.listeners.onClick diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index b3fb5674d..0782c7c39 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -21,11 +21,11 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookGroup import io.legado.app.help.AppConfig -import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.dialogs.* import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.primaryColor +import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 7a83ab140..bee66bcc6 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -20,7 +20,6 @@ import io.legado.app.base.BaseDialogFragment import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookGroup -import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton @@ -28,6 +27,7 @@ import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.primaryColor +import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index 4603a0d33..c0bed1512 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -21,13 +21,13 @@ import io.legado.app.base.BaseDialogFragment import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.TxtTocRule -import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.cancelButton import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.primaryColor +import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index c7139fd01..a7d58dba5 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -20,7 +20,6 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppPattern import io.legado.app.data.entities.BookSource import io.legado.app.help.IntentDataHelp -import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.dialogs.* import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor @@ -32,6 +31,7 @@ import io.legado.app.ui.filechooser.FilePicker import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.recycler.DragSelectTouchHelper +import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index afacfa0a2..a5177f443 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -12,9 +12,9 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookSource -import io.legado.app.help.ItemTouchCallback.OnItemTouchCallbackListener import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.widget.recycler.DragSelectTouchHelper +import io.legado.app.ui.widget.recycler.ItemTouchCallback.OnItemTouchCallbackListener import io.legado.app.utils.invisible import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_book_source.view.* diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 3c33d008b..1f65877f8 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -21,7 +21,6 @@ import io.legado.app.constant.AppPattern import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.BookHelp import io.legado.app.help.IntentDataHelp -import io.legado.app.help.ItemTouchCallback import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.dialogs.* import io.legado.app.lib.theme.ATH @@ -32,6 +31,7 @@ import io.legado.app.ui.filechooser.FilePicker import io.legado.app.ui.replacerule.edit.ReplaceEditDialog import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.recycler.DragSelectTouchHelper +import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt index a62c62ac6..bcb29e87d 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt @@ -10,9 +10,9 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.ReplaceRule -import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.widget.recycler.DragSelectTouchHelper +import io.legado.app.ui.widget.recycler.ItemTouchCallback import kotlinx.android.synthetic.main.item_replace_rule.view.* import org.jetbrains.anko.sdk27.listeners.onClick import java.util.* diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index b53c31b50..05885d183 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -20,7 +20,6 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppPattern import io.legado.app.data.entities.RssSource import io.legado.app.help.IntentDataHelp -import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.dialogs.* import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor @@ -31,6 +30,7 @@ import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.recycler.DragSelectTouchHelper +import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index 5693af3d4..2652503b3 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -10,9 +10,9 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.RssSource -import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.widget.recycler.DragSelectTouchHelper +import io.legado.app.ui.widget.recycler.ItemTouchCallback import kotlinx.android.synthetic.main.item_rss_source.view.* import org.jetbrains.anko.sdk27.listeners.onClick import java.util.* diff --git a/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt similarity index 99% rename from app/src/main/java/io/legado/app/help/ItemTouchCallback.kt rename to app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt index 9c1a0bbf2..b015a0086 100644 --- a/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt @@ -1,4 +1,4 @@ -package io.legado.app.help +package io.legado.app.ui.widget.recycler import androidx.recyclerview.widget.GridLayoutManager From b5ead6644126349387761d69f0253e2b5146cefb Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 17:47:01 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/App.kt | 2 +- .../java/io/legado/app/help/CrashHandler.kt | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index a96db68fb..4fac6f22e 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -45,7 +45,7 @@ class App : MultiDexApplication() { super.onCreate() INSTANCE = this androidId = Settings.System.getString(contentResolver, Settings.Secure.ANDROID_ID) - CrashHandler().init(this) + CrashHandler(this) LanguageUtils.setConfigurationOld(this) db = AppDatabase.createDatabase(INSTANCE) packageManager.getPackageInfo(packageName, 0)?.let { diff --git a/app/src/main/java/io/legado/app/help/CrashHandler.kt b/app/src/main/java/io/legado/app/help/CrashHandler.kt index 223d8f29e..e842707d3 100644 --- a/app/src/main/java/io/legado/app/help/CrashHandler.kt +++ b/app/src/main/java/io/legado/app/help/CrashHandler.kt @@ -20,18 +20,14 @@ import java.util.concurrent.TimeUnit * 异常管理类 */ @Suppress("DEPRECATION") -class CrashHandler : Thread.UncaughtExceptionHandler { +class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler { private val tag = this.javaClass.simpleName + /** * 系统默认UncaughtExceptionHandler */ private var mDefaultHandler: Thread.UncaughtExceptionHandler? = null - /** - * context - */ - private var mContext: Context? = null - /** * 存储异常和参数信息 */ @@ -43,8 +39,7 @@ class CrashHandler : Thread.UncaughtExceptionHandler { @SuppressLint("SimpleDateFormat") private val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss") - fun init(context: Context) { - mContext = context + init { mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler() //设置该CrashHandler为系统默认的 Thread.setDefaultUncaughtExceptionHandler(this) @@ -65,14 +60,14 @@ class CrashHandler : Thread.UncaughtExceptionHandler { private fun handleException(ex: Throwable?) { if (ex == null) return //收集设备参数信息 - collectDeviceInfo(mContext!!) + collectDeviceInfo(context) //添加自定义信息 addCustomInfo() kotlin.runCatching { //使用Toast来显示异常信息 Handler(Looper.getMainLooper()).post { Toast.makeText( - mContext, + context, ex.message, Toast.LENGTH_LONG ).show() @@ -141,7 +136,7 @@ class CrashHandler : Thread.UncaughtExceptionHandler { val timestamp = System.currentTimeMillis() val time = format.format(Date()) val fileName = "crash-$time-$timestamp.log" - mContext?.externalCacheDir?.let { rootFile -> + context.externalCacheDir?.let { rootFile -> FileUtils.getFile(rootFile, "crash").listFiles()?.forEach { if (it.lastModified() < System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7)) { it.delete() From a02d5525bea6d4fd4353b44851deba22d9cb3531 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 8 Sep 2020 17:56:10 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widget/recycler/HeaderAdapterDataObserver.kt} | 4 ++-- .../legado/app/ui/widget/recycler/UpLinearLayoutManager.kt | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) rename app/src/main/java/io/legado/app/{help/AdapterDataObserverHeader.kt => ui/widget/recycler/HeaderAdapterDataObserver.kt} (93%) diff --git a/app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/HeaderAdapterDataObserver.kt similarity index 93% rename from app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt rename to app/src/main/java/io/legado/app/ui/widget/recycler/HeaderAdapterDataObserver.kt index 1aeddeb95..f8e2a0c8c 100644 --- a/app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/HeaderAdapterDataObserver.kt @@ -1,8 +1,8 @@ -package io.legado.app.help +package io.legado.app.ui.widget.recycler import androidx.recyclerview.widget.RecyclerView -internal class AdapterDataObserverHeader( +internal class HeaderAdapterDataObserver( private var adapterDataObserver: RecyclerView.AdapterDataObserver, private var headerCount: Int ) : RecyclerView.AdapterDataObserver() { diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt index 0df53aba7..0af559c45 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt @@ -4,12 +4,7 @@ import android.content.Context import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearSmoothScroller -class UpLinearLayoutManager: LinearLayoutManager { - val context: Context - - constructor(context: Context) : super(context) { - this.context = context - } +class UpLinearLayoutManager(val context: Context) : LinearLayoutManager(context) { fun smoothScrollToPosition(position: Int) { smoothScrollToPosition(position, 0)